Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Create a manifest list for webapp Docker image and push it to DockerHub. #436

Merged
merged 13 commits into from
May 9, 2024
55 changes: 42 additions & 13 deletions .github/workflows/build-deploy-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ on:
workflow_dispatch:

env:
REGISTRY: ghcr.io
WEBAPP_IMAGE_NAME: bigcapital/bigcapital-webapp
SERVER_IMAGE_NAME: bigcapital/bigcapital-server
WEBAPP_IMAGE_NAME: bigcapitalhq/webapp
SERVER_IMAGE_NAME: bigcapitalhq/server

jobs:
build-publish-webapp:
Expand Down Expand Up @@ -40,15 +39,14 @@ jobs:
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.WEBAPP_IMAGE_NAME }}
images: ${{ env.WEBAPP_IMAGE_NAME }}

# Builds and push the Docker image.
- name: Build and push Docker image
Expand All @@ -59,8 +57,8 @@ jobs:
file: ./packages/webapp/Dockerfile
platforms: ${{ matrix.platform }}
push: true
tags: ghcr.io/bigcapitalhq/webapp:latest, ghcr.io/bigcapitalhq/webapp:${{github.ref_name}}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=bigcapitalhq/webapp,push-by-digest=true,name-canonical=true,push=true

- name: Export digest
run: |
Expand Down Expand Up @@ -103,9 +101,8 @@ jobs:
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

# Builds and push the Docker image.
- name: Build and push Docker image
Expand All @@ -116,7 +113,7 @@ jobs:
file: ./packages/server/Dockerfile
platforms: ${{ matrix.platform }}
push: true
tags: ghcr.io/bigcapitalhq/server:latest, ghcr.io/bigcapitalhq/server:${{github.ref_name}}
tags: bigcapitalhq/server:latest, bigcapitalhq/server:${{github.ref_name}}
labels: ${{ steps.meta.outputs.labels }}

- name: Export digest
Expand All @@ -137,4 +134,36 @@ jobs:
- name: Slack Notification built and published server container successfully.
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}

merge:
runs-on: ubuntu-latest
needs:
- build-publish-webapp
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.WEBAPP_IMAGE_NAME }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.WEBAPP_IMAGE_NAME }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.WEBAPP_IMAGE_NAME }}:${{ steps.meta.outputs.version }}