-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (71 loc) · 2.71 KB
/
build_and_deploy.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
name: Deploy to Kubernetes
on:
workflow_dispatch:
push:
branches:
- development
- master
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
env:
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
KUBE_NAMESPACE: staging
IMAGE_NAME: rg.fr-par.scw.cloud/redcraft/redcraft-website
GENERIC_IMAGE_TAG: staging
steps:
- name: Cancel previous runs
uses: styfle/cancel-workflow-action@0.4.1
with:
access_token: ${{ github.token }}
- name: Checkout
uses: actions/checkout@v2
- name: Production settings
if: github.ref == 'refs/heads/master'
run: |
echo "KUBE_NAMESPACE=production" >> $GITHUB_ENV
echo "GENERIC_IMAGE_TAG=latest" >> $GITHUB_ENV
- name: Login to Container Registry
run: docker login rg.fr-par.scw.cloud/redcraft -u nologin -p "$AWS_SECRET_ACCESS_KEY"
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
with:
install: true
- name: Docker cache layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-single-buildx-${{ github.sha }}
restore-keys: ${{ runner.os }}-single-buildx
- name: Generate CSS files
run: |
npm install
npm run production
- name: Build & push Docker image
env:
RELEASE_IMAGE: ${{ env.IMAGE_NAME }}:${{ github.sha }}
LATEST_RELEASE_IMAGE: ${{ env.IMAGE_NAME }}:${{ env.GENERIC_IMAGE_TAG }}
run: |
docker buildx create --use
docker buildx build \
--cache-from=type=local,src=/tmp/.buildx-cache \
--cache-to=type=local,dest=/tmp/.buildx-cache-new \
--tag ${{ env.RELEASE_IMAGE }} \
--tag ${{ env.LATEST_RELEASE_IMAGE }} \
--push \
.
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Update deployment
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
run: |
mkdir -p ~/.kube
echo "$KUBE_CONFIG" | base64 -d > ~/.kube/config
kubectl set image deployment/website website-http=${{ env.IMAGE_NAME }}:${{ github.sha }} --namespace=${{ env.KUBE_NAMESPACE }}
kubectl set image deployment/website website-queue=${{ env.IMAGE_NAME }}:${{ github.sha }} --namespace=${{ env.KUBE_NAMESPACE }}
kubectl set image cronjob/website-cronjob website-cron=${{ env.IMAGE_NAME }}:${{ github.sha }} --namespace=${{ env.KUBE_NAMESPACE }}