Skip to content

Add GitHub action for docker builds #1

Add GitHub action for docker builds

Add GitHub action for docker builds #1

Workflow file for this run

name: Docker Build and Publish
on:
push:
branches:
- master
- '**'
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
run: |
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT
TAGS="ghcr.io/invoiceshelf/docs:$SHORT_SHA"
if [ "${{ github.ref }}" == "refs/heads/master" ]; then
TAGS="$TAGS,ghcr.io/invoiceshelf/docs:latest"
fi
echo "tags=$TAGS" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max