@@ -10,57 +10,70 @@ permissions:
1010 packages : write
1111
1212env :
13+ REGISTRY : ghcr.io
14+ IMAGE_NAME : crunchloop/workshops
1315 AWS_REGION : sa-east-1
1416 EKS_CLUSTER : k8-dev
1517 NAMESPACE : workshops
16- IMAGE_NAME : ghcr.io/crunchloop/workshops
18+ DEPLOY_ROLE_ARN : ${{ vars.AWS_DEPLOY_ROLE_ARN }}
1719
1820jobs :
1921 docker-publish :
2022 runs-on : ubuntu-latest
2123 outputs :
22- image-tag : ${{ steps.meta .outputs.version }}
24+ image-tag : ${{ steps.sha .outputs.short }}
2325 steps :
2426 - uses : actions/checkout@v4
2527
26- - name : Log in to GHCR
27- uses : docker/login-action@v3
28+ - name : Get short SHA
29+ id : sha
30+ run : echo "short=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
31+
32+ - uses : docker/login-action@v3
2833 with :
29- registry : ghcr.io
34+ registry : ${{ env.REGISTRY }}
3035 username : ${{ github.actor }}
3136 password : ${{ secrets.GITHUB_TOKEN }}
3237
33- - name : Docker meta
34- id : meta
38+ - id : meta
3539 uses : docker/metadata-action@v5
3640 with :
37- images : ${{ env.IMAGE_NAME }}
41+ images : ${{ env.REGISTRY }}/${{ env. IMAGE_NAME }}
3842 tags : |
3943 type=sha,prefix=
40- type=raw,value=latest
44+ type=raw,value=latest,enable={{is_default_branch}}
4145
42- - name : Build and push
43- uses : docker/build-push-action@v6
46+ - uses : docker/build-push-action@v6
4447 with :
4548 context : .
4649 push : true
4750 tags : ${{ steps.meta.outputs.tags }}
51+ labels : ${{ steps.meta.outputs.labels }}
4852
4953 deploy :
50- runs-on : ubuntu-latest
5154 needs : docker-publish
55+ runs-on : ubuntu-latest
5256 steps :
5357 - uses : actions/checkout@v4
5458
55- - name : Configure AWS credentials
56- uses : aws-actions/configure-aws-credentials@v4
59+ - uses : aws-actions/configure-aws-credentials@v4
5760 with :
58- role-to-assume : arn:aws:iam::176434290504:role/workshops-github-deploy
59- role-session-name : workshops-github-deploy
61+ role-to-assume : ${{ env.DEPLOY_ROLE_ARN }}
6062 aws-region : ${{ env.AWS_REGION }}
6163
62- - name : Configure kubeconfig
63- run : aws eks update-kubeconfig --name ${{ env.EKS_CLUSTER }} --region ${{ env.AWS_REGION }}
64+ - run : aws eks update-kubeconfig --name ${{ env.EKS_CLUSTER }} --region ${{ env.AWS_REGION }}
65+
66+ - uses : azure/setup-helm@v4
67+
68+ - name : Create GHCR pull secret
69+ run : |
70+ kubectl create namespace ${{ env.NAMESPACE }} --dry-run=client -o yaml | kubectl apply -f -
71+ kubectl create secret docker-registry ghcr-secret \
72+ --namespace ${{ env.NAMESPACE }} \
73+ --docker-server=ghcr.io \
74+ --docker-username=${{ github.actor }} \
75+ --docker-password=${{ secrets.GITHUB_TOKEN }} \
76+ --dry-run=client -o yaml | kubectl apply -f -
6477
6578 - name : Deploy with Helm
6679 run : |
0 commit comments