-
Notifications
You must be signed in to change notification settings - Fork 0
98 lines (83 loc) · 2.95 KB
/
workflow.yml
File metadata and controls
98 lines (83 loc) · 2.95 KB
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
89
90
91
92
93
94
95
96
97
98
name: build_and_deploy
on:
push:
branches:
- "main"
- "staging"
env:
TAG: $(echo $GITHUB_SHA | head -c7)
IMAGE: 661254676507.dkr.ecr.ap-southeast-1.amazonaws.com/$(echo $GITHUB_REPOSITORY | cut -d "/" -f2)
RELEASE: $(echo $GITHUB_REPOSITORY | cut -d "/" -f2)
BRANCH: $(echo $GITHUB_REF | cut -d'/' -f 3)"
jobs:
build_and_push:
runs-on: ubuntu-latest
name: Docker Build & Push
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-southeast-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
run: |
docker build -t ${{ env.IMAGE }}:${{ env.TAG }} .
docker push ${{ env.IMAGE }}:${{ env.TAG }}
- name: slack notification
uses: 8398a7/action-slack@v3
with:
job_name: Docker Build & Push
status: ${{ job.status }}
fields: all
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()
deployment:
runs-on: ubuntu-latest
needs: build_and_push
name: Deploy to Kubernetes
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: save and decode kubeconfig
run: |
mkdir ~/.kube
echo ${{ secrets.KUBE_CONFIG }} | base64 --decode > ~/.kube/config
- name: SOPS Binary Installer
uses: mdgreenwald/mozilla-sops-action@v1.1.0
- name: Setup helmfile
uses: mamezou-tech/setup-helmfile@v0.8.0
with:
additional-helm-plugins: https://github.com/jkroepke/helm-secrets.git --version 2.0.2
helmfile-version: "v0.138.4"
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v3
with:
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
- name: Deploy to Staging
if: github.ref == 'refs/heads/staging'
run: |
export RELEASE=${{ env.RELEASE }}
helmfile -e staging sync --set=image.repository=${{ env.IMAGE }} --set=image.tag=${{ env.TAG }}
- name: Deploy to Production
if: github.ref == 'refs/heads/main'
run: |
export RELEASE=${{ env.RELEASE }}
helmfile -e production sync --set=image.repository=${{ env.IMAGE }} --set=image.tag=${{ env.TAG }}
- name: slack notification
uses: 8398a7/action-slack@v3
with:
job_name: Deploy to Kubernetes
status: ${{ job.status }}
fields: all
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()