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 <miha@filetki.si>
This commit is contained in:
Jakob Borg 2023-07-01 08:35:41 +02:00
parent 5a1f996e56
commit 465823237f
3 changed files with 39 additions and 16 deletions

View File

@ -647,6 +647,19 @@ jobs:
runs-on: ubuntu-latest 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-')) if: github.event_name == 'push' && (github.ref == 'refs/heads/release' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-'))
environment: docker environment: docker
strategy:
matrix:
pkg:
- syncthing
- strelaysrv
- stdiscosrv
include:
- pkg: syncthing
dockerfile: Dockerfile
- pkg: strelaysrv
dockerfile: Dockerfile.strelaysrv
- pkg: stdiscosrv
dockerfile: Dockerfile.stdiscosrv
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
with: with:
@ -663,13 +676,13 @@ jobs:
path: | path: |
~/.cache/go-build ~/.cache/go-build
~/go/pkg/mod ~/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 - name: Build binaries
run: | run: |
for arch in arm64 amd64; do for arch in arm64 amd64; do
go run build.go -goos linux -goarch "$arch" -no-upgrade build syncthing go run build.go -goos linux -goarch "$arch" -no-upgrade build ${{ matrix.pkg }}
mv syncthing syncthing-linux-"$arch" mv ${{ matrix.pkg }} ${{ matrix.pkg }}-linux-"$arch"
done done
env: env:
CGO_ENABLED: "0" CGO_ENABLED: "0"
@ -692,21 +705,21 @@ jobs:
echo Release version, pushing to :latest and version tags echo Release version, pushing to :latest and version tags
major=${version%.*.*} major=${version%.*.*}
minor=${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 elif [[ $version == *-rc.@([0-9]|[0-9][0-9]) ]] ; then
echo Release candidate, pushing to :rc echo Release candidate, pushing to :rc
tags=syncthing/syncthing:rc tags=syncthing/${{ matrix.pkg }}:rc
else else
echo Development version, pushing to :edge echo Development version, pushing to :edge
tags=syncthing/syncthing:edge tags=syncthing/${{ matrix.pkg }}:edge
fi fi
echo "DOCKER_TAGS=$tags" >> $GITHUB_ENV echo "DOCKER_TAGS=$tags" >> $GITHUB_ENV
- name: Build and push syncthing - name: Build and push Docker image
uses: docker/build-push-action@v4 uses: docker/build-push-action@v4
with: with:
context: . context: .
file: ./Dockerfile file: ${{ matrix.dockerfile }}
platforms: linux/amd64,linux/arm64 platforms: linux/amd64,linux/arm64
push: true push: true
tags: ${{ env.DOCKER_TAGS }} tags: ${{ env.DOCKER_TAGS }}

View File

@ -1,15 +1,20 @@
ARG GOVERSION=latest ARG GOVERSION=latest
FROM golang:$GOVERSION AS builder FROM golang:$GOVERSION AS builder
ARG BUILD_USER
ARG BUILD_HOST
ARG TARGETARCH
WORKDIR /src WORKDIR /src
COPY . . COPY . .
ENV CGO_ENABLED=0 ENV CGO_ENABLED=0
ENV BUILD_HOST=syncthing.net RUN if [ ! -f stdiscosrv-linux-$TARGETARCH ] ; then \
ENV BUILD_USER=docker go run build.go -no-upgrade build stdiscosrv ; \
RUN rm -f stdiscosrv && go run build.go -no-upgrade build stdiscosrv mv stdiscosrv stdiscosrv-linux-$TARGETARCH ; \
fi
FROM alpine FROM alpine
ARG TARGETARCH
EXPOSE 19200 8443 EXPOSE 19200 8443
@ -17,7 +22,7 @@ VOLUME ["/var/stdiscosrv"]
RUN apk add --no-cache ca-certificates su-exec 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 COPY --from=builder /src/script/docker-entrypoint.sh /bin/entrypoint.sh
ENV PUID=1000 PGID=1000 HOME=/var/stdiscosrv ENV PUID=1000 PGID=1000 HOME=/var/stdiscosrv

View File

@ -1,15 +1,20 @@
ARG GOVERSION=latest ARG GOVERSION=latest
FROM golang:$GOVERSION AS builder FROM golang:$GOVERSION AS builder
ARG BUILD_USER
ARG BUILD_HOST
ARG TARGETARCH
WORKDIR /src WORKDIR /src
COPY . . COPY . .
ENV CGO_ENABLED=0 ENV CGO_ENABLED=0
ENV BUILD_HOST=syncthing.net RUN if [ ! -f strelaysrv-linux-$TARGETARCH ] ; then \
ENV BUILD_USER=docker go run build.go -no-upgrade build strelaysrv ; \
RUN rm -f strelaysrv && go run build.go -no-upgrade build strelaysrv mv strelaysrv strelaysrv-linux-$TARGETARCH ; \
fi
FROM alpine FROM alpine
ARG TARGETARCH
EXPOSE 22067 22070 EXPOSE 22067 22070
@ -17,7 +22,7 @@ VOLUME ["/var/strelaysrv"]
RUN apk add --no-cache ca-certificates su-exec 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 COPY --from=builder /src/script/docker-entrypoint.sh /bin/entrypoint.sh
ENV PUID=1000 PGID=1000 HOME=/var/strelaysrv ENV PUID=1000 PGID=1000 HOME=/var/strelaysrv