diff --git a/.github/workflows/docker.yml b/.github/workflows/release.yml similarity index 69% rename from .github/workflows/docker.yml rename to .github/workflows/release.yml index 05ef3ede..9d97fc84 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/release.yml @@ -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: diff --git a/.gitignore b/.gitignore index 10601165..e96bcd28 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ gist.db public/assets/* public/manifest.json opengist +build/ diff --git a/Makefile b/Makefile index 80c713bc..012a3977 100644 --- a/Makefile +++ b/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..." diff --git a/README.md b/README.md index 1c2a3dff..07973907 100644 --- a/README.md +++ b/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+) diff --git a/config.yml b/config.yml index ea947729..f48d79ed 100644 --- a/config.yml +++ b/config.yml @@ -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 diff --git a/docs/index.md b/docs/index.md index 09a0c883..27cc6271 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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 diff --git a/docs/installation.md b/docs/installation.md index 3def0269..33ac1840 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -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 diff --git a/scripts/build-all.sh b/scripts/build-all.sh new file mode 100755 index 00000000..fe567100 --- /dev/null +++ b/scripts/build-all.sh @@ -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." diff --git a/watch.sh b/scripts/watch.sh old mode 100644 new mode 100755 similarity index 100% rename from watch.sh rename to scripts/watch.sh