Skip to content

Commit d00a7e4

Browse files
Merge pull request #355 from adorsys/354-improve-cd-workflow-to-avoid-overusing-runners
fix(ci): restrict CD workflow to main branch only
2 parents 7ab733e + 6e95e05 commit d00a7e4

File tree

1 file changed

+25
-40
lines changed

1 file changed

+25
-40
lines changed

.github/workflows/CD.yml

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ name: Publish Image & Deploy
33
on:
44
push:
55
branches:
6-
- '*'
6+
- main
77
tags:
8-
- 'v*'
9-
8+
- 'v*'
9+
1010
env:
1111
IMAGE_NAME: didcomm-mediator-rs
1212
NAMESPACE: didcomm-mediator
@@ -21,53 +21,38 @@ jobs:
2121
contents: read
2222

2323
steps:
24-
- uses: actions/checkout@v4
25-
26-
- name: Build image
27-
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
28-
29-
- name: Log in to GitHub Container Registry (GHCR)
30-
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
24+
- name: 📥 Checkout repository
25+
uses: actions/checkout@v4
3126

32-
- name: Push image
33-
run: |
34-
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
35-
36-
# Ensure lowercase image ID
37-
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
38-
39-
# Use Git SHA as version tag
40-
VERSION=${{ github.sha }}
41-
42-
echo "IMAGE_ID=$IMAGE_ID"
43-
echo "VERSION=$VERSION"
44-
45-
# Tag and push the image with the unique SHA version
46-
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
47-
docker push $IMAGE_ID:$VERSION
27+
- name: 🔐 Log in to GitHub Container Registry (GHCR)
28+
uses: docker/login-action@v3
29+
with:
30+
registry: ghcr.io
31+
username: ${{ github.actor }}
32+
password: ${{ secrets.GITHUB_TOKEN }}
4833

49-
# Export the IMAGE_ID and VERSION as environment variables
50-
echo "IMAGE_ID=$IMAGE_ID" >> $GITHUB_ENV
51-
echo "VERSION=$VERSION" >> $GITHUB_ENV
34+
- name: 🐳 Build and Push Docker image
35+
uses: docker/build-push-action@v5
36+
with:
37+
context: .
38+
file: ./Dockerfile
39+
push: true
40+
tags: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
5241

53-
- name: Install kubectl
54-
if: github.ref == 'refs/heads/main' # Only run if the branch is main
55-
uses: azure/setup-kubectl@v3
42+
- name: 📥 Install kubectl
43+
uses: azure/setup-kubectl@v4
5644

57-
- name: Configure AWS credentials
58-
if: github.ref == 'refs/heads/main' # Only run if the branch is main
59-
uses: aws-actions/configure-aws-credentials@v3
45+
- name: 🔐 Configure AWS credentials
46+
uses: aws-actions/configure-aws-credentials@v4
6047
with:
6148
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
6249
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
6350
aws-region: ${{ env.AWS_REGION }}
6451

65-
- name: Update kubeconfig for EKS
66-
if: github.ref == 'refs/heads/main' # Only run if the branch is main
52+
- name: 🛠️ Update kubeconfig for EKS
6753
run: |
6854
aws eks update-kubeconfig --name ${{ env.CLUSTER_NAME }} --region ${{ env.AWS_REGION }}
6955
70-
- name: Update Kubernetes deployment
71-
if: github.ref == 'refs/heads/main' # Only run if the branch is main
56+
- name: 🚀 Update Kubernetes deployment
7257
run: |
73-
kubectl set image deployment/mediator-deployment mediator-container=${{ env.IMAGE_ID }}:${{ env.VERSION }} -n ${{ env.NAMESPACE }}
58+
kubectl set image deployment/mediator-deployment mediator-container=ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.sha }} -n ${{ env.NAMESPACE }}

0 commit comments

Comments
 (0)