From e3b209e38988fcf70b4e635a1ab7588bcd7907f7 Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Tue, 7 Oct 2025 20:15:24 +0700 Subject: [PATCH] feat(template): add template --- .github/workflows/template.yml | 64 ++++++++++++++++++++++++++++++++++ README.md | 7 ++++ 2 files changed, 71 insertions(+) create mode 100644 .github/workflows/template.yml diff --git a/.github/workflows/template.yml b/.github/workflows/template.yml new file mode 100644 index 0000000..5a4f088 --- /dev/null +++ b/.github/workflows/template.yml @@ -0,0 +1,64 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +# GitHub recommends pinning actions to a commit SHA. +# To get a newer version, you will need to update the SHA. +# You can also reference a tag or branch, but the action may change without warning. + +name: Publish Docker image + +on: + release: + types: [published] + +jobs: + push_to_registries: + name: Push Docker image to multiple registries + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + attestations: write + id-token: write + steps: + - name: Check out the repo + uses: actions/checkout@v5 + + - name: Log in to Docker Hub + uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: | + my-docker-hub-namespace/my-docker-hub-repository + ghcr.io/${{ github.repository }} + + - name: Build and push Docker images + id: push + uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v3 + with: + subject-name: ghcr.io/${{ github.repository }} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true diff --git a/README.md b/README.md index c911e91..515fe03 100644 --- a/README.md +++ b/README.md @@ -35,3 +35,10 @@ More options: https://github.com/tiennm99/docker-images/pkgs/container/docker-im - https://www.oracle.com/java/technologies/javase/javase8-archive-downloads.html - https://repo.huaweicloud.com/java/jdk/8u201-b09/ + + +## GitHub Actions template + +### Credits + +- https://docs.github.com/en/actions/tutorials/publish-packages/publish-docker-images