From 8aa7608816772f866eeb16fd07db3def093a620c Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 3 Sep 2021 23:17:14 -0500 Subject: [PATCH] github: add docker build workflow action. Add an action to build a Docker image and push it to the Github Packages registry. --- .github/workflows/test.yaml | 30 ++++++++++++++++++++++++++++++ config/docker/Dockerfile.danbooru | 3 +++ 2 files changed, 33 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f834636c4..90b04540e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,6 +10,36 @@ on: - master jobs: + # Build Docker image and push to Github Packages registry. + docker: + runs-on: ubuntu-latest + + defaults: + run: + shell: bash + + env: + IMAGE_NAME: ${{ github.repository }} + IMAGE_ID: ghcr.io/${{ github.repository }} + + steps: + - uses: actions/checkout@v2 + + - name: Build image + run: docker build . --file Dockerfile --tag "$IMAGE_NAME" --label "github_run_id=${{ github.run_id }}" + + - name: Log in to registry + run: docker login ghcr.io -u "${{ github.repository_owner }}" -p "${{ github.token }}" + + - name: Push image + run: | + REF=$(echo ${{ github.sha }} | cut -c1-9) + + docker tag $IMAGE_NAME $IMAGE_ID:$REF + docker tag $IMAGE_NAME $IMAGE_ID:latest + docker push $IMAGE_ID:$REF + docker push $IMAGE_ID:latest + test: runs-on: ubuntu-latest container: ubuntu:20.10 diff --git a/config/docker/Dockerfile.danbooru b/config/docker/Dockerfile.danbooru index 7d77b9292..9aab5c33d 100644 --- a/config/docker/Dockerfile.danbooru +++ b/config/docker/Dockerfile.danbooru @@ -71,3 +71,6 @@ COPY --from=assets /danbooru /danbooru USER danbooru CMD ["bin/rails", "server"] + +# https://github.com/opencontainers/image-spec/blob/main/annotations.md +LABEL org.opencontainers.image.source https://github.com/danbooru/danbooru