Skip to content

Build and Deploy to Docker Hub and GitHub Packages #22

Build and Deploy to Docker Hub and GitHub Packages

Build and Deploy to Docker Hub and GitHub Packages #22

Workflow file for this run

name: Build and Deploy to Docker Hub and GitHub Packages
on:
workflow_run:
workflows: ["Application Tests"]
types:
- completed
branches: [main]
jobs:
check_previous_success:
runs-on: ubuntu-latest
outputs:
success: ${{ steps.check_success.outputs.success }}
steps:
- name: Check if previous workflows were successful
id: check_success
run: |
echo "Workflow conclusion: ${{ github.event.workflow_run.conclusion }}"
if [[ "${{ github.event.workflow_run.conclusion }}" != "success" ]]; then
echo "One or more of the required workflows failed."
echo "::set-output name=success::false"
exit 1
fi
echo "::set-output name=success::true"
build-and-push:
needs: check_previous_success
if: needs.check_previous_success.outputs.success == 'true'
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Log in to GitHub Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_PAT }}
- name: Prepare Docker Metadata
id: meta
uses: docker/metadata-action@v3
with:
images: |
aaronzi/go-demo-api
ghcr.io/${{ github.repository_owner }}/go-demo-api
tags: |
type=sha
type=ref,event=branch
type=semver,pattern={{version}}
- name: Build and Push Docker Image to Docker Hub and GitHub Packages
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64