From 465823237f75c82a2f36bbba60dd0b8af8619f36 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sat, 1 Jul 2023 08:35:41 +0200 Subject: [PATCH] build: Build and publish Docker images for relay and discovery server (fixes #8691, fixes #8960) This adds builds for the discovery and relay servers in the same manner as Syncthing, so that Docker images are kept up to date with releases. Inspired by and closes #8834. Co-authored-by: Migelo --- .github/workflows/build-syncthing.yaml | 29 +++++++++++++++++++------- Dockerfile.stdiscosrv | 13 ++++++++---- Dockerfile.strelaysrv | 13 ++++++++---- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build-syncthing.yaml b/.github/workflows/build-syncthing.yaml index 1366122c5..75c05004c 100644 --- a/.github/workflows/build-syncthing.yaml +++ b/.github/workflows/build-syncthing.yaml @@ -647,6 +647,19 @@ jobs: runs-on: ubuntu-latest if: github.event_name == 'push' && (github.ref == 'refs/heads/release' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-')) environment: docker + strategy: + matrix: + pkg: + - syncthing + - strelaysrv + - stdiscosrv + include: + - pkg: syncthing + dockerfile: Dockerfile + - pkg: strelaysrv + dockerfile: Dockerfile.strelaysrv + - pkg: stdiscosrv + dockerfile: Dockerfile.stdiscosrv steps: - uses: actions/checkout@v3 with: @@ -663,13 +676,13 @@ jobs: path: | ~/.cache/go-build ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ env.GO_VERSION }}-docker-${{ hashFiles('**/go.sum') }} + key: ${{ runner.os }}-go-${{ env.GO_VERSION }}-docker-${{ matrix.pkg }}-${{ hashFiles('**/go.sum') }} - name: Build binaries run: | for arch in arm64 amd64; do - go run build.go -goos linux -goarch "$arch" -no-upgrade build syncthing - mv syncthing syncthing-linux-"$arch" + go run build.go -goos linux -goarch "$arch" -no-upgrade build ${{ matrix.pkg }} + mv ${{ matrix.pkg }} ${{ matrix.pkg }}-linux-"$arch" done env: CGO_ENABLED: "0" @@ -692,21 +705,21 @@ jobs: echo Release version, pushing to :latest and version tags major=${version%.*.*} minor=${version%.*} - tags=syncthing/syncthing:$version,syncthing/syncthing:$major,syncthing/syncthing:$minor,syncthing/syncthing:latest + tags=syncthing/${{ matrix.pkg }}:$version,syncthing/${{ matrix.pkg }}:$major,syncthing/${{ matrix.pkg }}:$minor,syncthing/${{ matrix.pkg }}:latest elif [[ $version == *-rc.@([0-9]|[0-9][0-9]) ]] ; then echo Release candidate, pushing to :rc - tags=syncthing/syncthing:rc + tags=syncthing/${{ matrix.pkg }}:rc else echo Development version, pushing to :edge - tags=syncthing/syncthing:edge + tags=syncthing/${{ matrix.pkg }}:edge fi echo "DOCKER_TAGS=$tags" >> $GITHUB_ENV - - name: Build and push syncthing + - name: Build and push Docker image uses: docker/build-push-action@v4 with: context: . - file: ./Dockerfile + file: ${{ matrix.dockerfile }} platforms: linux/amd64,linux/arm64 push: true tags: ${{ env.DOCKER_TAGS }} diff --git a/Dockerfile.stdiscosrv b/Dockerfile.stdiscosrv index 2373b7cd9..6adb5dcc3 100644 --- a/Dockerfile.stdiscosrv +++ b/Dockerfile.stdiscosrv @@ -1,15 +1,20 @@ ARG GOVERSION=latest FROM golang:$GOVERSION AS builder +ARG BUILD_USER +ARG BUILD_HOST +ARG TARGETARCH WORKDIR /src COPY . . ENV CGO_ENABLED=0 -ENV BUILD_HOST=syncthing.net -ENV BUILD_USER=docker -RUN rm -f stdiscosrv && go run build.go -no-upgrade build stdiscosrv +RUN if [ ! -f stdiscosrv-linux-$TARGETARCH ] ; then \ + go run build.go -no-upgrade build stdiscosrv ; \ + mv stdiscosrv stdiscosrv-linux-$TARGETARCH ; \ + fi FROM alpine +ARG TARGETARCH EXPOSE 19200 8443 @@ -17,7 +22,7 @@ VOLUME ["/var/stdiscosrv"] RUN apk add --no-cache ca-certificates su-exec -COPY --from=builder /src/stdiscosrv /bin/stdiscosrv +COPY --from=builder /src/stdiscosrv-linux-$TARGETARCH /bin/stdiscosrv COPY --from=builder /src/script/docker-entrypoint.sh /bin/entrypoint.sh ENV PUID=1000 PGID=1000 HOME=/var/stdiscosrv diff --git a/Dockerfile.strelaysrv b/Dockerfile.strelaysrv index 26bbf0098..841d2feb3 100644 --- a/Dockerfile.strelaysrv +++ b/Dockerfile.strelaysrv @@ -1,15 +1,20 @@ ARG GOVERSION=latest FROM golang:$GOVERSION AS builder +ARG BUILD_USER +ARG BUILD_HOST +ARG TARGETARCH WORKDIR /src COPY . . ENV CGO_ENABLED=0 -ENV BUILD_HOST=syncthing.net -ENV BUILD_USER=docker -RUN rm -f strelaysrv && go run build.go -no-upgrade build strelaysrv +RUN if [ ! -f strelaysrv-linux-$TARGETARCH ] ; then \ + go run build.go -no-upgrade build strelaysrv ; \ + mv strelaysrv strelaysrv-linux-$TARGETARCH ; \ + fi FROM alpine +ARG TARGETARCH EXPOSE 22067 22070 @@ -17,7 +22,7 @@ VOLUME ["/var/strelaysrv"] RUN apk add --no-cache ca-certificates su-exec -COPY --from=builder /src/strelaysrv /bin/strelaysrv +COPY --from=builder /src/strelaysrv-linux-$TARGETARCH /bin/strelaysrv COPY --from=builder /src/script/docker-entrypoint.sh /bin/entrypoint.sh ENV PUID=1000 PGID=1000 HOME=/var/strelaysrv