mirror of
https://github.com/thomiceli/opengist.git
synced 2024-12-22 20:42:40 +00:00
Add binaries cross compile in CD (#113)
This commit is contained in:
parent
fa8e068e24
commit
30ca090e74
9 changed files with 134 additions and 7 deletions
|
@ -1,11 +1,36 @@
|
|||
name: Docker
|
||||
name: Release
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
binaries-build-release:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Go 1.20
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: "1.20"
|
||||
|
||||
- name: Cross compile build
|
||||
run: make all_crosscompile
|
||||
|
||||
- name: Upload Release Assets
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: |
|
||||
build/*.tar.gz
|
||||
build/*.zip
|
||||
build/checksums.txt
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
docker-build-release:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,3 +6,4 @@ gist.db
|
|||
public/assets/*
|
||||
public/manifest.json
|
||||
opengist
|
||||
build/
|
||||
|
|
11
Makefile
11
Makefile
|
@ -1,10 +1,12 @@
|
|||
.PHONY: all install build_frontend build_backend build build_docker watch_frontend watch_backend watch clean clean_docker check_changes go_mod fmt test
|
||||
.PHONY: all all_crosscompile install build_frontend build_backend build build_crosscompile build_docker watch_frontend watch_backend watch clean clean_docker check_changes go_mod fmt test
|
||||
|
||||
# Specify the name of your Go binary output
|
||||
BINARY_NAME := opengist
|
||||
|
||||
all: clean install build
|
||||
|
||||
all_crosscompile: clean install build_frontend build_crosscompile
|
||||
|
||||
install:
|
||||
@echo "Installing NPM dependencies..."
|
||||
@npm ci || (echo "Error: Failed to install NPM dependencies." && exit 1)
|
||||
|
@ -21,6 +23,9 @@ build_backend:
|
|||
|
||||
build: build_frontend build_backend
|
||||
|
||||
build_crosscompile:
|
||||
@bash ./scripts/build-all.sh
|
||||
|
||||
build_docker:
|
||||
@echo "Building Docker image..."
|
||||
docker build -t $(BINARY_NAME):latest .
|
||||
|
@ -34,12 +39,12 @@ watch_backend:
|
|||
OG_DEV=1 npx nodemon --watch '**/*' -e html,yml,go,js --signal SIGTERM --exec 'go run . --config config.yml'
|
||||
|
||||
watch:
|
||||
@bash ./watch.sh
|
||||
@bash ./scripts/watch.sh
|
||||
|
||||
clean:
|
||||
@echo "Cleaning up build artifacts..."
|
||||
@rm -f $(BINARY_NAME) public/manifest.json
|
||||
@rm -rf public/assets
|
||||
@rm -rf public/assets build
|
||||
|
||||
clean_docker:
|
||||
@echo "Cleaning up Docker image..."
|
||||
|
|
16
README.md
16
README.md
|
@ -50,7 +50,7 @@ version: "3"
|
|||
|
||||
services:
|
||||
opengist:
|
||||
image: ghcr.io/thomiceli/opengist:1.4
|
||||
image: ghcr.io/thomiceli/opengist:1
|
||||
container_name: opengist
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
|
@ -71,6 +71,20 @@ services:
|
|||
GID: 1001
|
||||
```
|
||||
|
||||
### Via binary
|
||||
|
||||
Download the archive for your system from the release page [here](https://github.com/thomiceli/opengist/releases/latest), and extract it.
|
||||
|
||||
```shell
|
||||
# example for linux amd64
|
||||
wget https://github.com/thomiceli/opengist/releases/download/v1.5.0/opengist1.5.0-linux-amd64.tar.gz
|
||||
|
||||
tar xzvf opengist1.5.0-linux-amd64.tar.gz
|
||||
cd opengist
|
||||
chmod +x opengist
|
||||
./opengist # with or without `--config config.yml`
|
||||
```
|
||||
|
||||
### From source
|
||||
|
||||
Requirements : [Git](https://git-scm.com/downloads) (2.20+), [Go](https://go.dev/doc/install) (1.20+), [Node.js](https://nodejs.org/en/download/) (16+)
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
# Learn more about Opengist configuration here:
|
||||
# https://github.com/thomiceli/opengist/blob/master/docs/configuration/index.md
|
||||
# https://github.com/thomiceli/opengist/blob/master/docs/configuration/cheat-sheet.md
|
||||
|
||||
# Set the log level to one of the following: trace, debug, info, warn, error, fatal, panic. Default: warn
|
||||
log-level: warn
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ Written in [Go](https://go.dev), Opengist aims to be fast and easy to deploy.
|
|||
[Git](https://git-scm.com/download) is obviously required to run Opengist, as it's the main feature of the app.
|
||||
Version **2.20** or later is recommended as the app has not been tested with older Git versions.
|
||||
|
||||
[OpenSSH](https://www.openssh.com/) suite if you wish to use Git over SSH
|
||||
[OpenSSH](https://www.openssh.com/) suite if you wish to use Git over SSH.
|
||||
|
||||
|
||||
## Components
|
||||
|
|
|
@ -41,6 +41,20 @@ services:
|
|||
GID: 1001
|
||||
```
|
||||
|
||||
### Via binary
|
||||
|
||||
Download the archive for your system from the release page [here](https://github.com/thomiceli/opengist/releases/latest), and extract it.
|
||||
|
||||
```shell
|
||||
# example for linux amd64
|
||||
wget https://github.com/thomiceli/opengist/releases/download/v1.5.0/opengist1.5.0-linux-amd64.tar.gz
|
||||
|
||||
tar xzvf opengist1.5.0-linux-amd64.tar.gz
|
||||
cd opengist
|
||||
chmod +x opengist
|
||||
./opengist # with or without `--config config.yml`
|
||||
```
|
||||
|
||||
|
||||
## From source
|
||||
|
||||
|
|
64
scripts/build-all.sh
Executable file
64
scripts/build-all.sh
Executable file
|
@ -0,0 +1,64 @@
|
|||
#!/bin/sh
|
||||
|
||||
CHECKSUMS_FILE="build/checksums.txt"
|
||||
BINARY_NAME="opengist"
|
||||
TARGETS="darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 linux/armv6 linux/armv7 linux/386 windows/amd64"
|
||||
VERSION=$(git describe --tags | sed 's/^v//')
|
||||
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "Error: Could not retrieve version from git tags. Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for TARGET in $TARGETS; do
|
||||
GOOS=${TARGET%/*}
|
||||
GOARCH=${TARGET#*/}
|
||||
|
||||
case $GOOS-$GOARCH in
|
||||
linux-armv6)
|
||||
GOARCH="arm"
|
||||
GOARM=6
|
||||
;;
|
||||
linux-armv7)
|
||||
GOARCH="arm"
|
||||
GOARM=7
|
||||
;;
|
||||
*)
|
||||
unset GOARM
|
||||
;;
|
||||
esac
|
||||
|
||||
OUTPUT_PARENT_DIR="build/$GOOS-$GOARCH${GOARM:+v$GOARM}-$VERSION"
|
||||
OUTPUT_DIR="$OUTPUT_PARENT_DIR/$BINARY_NAME"
|
||||
OUTPUT_FILE="$OUTPUT_DIR/$BINARY_NAME"
|
||||
|
||||
if [ "$GOOS" = "windows" ]; then
|
||||
OUTPUT_FILE="$OUTPUT_FILE.exe"
|
||||
fi
|
||||
|
||||
echo "Building version $VERSION for $GOOS/$GOARCH${GOARM:+v$GOARM}..."
|
||||
mkdir -p $OUTPUT_DIR
|
||||
env GOOS=$GOOS GOARCH=$GOARCH GOARM=$GOARM CGO_ENABLED=0 go build -tags fs_embed -o $OUTPUT_FILE
|
||||
cp README.md $OUTPUT_DIR
|
||||
cp LICENSE $OUTPUT_DIR
|
||||
cp config.yml $OUTPUT_DIR
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error building for $GOOS/$GOARCH${GOARM:+v$GOARM}. Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Archive the binary with README and LICENSE
|
||||
echo "Archiving for $GOOS/$GOARCH${GOARM:+v$GOARM}..."
|
||||
if [ "$GOOS" = "windows" ]; then
|
||||
# ZIP for Windows
|
||||
cd $OUTPUT_PARENT_DIR && zip -r "../$BINARY_NAME$VERSION-$GOOS-$GOARCH${GOARM:+v$GOARM}.zip" "$BINARY_NAME/" && cd - > /dev/null
|
||||
sha256sum "build/$BINARY_NAME$VERSION-$GOOS-$GOARCH${GOARM:+v$GOARM}.zip" | awk '{print $1 " " substr($2,7)}' >> $CHECKSUMS_FILE
|
||||
else
|
||||
# tar.gz for other platforms
|
||||
tar -czf "build/$BINARY_NAME$VERSION-$GOOS-$GOARCH${GOARM:+v$GOARM}.tar.gz" -C $OUTPUT_PARENT_DIR "$BINARY_NAME"
|
||||
sha256sum "build/$BINARY_NAME$VERSION-$GOOS-$GOARCH${GOARM:+v$GOARM}.tar.gz" | awk '{print $1 " " substr($2,7)}' >> $CHECKSUMS_FILE
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Build and archiving complete."
|
0
watch.sh → scripts/watch.sh
Normal file → Executable file
0
watch.sh → scripts/watch.sh
Normal file → Executable file
Loading…
Reference in a new issue