From faecf1a3929400884aea1d103802fc6d96f67113 Mon Sep 17 00:00:00 2001 From: Marco Argentieri <3596602+tiero@users.noreply.github.com> Date: Thu, 15 Aug 2024 04:52:04 +0200 Subject: [PATCH] gha release: split docker and binaries. tag name as VERSION in build-arg (#256) * client: print version * arkd: add --version * release action refactor --- .github/workflows/ark.release.yaml | 26 +++++--- Dockerfile | 6 +- server/.goreleaser.yaml | 99 ------------------------------ server/goreleaser.Dockerfile | 35 ----------- 4 files changed, 18 insertions(+), 148 deletions(-) delete mode 100755 server/.goreleaser.yaml delete mode 100755 server/goreleaser.Dockerfile diff --git a/.github/workflows/ark.release.yaml b/.github/workflows/ark.release.yaml index bb488ac..0b4f052 100755 --- a/.github/workflows/ark.release.yaml +++ b/.github/workflows/ark.release.yaml @@ -1,18 +1,16 @@ -name: release +name: Release Binaries and Docker Build on: release: types: [released] - permissions: contents: write packages: write - -jobs: - build: - runs-on: ubuntu-latest +jobs: + build-and-upload: + runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 @@ -22,10 +20,11 @@ jobs: with: go-version: 1.21.0 + # Build binaries for all architectures - name: Build binaries run: make build-all - # Server + # Server binary uploads - name: Upload server binary (Linux, AMD64) uses: actions/upload-release-asset@v1 env: @@ -66,7 +65,7 @@ jobs: asset_name: arkd-darwin-arm64 asset_content_type: application/octet-stream - # CLI + # CLI binary uploads - name: Upload client binary (Linux, AMD64) uses: actions/upload-release-asset@v1 env: @@ -107,7 +106,7 @@ jobs: asset_name: ark-darwin-arm64 asset_content_type: application/octet-stream - # WASM SDK + # WASM SDK upload - name: Upload WASM SDK uses: actions/upload-release-asset@v1 env: @@ -118,7 +117,12 @@ jobs: asset_name: ark-sdk.wasm asset_content_type: application/wasm - # Docker + docker-build-and-push: + runs-on: ubuntu-latest + needs: build-and-upload + steps: + - name: Checkout code + uses: actions/checkout@v2 - name: Set up Docker uses: docker/setup-buildx-action@v1 @@ -137,3 +141,5 @@ jobs: push: true tags: ghcr.io/${{ github.repository }}:${{ github.event.release.tag_name }},ghcr.io/${{ github.repository }}:latest platforms: linux/amd64,linux/arm64 + build-args: | + VERSION=${{ github.event.release.tag_name }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index d839fc9..522ad64 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,6 @@ FROM golang:1.21.0 AS builder ARG VERSION -ARG COMMIT -ARG DATE ARG TARGETOS ARG TARGETARCH @@ -12,8 +10,8 @@ WORKDIR /app COPY . . ENV GOPROXY=https://goproxy.io,direct -RUN cd server && CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-X 'main.Version=${VERSION}' -X 'main.Commit=${COMMIT}' -X 'main.Date=${DATE}}'" -o ../bin/arkd ./cmd/arkd -RUN cd client && CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-X 'main.Version=${VERSION}}' -X 'main.Commit=${COMMIT}' -X 'main.Date=${DATE}}'" -o ../bin/ark . +RUN cd server && CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-X 'main.Version=${VERSION}'" -o ../bin/arkd ./cmd/arkd +RUN cd client && CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-X 'main.Version=${VERSION}}'" -o ../bin/ark . # Second image, running the arkd executable FROM alpine:3.12 diff --git a/server/.goreleaser.yaml b/server/.goreleaser.yaml deleted file mode 100755 index ab83b2a..0000000 --- a/server/.goreleaser.yaml +++ /dev/null @@ -1,99 +0,0 @@ -builds: - - id: "arkd" - main: ./cmd/arkd - ldflags: - - -s -X 'main.version={{.Version}}' -X 'main.commit={{.Commit}}' -X 'main.date={{.Date}}' - goos: - - linux - - darwin - goarch: - - amd64 - - arm64 - binary: arkd - -## flag the semver v**.**.**-.* as pre-release on Github -release: - prerelease: auto - -checksum: - name_template: "checksums.txt" - -snapshot: - name_template: "{{ .Tag }}-next" - -changelog: - use: github-native - -archives: - - id: arkd - format: binary - builds: - - arkd - name_template: "arkd-v{{ .Version }}-{{ .Os }}-{{ .Arch }}" - -dockers: - ########################### - # tag latest & prerelease # - ########################### - - #amd64 - - image_templates: - - "ghcr.io/ark-network/arkd:{{ .Tag }}-amd64" - # push always either release or prerelease with a docker tag with the semver only - skip_push: "false" - use: buildx - ids: - - arkd - dockerfile: goreleaser.Dockerfile - # GOOS of the built binaries/packages that should be used. - goos: linux - # GOARCH of the built binaries/packages that should be used. - goarch: amd64 - # Template of the docker build flags. - build_flag_templates: - - "--platform=linux/amd64" - - "--pull" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title=arkd" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - - "--build-arg=VERSION={{.Version}}" - - "--build-arg=COMMIT={{.Commit}}" - - "--build-arg=DATE={{.Date}}" - - image_templates: - - "ghcr.io/ark-network/arkd:{{ .Tag }}-arm64v8" - # push always either release or prerelease with a docker tag with the semver only - skip_push: "false" - use: buildx - ids: - - arkd - dockerfile: goreleaser.Dockerfile - # GOOS of the built binaries/packages that should be used. - goos: linux - # GOARCH of the built binaries/packages that should be used. - goarch: arm64 - # Template of the docker build flags. - build_flag_templates: - - "--platform=linux/arm64/v8" - - "--pull" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title=arkd" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - - "--build-arg=VERSION={{.Version}}" - - "--build-arg=COMMIT={{.Commit}}" - - "--build-arg=DATE={{.Date}}" - -docker_manifests: - - name_template: ghcr.io/ark-network/arkd:{{ .Tag }} - image_templates: - - ghcr.io/ark-network/arkd:{{ .Tag }}-amd64 - - ghcr.io/ark-network/arkd:{{ .Tag }}-arm64v8 - skip_push: "false" - - - name_template: ghcr.io/ark-network/arkd:latest - image_templates: - - ghcr.io/ark-network/arkd:{{ .Tag }}-amd64 - - ghcr.io/ark-network/arkd:{{ .Tag }}-arm64v8 - skip_push: auto - \ No newline at end of file diff --git a/server/goreleaser.Dockerfile b/server/goreleaser.Dockerfile deleted file mode 100755 index 753614e..0000000 --- a/server/goreleaser.Dockerfile +++ /dev/null @@ -1,35 +0,0 @@ -FROM debian:buster-slim - -ARG TARGETPLATFORM - -WORKDIR /app - -COPY . . - -RUN set -ex \ - && if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then export TARGETPLATFORM=amd64; fi \ - && if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then export TARGETPLATFORM=arm64; fi \ - && mv "arkd-linux-$TARGETPLATFORM" /usr/local/bin/arkd - - -# $USER name, and data $DIR to be used in the 'final' image -ARG USER=ark -ARG DIR=/home/ark - -RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates - -# NOTE: Default GID == UID == 1000 -RUN adduser --disabled-password \ - --home "$DIR/" \ - --gecos "" \ - "$USER" -USER $USER - -# Prevents 'VOLUME $DIR/.arkd/' being created as owned by 'root' -RUN mkdir -p "$DIR/.arkd/" - -# Expose volume containing all arkd data -VOLUME $DIR/.arkd/ - -ENTRYPOINT [ "arkd" ] - \ No newline at end of file