github: add docker build workflow action.

Add an action to build a Docker image and push it to the Github Packages
registry.
This commit is contained in:
evazion
2021-09-03 23:17:14 -05:00
parent 8b85bbe8ea
commit 8aa7608816
2 changed files with 33 additions and 0 deletions

View File

@@ -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

View File

@@ -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