From 1cdbb58da3b90f498c6a5952c7b0e2f3ebeb87f4 Mon Sep 17 00:00:00 2001 From: weaponsforge Date: Wed, 7 Oct 2026 10:28:22 +0800 Subject: [PATCH] feat: deploy to docker hub on new release/tags --- .github/workflows/release.yml | 70 +++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ae43a57..363cf7f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -70,3 +70,73 @@ jobs: cp docs/README_NPM.md app/README.md cd app npm publish --provenance --access public + + docker-build-push: + name: Build and Push Docker Image + if: github.event.release.target_commitish == 'main' && vars.DOCKERHUB_USERNAME != '' + needs: [lint-test-app] + runs-on: ubuntu-latest + env: + REGISTRY: docker.io + IMAGE_NAME: weaponsforge/cloudinary-cli + permissions: + contents: read + security-events: write + packages: write + steps: + - name: Checkout the repository + uses: actions/checkout@v6 + with: + ref: ${{ github.event.release.tag_name }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Generate Docker Image Tags and Labels + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + # type=semver,pattern={{major}}.{{minor}} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and Push Docker Image + id: build + uses: docker/build-push-action@v6 + with: + context: ./app + file: ./app/Dockerfile + target: production + platforms: linux/amd64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + build-args: | + BUILDKIT_INLINE_CACHE=1 + CACHEBUST=${{ github.run_id }} + + - name: Scan Image for Vulnerabilities + uses: aquasecurity/trivy-action@v0.35.0 + with: + image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }} + format: 'sarif' + output: 'trivy-results.sarif' + + - name: Upload Trivy Scan Results to GitHub Security Tab + uses: github/codeql-action/upload-sarif@v4 + if: always() + with: + sarif_file: 'trivy-results.sarif'