-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (66 loc) · 2.38 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: Build, Push and Deploy to Dev
on:
workflow_dispatch:
permissions:
contents: read
packages: write
env:
DOCKER_REGISTRY: ghcr.io
DOCKER_USERNAME: ${{ github.actor }}
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
GITHUB_USERNAME: interviewandhealth
IMAGE_NAME: user-service
IMAGE_TAG: v${{ github.run_number }}
CLUSTER_USERNAME: InterviewAndHealth
CLUSTER_REPOSITORY: Cluster
BRANCH: main
USERNAME: GopalSaraf
ACCESS_TOKEN: ${{ secrets.PERSONEL_TOKEN }}
FILE_PATH: services/user-service/overlays/development/kustomization.yaml
KEY: newTag
ENVIRONMENT: development
jobs:
build:
name: Build Image and Push to GitHub Container Registry
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_PASSWORD }}
registry: ${{ env.DOCKER_REGISTRY }}
- name: Build Docker Image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
${{ env.DOCKER_REGISTRY }}/${{ env.GITHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest
${{ env.DOCKER_REGISTRY }}/${{ env.GITHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
${{ env.DOCKER_REGISTRY }}/${{ env.GITHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
deploy:
name: Deploy to Development
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout Repository
shell: bash
run: |
REPOSITORY=https://${{ env.USERNAME }}:${{ env.ACCESS_TOKEN }}@github.com/${{ env.CLUSTER_USERNAME }}/${{ env.CLUSTER_REPOSITORY }}.git
git clone $REPOSITORY --depth 1 --branch ${{ env.BRANCH }} --single-branch .
- name: Update Kustomization File
shell: bash
run: |
sed -i "s/${{ env.KEY }}: .*/${{ env.KEY }}: ${{ env.IMAGE_TAG }}/g" ${{ env.FILE_PATH }}
- name: Commit Changes
shell: bash
run: |
git config user.name "${{ env.USERNAME }}"
git config user.email "${{ env.USERNAME }}@users.noreply.github.com"
git add $FILE_PATH
git commit -m "Update ${{ env.IMAGE_NAME }} image tag to ${{ env.IMAGE_TAG }} in ${{ env.ENVIRONMENT }}"
git pull --rebase
git push