Skip to content

Use Blacksmith for template builds #1

Use Blacksmith for template builds

Use Blacksmith for template builds #1

Workflow file for this run

name: Docker Build and Push
on:
push:
branches:
- main
tags:
- v*
pull_request:
branches:
- main
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
ENVIRONMENT: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && 'production' || 'preview' }}
jobs:
build:
runs-on: blacksmith-4vcpu-ubuntu-2404
permissions:
contents: write
packages: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Blacksmith Builder
uses: useblacksmith/setup-docker-builder@v1
- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
uses: docker/metadata-action@v5
id: meta
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=raw,value=pr-${{ github.event.number }}-{{date 'YYYYMMDDHHmmss'}},enable=${{ github.event_name == 'pull_request' }}
type=raw,value=edge-{{date 'YYYYMMDDHHmmss'}},enable={{is_default_branch}}
- name: Build and push Docker images
uses: useblacksmith/build-push-action@v2
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64
- name: Generate comment content
id: comment
run: |
COMMENT_BODY="**🐳 Docker images built and pushed to GitHub Container Registry**
<details>
<summary>🏷️ View image tags and details</summary>
**Available Image Tags**
\`\`\`
${{ steps.meta.outputs.tags }}
\`\`\`
</details>"
echo "body<<EOF" >> $GITHUB_OUTPUT
echo "$COMMENT_BODY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Add comment to commit
uses: peter-evans/commit-comment@v3
with:
body: ${{ steps.comment.outputs.body }}
- name: Add comment to pull request (if applicable)
if: github.event_name == 'pull_request'
uses: thollander/actions-comment-pull-request@v2
with:
comment_tag: image_tags
message: ${{ steps.comment.outputs.body }}