Skip to content

Add Docker support and enhance documentation #2

Add Docker support and enhance documentation

Add Docker support and enhance documentation #2

Workflow file for this run

name: Docker Publish to GHCR
on:
push:
tags:
- 'v*'
- '*'
branches:
- main
- develop
pull_request:
branches:
- main
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
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 Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Test Docker image
if: github.event_name == 'pull_request' || startsWith(github.ref, 'refs/tags/')
run: |
echo "Testing Docker image..."
docker build -f Dockerfile -t localup:test .
docker run --rm localup:test --version
docker run --rm localup:test --help
- name: Create release notes
if: startsWith(github.ref, 'refs/tags/')
id: release_notes
run: |
TAG="${{ github.ref_name }}"
echo "## Docker Image Released: $TAG" > release_notes.md
echo "" >> release_notes.md
echo "### Image Details" >> release_notes.md
echo "- **Registry**: \`${{ env.REGISTRY }}\`" >> release_notes.md
echo "- **Repository**: \`${{ env.IMAGE_NAME }}\`" >> release_notes.md
echo "- **Tags**:" >> release_notes.md
echo " - \`$TAG\`" >> release_notes.md
echo " - \`latest\`" >> release_notes.md
echo "" >> release_notes.md
echo "### Pull Docker Image" >> release_notes.md
echo "\`\`\`bash" >> release_notes.md
echo "docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$TAG" >> release_notes.md
echo "docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> release_notes.md
echo "\`\`\`" >> release_notes.md
echo "" >> release_notes.md
echo "### Run Container" >> release_notes.md
echo "\`\`\`bash" >> release_notes.md
echo "docker run --rm ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$TAG --help" >> release_notes.md
echo "\`\`\`" >> release_notes.md
cat release_notes.md
- name: Upload release notes
if: startsWith(github.ref, 'refs/tags/')
uses: actions/upload-artifact@v4
with:
name: release-notes
path: release_notes.md
- name: Print image details
if: github.event_name != 'pull_request'
run: |
echo "## Docker Image Build Complete ✅"
echo ""
echo "### Build Metadata"
echo "**Images:**"
echo "${{ steps.meta.outputs.tags }}"
echo ""
echo "**Labels:**"
echo "${{ steps.meta.outputs.labels }}"
echo ""
echo "**Pull Commands:**"
for tag in ${{ steps.meta.outputs.tags }}; do
echo " docker pull $tag"
done