Skip to content

Commit

Permalink
Add binaries cross compile in CD (thomiceli#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomiceli authored Sep 26, 2023
1 parent 4687bfe commit e008efd
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 7 deletions.
29 changes: 27 additions & 2 deletions .github/workflows/docker.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ gist.db
public/assets/*
public/manifest.json
opengist
build/
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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 .
Expand All @@ -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..."
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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+)
Expand Down
4 changes: 4 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
64 changes: 64 additions & 0 deletions scripts/build-all.sh
Original file line number Diff line number Diff line change
@@ -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
100644 → 100755
File renamed without changes.

0 comments on commit e008efd

Please sign in to comment.