Add binaries cross compile in CD (#113)

This commit is contained in:
Thomas Miceli 2023-09-26 15:13:58 +02:00 committed by GitHub
parent fa8e068e24
commit 30ca090e74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 134 additions and 7 deletions

View file

@ -1,11 +1,36 @@
name: Docker name: Release
on: on:
release: release:
types: [published] types: [published]
workflow_dispatch:
jobs: 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: docker-build-release:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:

1
.gitignore vendored
View file

@ -6,3 +6,4 @@ gist.db
public/assets/* public/assets/*
public/manifest.json public/manifest.json
opengist opengist
build/

View file

@ -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 # Specify the name of your Go binary output
BINARY_NAME := opengist BINARY_NAME := opengist
all: clean install build all: clean install build
all_crosscompile: clean install build_frontend build_crosscompile
install: install:
@echo "Installing NPM dependencies..." @echo "Installing NPM dependencies..."
@npm ci || (echo "Error: Failed to install NPM dependencies." && exit 1) @npm ci || (echo "Error: Failed to install NPM dependencies." && exit 1)
@ -21,6 +23,9 @@ build_backend:
build: build_frontend build_backend build: build_frontend build_backend
build_crosscompile:
@bash ./scripts/build-all.sh
build_docker: build_docker:
@echo "Building Docker image..." @echo "Building Docker image..."
docker build -t $(BINARY_NAME):latest . 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' OG_DEV=1 npx nodemon --watch '**/*' -e html,yml,go,js --signal SIGTERM --exec 'go run . --config config.yml'
watch: watch:
@bash ./watch.sh @bash ./scripts/watch.sh
clean: clean:
@echo "Cleaning up build artifacts..." @echo "Cleaning up build artifacts..."
@rm -f $(BINARY_NAME) public/manifest.json @rm -f $(BINARY_NAME) public/manifest.json
@rm -rf public/assets @rm -rf public/assets build
clean_docker: clean_docker:
@echo "Cleaning up Docker image..." @echo "Cleaning up Docker image..."

View file

@ -50,7 +50,7 @@ version: "3"
services: services:
opengist: opengist:
image: ghcr.io/thomiceli/opengist:1.4 image: ghcr.io/thomiceli/opengist:1
container_name: opengist container_name: opengist
restart: unless-stopped restart: unless-stopped
ports: ports:
@ -71,6 +71,20 @@ services:
GID: 1001 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 ### 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+) 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+)

View file

@ -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 # Set the log level to one of the following: trace, debug, info, warn, error, fatal, panic. Default: warn
log-level: warn log-level: warn

View file

@ -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. [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. 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 ## Components

View file

@ -41,6 +41,20 @@ services:
GID: 1001 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 ## From source

64
scripts/build-all.sh Executable file
View 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
View file