1+ name : Build and Publish Docker Image
2+
3+ on :
4+ push :
5+ tags : [ 'v*.*.*' ]
6+ branches : [ main ]
7+ paths :
8+ - " frontend/**"
9+
10+
11+ env :
12+ REGISTRY : ghcr.io
13+ IMAGE_NAME : ${{ github.repository }}
14+
15+
16+ jobs :
17+ build-and-publish-docker-image :
18+
19+ runs-on : ubuntu-latest
20+ permissions :
21+ contents : read
22+ packages : write
23+ id-token : write
24+
25+ steps :
26+ - name : Checkout repository
27+ uses : actions/checkout@v4
28+
29+ - name : Install cosign
30+ if : github.event_name != 'pull_request'
31+ uses : sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 # v3.5.0
32+ with :
33+ cosign-release : ' v2.2.4'
34+
35+ - name : Set up Docker Buildx
36+ uses : docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
37+
38+ - name : Log into registry ${{ env.REGISTRY }}
39+ if : github.event_name != 'pull_request'
40+ uses : docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
41+ with :
42+ registry : ${{ env.REGISTRY }}
43+ username : ${{ github.actor }}
44+ password : ${{ secrets.GITHUB_TOKEN }}
45+
46+ - name : Extract Docker metadata
47+ id : meta
48+ uses : docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
49+ with :
50+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
51+
52+ - name : Build and push Docker image
53+ id : build-and-push
54+ uses : docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
55+ with :
56+ context : frontend/
57+ push : ${{ github.event_name != 'pull_request' }}
58+ tags : ${{ steps.meta.outputs.tags }}
59+ labels : ${{ steps.meta.outputs.labels }}
60+ cache-from : type=gha
61+ cache-to : type=gha,mode=max
62+
63+ - name : Sign the published Docker image
64+ if : ${{ github.event_name != 'pull_request' }}
65+ env :
66+ # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
67+ TAGS : ${{ steps.meta.outputs.tags }}
68+ DIGEST : ${{ steps.build-and-push.outputs.digest }}
69+ run : echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
70+
71+ # - name: Dokploy Deployment
72+ # if: github.ref == 'refs/heads/main' && github.event_name == 'push'
73+ # run: |
74+ # response=$(curl -X 'POST' \
75+ # "$DOKPLOY_URL/api/application.deploy" \
76+ # -H 'accept: application/json' \
77+ # -H 'Content-Type: application/json' \
78+ # -H "x-api-key: $DOKPLOY_AUTH_TOKEN" \
79+ # -d "{\"applicationId\": \"$DOKPLOY_APPLICATION_ID\"}" \
80+ # -w "%{http_code}" \
81+ # -o /dev/null \
82+ # -s)
83+
84+ # if [ "$response" -ne 200 ]; then
85+ # echo "Deployment failed with status code: $response"
86+ # exit 1
87+ # fi
88+ # env:
89+ # DOKPLOY_AUTH_TOKEN: ${{ secrets.DOKPLOY_AUTH_TOKEN }}
90+ # DOKPLOY_APPLICATION_ID: ${{ secrets.DOKPLOY_APPLICATION_ID }}
91+ # DOKPLOY_URL: ${{ secrets.DOKPLOY_URL }}
0 commit comments