Docker #547
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker | |
on: | |
push: | |
# Publish `v1.2.3` tags as releases. | |
tags: | |
- v* | |
workflow_run: | |
workflows: [Django Tests] | |
types: | |
- completed | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
# Run tests. | |
# See also https://docs.docker.com/docker-hub/builds/automated-testing/ | |
test: | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Run tests | |
run: | | |
if [ -f docker-compose.test.yml ]; then | |
docker compose --file docker-compose.test.yml build | |
docker compose --file docker-compose.test.yml run sut | |
else | |
docker build . --file Dockerfile | |
fi | |
# Push image to GitHub Packages. | |
publish: | |
# Ensure test job passes before pushing image. | |
needs: test | |
runs-on: ubuntu-latest | |
if: github.event.workflow_run && github.event.workflow_run.head_branch == 'refs/heads/master' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} | |
- name: Build and push Docker images | |
uses: docker/[email protected] | |
with: | |
context: . | |
push: ${{ github.event_name != 'pull_request' }} | |
pull: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |