Skip to content

Commit

Permalink
update docker-publish.yml to match other repos
Browse files Browse the repository at this point in the history
  • Loading branch information
ilude committed Mar 26, 2024
1 parent ce13206 commit f4a5e4f
Showing 1 changed file with 66 additions and 29 deletions.
95 changes: 66 additions & 29 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,89 @@
name: Publish Docker Image
name: Build and Publish Docker Image

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
workflow_dispatch:
push:
branches:
- master
- main
branches: [ "main" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
paths:
- 'app/**/*'
- 'Dockerfile'
- 'requirements.txt'
- '.github/workflows/docker-publish.yml'
pull_request:
branches:
- master
- main
permissions:
packages: write
contents: read
branches: [ "main" ]
types: [ closed ]
paths:
- 'app/**/*'
- 'Dockerfile'
- 'requirements.txt'
- '.github/workflows/docker-publish.yml'

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}


jobs:
publish:
build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=sha
- name: Login to GHCR
uses: docker/login-action@v3
- name: Checkout repository
uses: actions/checkout@v3

# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build container
uses: docker/build-push-action@v5

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
push: true
target: production
push: ${{ github.event_name != 'pull_request' }}
tags: ghcr.io/${{ github.repository }}:latest,${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Discord notification
env:
Expand All @@ -60,4 +98,3 @@ jobs:
details: Based on ${{ github.event.head_commit.url }}
footer: MafenBot became self aware
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}

0 comments on commit f4a5e4f

Please sign in to comment.