From d5d5ab9a908070a644d8d447827c9fdd90cd5b8b Mon Sep 17 00:00:00 2001 From: insleker Date: Thu, 4 Sep 2025 21:23:44 +0800 Subject: [PATCH] chore: support github action to push to docker.io --- .github/workflows/docker-publish.yml | 93 ++++++++++++++++++++++++++++ .gitignore | 1 + README.md | 2 + 3 files changed, 96 insertions(+) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..d467e89 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -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 diff --git a/.gitignore b/.gitignore index c8cd119..d30f692 100644 --- a/.gitignore +++ b/.gitignore @@ -125,6 +125,7 @@ devtools_options.yaml test/features/*_test.dart **/app_localizations*.dart .env +.secrets docs/wireframe.assets/*.excalidraw.svg docs/wireframe.assets/*.svg docs/wireframe.assets/*.png diff --git a/README.md b/README.md index df371c9..d64fffb 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,8 @@ docker build -t pdf_signature . # Run the container (serves static files on port 8080) 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)