-
Notifications
You must be signed in to change notification settings - Fork 13
58 lines (46 loc) · 2.69 KB
/
ci-cd.yaml
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
name: Build and Deploy Next JS App on DigitalOcean K8s Cluster
on:
push:
branches:
- dev
- staging
- production
jobs:
build-job:
name: Build YAM
runs-on: ubuntu-latest
steps:
- name: Checkout latest git repo
uses: actions/checkout@main
- name: Validate Access Token
run: echo ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Build container image
run: docker build
--build-arg BUILD_ENV=${GITHUB_REF_NAME}
--build-arg COMMUNITY_API_KEY_ARG=${{ secrets.COMMUNITY_API_KEY }}
--build-arg NEXT_PUBLIC_WALLET_CONNECT_KEY_ARG=${{ secrets.NEXT_PUBLIC_WALLET_CONNECT_KEY }}
-t registry.digitalocean.com/yam-realtoken-cr/${GITHUB_REF##*/}:$(echo $GITHUB_SHA | head -c7) .
- name: Log in to DigitalOcean Container Registry with short-lived credentials
run: doctl registry login --expiry-seconds 1200
- name: Push image to DigitalOcean Container Registry
run: docker push registry.digitalocean.com/yam-realtoken-cr/${GITHUB_REF##*/}:$(echo $GITHUB_SHA | head -c7)
- name: Update Docker Image in Deployment file
run: TAG=$(echo $GITHUB_SHA | head -c7) && ENV_PREFIX=$(echo ${GITHUB_REF##*/}) && sed -i 's|<IMAGE>|registry.digitalocean.com/yam-realtoken-cr/'${ENV_PREFIX}':'${TAG}'|' $GITHUB_WORKSPACE/k8s-yaml/deployment.yaml && cat $GITHUB_WORKSPACE/k8s-yaml/deployment.yaml
- name: Update Environment Prefix in Deployment|Service|Ingress files
run: ENV_PREFIX=$(echo ${GITHUB_REF##*/}) && sed -i 's|<ENV_PREFIX>|'${ENV_PREFIX}'|' $GITHUB_WORKSPACE/k8s-yaml/*.yaml && cat $GITHUB_WORKSPACE/k8s-yaml/*.yaml
- name: Update Environment Prefix in Cert-issuer files
run: ENV_PREFIX=$(echo ${GITHUB_REF##*/}) && sed -i 's|<ENV_PREFIX>|'${ENV_PREFIX}'|' $GITHUB_WORKSPACE/k8s-yaml/cert-manager/*.yaml && cat $GITHUB_WORKSPACE/k8s-yaml/cert-manager/*.yaml
- name: Update Ingress Host if Production
if: github.ref == 'refs/heads/production'
run: |
sed -i 's|production-yam.realtoken.network|'yam.realtoken.network'|' $GITHUB_WORKSPACE/k8s-yaml/ingress.yaml && cat $GITHUB_WORKSPACE/k8s-yaml/ingress.yaml
- name: Save DigitalOcean kubeconfig with short-lived credentials
run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 yam-realtoken-k8s
- name: Deploy to DigitalOcean Kubernetes
run: kubectl apply -f $GITHUB_WORKSPACE/k8s-yaml --recursive
- name: Verify deployment
run: kubectl rollout status deployment/${GITHUB_REF##*/}-yam-realtoken