chore: support github action to push to docker.io

This commit is contained in:
insleker 2025-09-04 21:23:44 +08:00
parent bec3f38cc5
commit d5d5ab9a90
3 changed files with 96 additions and 0 deletions

93
.github/workflows/docker-publish.yml vendored Normal file
View File

@ -0,0 +1,93 @@
name: Publish Docker image
on:
push:
branches: [ "main" ]
tags:
- "v*"
workflow_dispatch:
permissions:
contents: read
packages: write
env:
REGISTRY: docker.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
name: Build and push image
runs-on: ubuntu-latest
concurrency:
group: docker-${{ github.ref }}
cancel-in-progress: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU (for multi-arch builds)
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('Dockerfile', 'pubspec.lock') }}
restore-keys: |
${{ runner.os }}-buildx-
# Docker Hub login (active)
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# GHCR login (commented out for future usage)
# - 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 Docker metadata (tags, labels)
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}}
flavor: |
latest=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
- name: Move cache
if: always()
run: |
if [ -d /tmp/.buildx-cache-new ]; then
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
else
echo "No new cache to move"
fi

1
.gitignore vendored
View File

@ -125,6 +125,7 @@ devtools_options.yaml
test/features/*_test.dart test/features/*_test.dart
**/app_localizations*.dart **/app_localizations*.dart
.env .env
.secrets
docs/wireframe.assets/*.excalidraw.svg docs/wireframe.assets/*.excalidraw.svg
docs/wireframe.assets/*.svg docs/wireframe.assets/*.svg
docs/wireframe.assets/*.png docs/wireframe.assets/*.png

View File

@ -57,6 +57,8 @@ docker build -t pdf_signature .
# Run the container (serves static files on port 8080) # Run the container (serves static files on port 8080)
docker run --rm -p 8080:8080 pdf_signature docker run --rm -p 8080:8080 pdf_signature
# act push -P ubuntu-latest=catthehacker/ubuntu:act-latest --container-options "--privileged" --env-file .env --secret-file .secrets
``` ```
Access your app at [http://localhost:8080](http://localhost:8080) Access your app at [http://localhost:8080](http://localhost:8080)