-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (85 loc) · 2.87 KB
/
main.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Docker Build/Push and Deploy
on :
push :
branches :
- master
pull_request :
branches :
- master
env:
ECR_REPOSITORY: juliusoh
CLIENT_TAG: ecommerce-web-${{ github.sha }}
API_TAG: ecommerce-api-${{ github.sha }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build and tag and push Docker image Backend
env:
ECR_REGISTIRY: ${{ steps.login-ecr.outputs.registry }}
run: |
docker build -t $ECR_REGISTIRY/$ECR_REPOSITORY:$API_TAG .
docker push $ECR_REGISTIRY/$ECR_REPOSITORY:$API_TAG
- name: Build and tag and push Docker image Backend
env:
ECR_REGISTIRY: ${{ steps.login-ecr.outputs.registry }}
run: |
cd frontend
docker build -t $ECR_REGISTIRY/$ECR_REPOSITORY:$CLIENT_TAG .
docker push $ECR_REGISTIRY/$ECR_REPOSITORY:$CLIENT_TAG
- name: Checkout
uses: actions/checkout@v3
with:
path: 'dest'
ref: 'main'
repository: 'juliusoh/portfolio-helm-charts'
token: ${{ secrets.PERSONAL_TOKEN }}
fetch-depth: 0
persist-credentials: true
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Update Image Tag
working-directory: dest
run: |
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys CC86BB64
sudo add-apt-repository ppa:rmescandon/yq
sudo apt update
sudo apt install yq -y
cd ecommerce
yq eval ".image.tag = \"$API_TAG\"" -i values.yaml
yq eval ".image.clientTag = \"$CLIENT_TAG\"" -i values.yaml
- name: Update Git Changes
id: newFiles
shell: bash
working-directory: dest
run: |
git add -A
git status --porcelain | wc -l
if [ $(git status --porcelain | wc -l) -gt 0 ]; then
echo "::set-output name=changed::true"
else
echo "::set-output name=changed::false"
fi
- name: Commit and Push
shell: bash
if: steps.newFiles.outputs.changed == 'true'
working-directory: dest
run: |
git config --global user.email "[email protected]"
git config --global user.name "juliusoh"
git commit -m "Update ${{ github.repository }} image tag from reference ${{ github.sha }}"
git push