Skip to content

Commit

Permalink
Added some extra variables to the built docker image. Include push to…
Browse files Browse the repository at this point in the history
… ghcr.io.
  • Loading branch information
knicholson32 committed Dec 22, 2023
1 parent d62009a commit cee7504
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
43 changes: 35 additions & 8 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: ci

on:
push:
branches:
- "main"
workflow_dispatch:
# push:
# branches:
# - "main"

jobs:
build:
Expand All @@ -21,7 +22,9 @@ jobs:
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ vars.REGISTRY_IMAGE }}
images: |
${{ vars.REGISTRY_IMAGE }}
ghcr.io/${{ vars.REGISTRY_IMAGE }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
Expand All @@ -31,6 +34,12 @@ jobs:
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: build
uses: docker/build-push-action@v5
Expand All @@ -41,6 +50,8 @@ jobs:
GIT_COMMIT=${{ github.sha }}
GIT_REF=${{ github.ref_name }}
GIT_REF_PROTECTED=${{ github.ref_protected }}
REGISTRY_IMAGE=${{ vars.REGISTRY_IMAGE }}
CI=true
file: docker/Dockerfile
outputs: type=image,name=${{ vars.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
labels: ${{ steps.meta.outputs.labels }}
Expand Down Expand Up @@ -75,17 +86,33 @@ jobs:
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ vars.REGISTRY_IMAGE }}
images: |
${{ vars.REGISTRY_IMAGE }}
ghcr.io/${{ vars.REGISTRY_IMAGE }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Create manifest list and push
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create manifest list and push DockerHub
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ vars.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
- name: Inspect image DockerHub
run: |
docker buildx imagetools inspect ${{ vars.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
- name: Create manifest list and push ghcr.io
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf 'ghcr.io/${{ vars.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image ghcr.io
run: |
docker buildx imagetools inspect ${{ vars.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
docker buildx imagetools inspect ghcr.io/${{ vars.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
9 changes: 9 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,16 @@ RUN echo "---- Install Production Dependancies ----" \
COPY --from=build "/app/build/" "/app/"

ARG GIT_COMMIT
ARG GIT_REF
ARG GIT_REF_PROTECTED
ARG REGISTRY_IMAGE
ARG CI

ENV GIT_COMMIT=$GIT_COMMIT
ENV GIT_REF=$GIT_REF
ENV GIT_REF_PROTECTED=$GIT_REF_PROTECTED
ENV REGISTRY_IMAGE=$REGISTRY_IMAGE
ENV CI=$CI

STOPSIGNAL SIGKILL
# Set Docker command entry point and expose the proper port
Expand Down

0 comments on commit cee7504

Please sign in to comment.