-
Notifications
You must be signed in to change notification settings - Fork 10
96 lines (79 loc) · 3.31 KB
/
ci-master.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
# This is a basic workflow to help you get started with Actions
name: CI to Docker Hub
# Controls when the action will run. Triggers the workflow on push or pull request events
on:
push:
branches: [master, dev]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Set outputs
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: Make Cache Directory
run: mkdir bootstrap/cache
- name: Set up Node
uses: actions/setup-node@v1
- name: Build Docker Image
run: docker-compose build --no-cache
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push to Docker Hub (Master)
if: contains(github.ref, 'master')
run: |
docker tag vatusa/api vatusa/api:${{ steps.vars.outputs.sha_short }}
docker push vatusa/api:${{ steps.vars.outputs.sha_short }}
- name: Push to Docker Hub (Dev)
if: contains(github.ref, 'dev')
run: |
docker tag vatusa/api vatusa/api:dev
docker push vatusa/api:dev
- name: Install kubectl
uses: azure/setup-kubectl@v1
with:
version: 'v1.21.2'
- name: Create kubeconfig
run: |
mkdir ~/.kube
cat << EOF > ~/.kube/config
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: ${{ secrets.KUBECONFIG_CLUSTER_CERT_AUTH_DATA }}
server: ${{ secrets.KUBECONFIG_CLUSTER_SERVER }}
name: ${{ secrets.KUBECONFIG_CLUSTER_NAME }}
contexts:
- context:
cluster: ${{ secrets.KUBECONFIG_CLUSTER_NAME }}
user: ${{ secrets.KUBECONFIG_CLUSTER_NAME }}-admin
name: ${{ secrets.KUBECONFIG_CLUSTER_NAME }}
current-context: ${{ secrets.KUBECONFIG_CLUSTER_NAME }}
kind: Config
preferences: {}
users:
- name: ${{ secrets.KUBECONFIG_CLUSTER_NAME }}-admin
user:
token: ${{ secrets.KUBECONFIG_CLUSTER_TOKEN }}
EOF
- name: Deploy to Kubernetes Cluster - Update Deployment
if: contains(github.ref, 'master')
run: |
kubectl set image deployment/api *=vatusa/api:${{ steps.vars.outputs.sha_short }} -n web
- name: Deploy to Kubernetes Cluster - Update Cron Job
if: contains(github.ref, 'master')
run: |
kubectl set image cronjob/api-cron *=vatusa/api:${{ steps.vars.outputs.sha_short }} -n web
- name: Deploy to Kubernetes Cluster - Update Queue Worker
if: contains(github.ref, 'master')
run: |
kubectl set image deployment/api-queue *=vatusa/api:${{ steps.vars.outputs.sha_short }} -n web