-
Notifications
You must be signed in to change notification settings - Fork 19
120 lines (100 loc) · 4.37 KB
/
container_builds.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Container ECR build + deploy
on:
push:
branches:
- main
- demo
permissions:
id-token: write
contents: read
jobs:
setup-env:
if: github.repository == 'UnlockedLabs/UnlockEdv2' || github.repository == 'PThorpe92/UnlockEdv2'
runs-on: ubuntu-latest
outputs:
frontend_changes: ${{ steps.frontend_changes.outputs.changed }}
backend_changes: ${{ steps.backend_changes.outputs.changed }}
middleware_changes: ${{ steps.middleware_changes.outputs.changed }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 3
- id: frontend_changes
run: |
echo "changed=$(git diff --name-only HEAD~1 | grep '^frontend/' | wc -l)" >> $GITHUB_OUTPUT
- id: backend_changes
run: |
echo "changed=$(git diff --name-only HEAD~1 | grep '^backend/' | wc -l)" >> $GITHUB_OUTPUT
- id: middleware_changes
run: |
echo "changed=$(git diff --name-only HEAD~1 | grep '^provider-middleware/' | wc -l)" >> $GITHUB_OUTPUT
- name: Debug outputs
run: |
echo "Frontend changes: ${{ steps.frontend_changes.outputs.changed }}"
echo "Backend changes: ${{ steps.backend_changes.outputs.changed }}"
echo "Middleware changes: ${{ steps.middleware_changes.outputs.changed }}"
build-and-push:
if: github.repository == 'UnlockedLabs/UnlockEdv2' || github.repository == 'PThorpe92/UnlockEdv2'
needs: setup-env
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_IAM_ROLE }}
aws-region: us-west-2
mask-aws-account-id: true
- name: Log in to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push frontend image
if: ${{ needs.setup-env.outputs.frontend_changes != '0' }} && github.ref == 'refs/heads/main'
run: |
docker buildx build --platform linux/amd64 -t=${{ steps.login-ecr.outputs.registry }}/frontend:latest --push frontend/.
- name: Build and push backend image
if: ${{ needs.setup-env.outputs.backend_changes != '0' }} && github.ref == 'refs/heads/main'
run: |
docker buildx build --platform linux/amd64 -t=${{ steps.login-ecr.outputs.registry }}/unlockedv2:latest --push -f backend/Dockerfile .
- name: Build and push middleware image
if: ${{ needs.setup-env.outputs.middleware_changes != '0' }} && github.ref == 'refs/heads/main'
run: |
docker buildx build --platform linux/amd64 -t=${{ steps.login-ecr.outputs.registry }}/provider_middleware:latest --push -f provider-middleware/Dockerfile .
- name: Set up kubectl
uses: azure/setup-kubectl@v1
with:
version: v1.21.0
- name: Set up Kubeconfig Staging
if: github.ref == 'refs/heads/main'
run: |
mkdir -p $HOME/.kube && touch $HOME/.kube/config
echo "${{ secrets.KUBECTL_CONFIG }}" | base64 -d > $HOME/.kube/config
- name: Set up Kubeconfig Demo
if: github.ref == 'refs/heads/demo'
run: |
mkdir -p $HOME/.kube && touch $HOME/.kube/config
echo "${{ secrets.KUBECTL_CONFIG_DEMO }}" | base64 -d > $HOME/.kube/config
- name: Create k8s ECR secret
run: |
kubectl delete secret ecr-secret --ignore-not-found
kubectl create secret docker-registry ecr-secret \
--docker-server=${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.us-west-2.amazonaws.com \
--docker-username=AWS \
--docker-password=$(aws ecr get-login-password --region us-west-2) \
--docker-email=none
- name: restart frontend
if: ${{ needs.setup-env.outputs.frontend_changes != '0' }}
run: |
kubectl rollout restart deployment frontend
- name: restart server
if: ${{ needs.setup-env.outputs.backend_changes != '0' }}
run: |
kubectl rollout restart deployment server
- name: restart provider_middleware
if: ${{ needs.setup-env.outputs.middleware_changes != '0' }}
run: |
kubectl rollout restart deployment provider-service