From ed57e37b110693a3275faf3db532f51cbba37fb7 Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Mon, 28 Feb 2022 15:34:23 +0100 Subject: [PATCH] Publish docker image in GHCR (#21) --- .github/workflows/build.yml | 27 +++++++++++++++++++++++++++ Dockerfile | 17 +++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 Dockerfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ecf4e24..17db6ff 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,6 +12,22 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Determine Version + run: | + # determine version from tag + export VERSION=$(echo "${GITHUB_REF}" | cut -d "/" -f3) + if [[ $VERSION != v* ]] + then + export VERSION="" + echo "Building version-less (main or feature branch)" + else + # make version more Docker-friendly by dropping the 'v' + export VERSION=${VERSION:1:${#VERSION}} + echo "Building as ${VERSION}" + fi + echo "##[set-output name=version;]$VERSION" + id: determine_version + - name: Set up Go uses: actions/setup-go@v2 with: @@ -30,3 +46,14 @@ jobs: with: files: coverage.cov flags: unittests + + - name: Push Release Docker Image + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + docker build -t ghcr.io/oxisto/oauth2go:latest . + docker tag ghcr.io/oxisto/oauth2go:latest ghcr.io/oxisto/oauth2go:$VERSION + docker push ghcr.io/oxisto/oauth2go:$VERSION + docker push ghcr.io/oxisto/oauth2go:latest + if: startsWith(github.ref, 'refs/tags/v') + env: + VERSION: ${{ steps.determine_version.outputs.version }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e012515 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM golang as builder + +WORKDIR /build + +ADD go.mod . +ADD go.sum . + +ADD . . + +# Disable cgo because our final image will be alpine and will not have the same C stdlib +RUN CGO_ENABLED=0 go build cmd/server/server.go + +FROM alpine + +COPY --from=builder /build/server / + +CMD ["./server"]