Skip to content

Docker Publish (prod) #25

Docker Publish (prod)

Docker Publish (prod) #25

name: Docker Publish (prod)
on:
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Copy .env
run: |
if [[ ! -f '.env' ]];then
cp '.env.example' '.env'
fi
- name: Dotenv Action
uses: falti/dotenv-action@v1
with:
export-variables: true
keys-case: upper
# 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@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern=prod-{{raw}}
type=raw,value=prod-{{date 'YYYYMMDD-hhmmss' tz='Europe/Amsterdam'}}
type=raw,value=prod-{{branch}}-{{sha}}
type=raw,value=prod
# 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
uses: docker/build-push-action@v5
with:
context: ${{ github.workspace }}
file: Dockerfile.prod
build-args: WWWGROUP=${{ env.WWWGROUP }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}