-
Notifications
You must be signed in to change notification settings - Fork 3
134 lines (109 loc) · 4.71 KB
/
github.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: CI/CD Pipeline to deploy in Embassy Cloud EBI Openstack platform
on:
push:
branches:
- pride
workflow_dispatch:
env:
IMAGE_NAME: ${{ vars.IMAGE_NAME }}
USERNAME: ${{ secrets.GHCR_USER }}
IMAGE_TAG: ${{ github.sha }}
jobs:
docker_build:
environment: prod
env:
PORT: ${{ vars.PORT }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: create Dockerfile with environment variables
run: envsubst < .Dockerfile > Dockerfile
- name: Print Dockerfile
run: cat Dockerfile
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to GHCR
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USER }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
ghcr.io/${{ vars.API_GITHUB_REPOSITORY }}:latest
ghcr.io/${{ vars.API_GITHUB_REPOSITORY }}:${{ env.IMAGE_TAG }}
deploy:
needs: docker_build
environment: prod
runs-on: ubuntu-latest
env:
DOCKER_PULL_SECRET: pride-gitlab-docker-secret
DB_HOST : ${{ vars.DB_HOST }}
DB_DATABASE_NAME : ${{ vars.DB_DATABASE_NAME }}
DB_USER : ${{ vars.DB_USER }}
DB_PASSWORD : ${{ secrets.DB_PASSWORD }}
DB_PORT : ${{ vars.DB_PORT }}
API_KEY : ${{ secrets.API_KEY }}
API_VERSION : ${{ vars.API_VERSION }}
PORT: ${{ vars.PORT }}
node_port: ${{ vars.NODE_PORT }}
app_name: ${{ vars.APP_NAME }}
k8s_replicas: ${{ vars.K8S_REPLICAS }}
LOG_VOLUME_SIZE: ${{ vars.LOG_VOLUME_SIZE }}
log_volume_pvc: ${{ vars.LOG_VOLUME_PVC }}
K8S_NAMESPACE: ${{ vars.K8S_NAMESPACE }}
K8S_STORAGECLASS: ${{ vars.K8S_STORAGECLASS }}
DATABASE_INI: ${{ vars.DATABASE_INI }}
LOGGING_INI: ${{ vars.LOGGING_INI }}
IMAGE: ghcr.io/${{ vars.API_GITHUB_REPOSITORY }}:latest
XIVIEW_PRIDE_URL: ${{ vars.XIVIEW_PRIDE_URL }}
REDIS_HOST: ${{ vars.REDIS_HOST }}
REDIS_PORT: ${{ vars.REDIS_PORT }}
REDIS_PASSWORD: ${{ vars.REDIS_PASSWORD }}
PEPTIDE_PER_PROTEIN: ${{ vars.PEPTIDE_PER_PROTEIN }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install tools
run: sudo apt-get update && sudo apt-get install -y gettext tzdata coreutils
- name: Create kubeconfig
run: |
mkdir -p ~/.kube
echo ${{ secrets.KUBE_CONFIG }} > kubeconfig
base64 -d kubeconfig > ~/.kube/config
kubectl config get-contexts
- name: Create a Namespace if not exists
run: kubectl create namespace ${{ vars.K8S_NAMESPACE }} || true
- name: Delete the docker pull secrete if exist
run: kubectl -n ${{ vars.K8S_NAMESPACE }} delete secret ${{ env.DOCKER_PULL_SECRET }} || true
- name: Create a Docker registry secret with new image
run: |
kubectl -n ${{ vars.K8S_NAMESPACE }} create secret docker-registry ${{ env.DOCKER_PULL_SECRET }} \
--docker-server=ghcr.io \
--docker-username=${{ env.USERNAME }} \
--docker-password=${{ secrets.GHCR_TOKEN }}
- name: Substitute database variables by environment variables or variables
run: envsubst < default.database.ini > database.ini
- name: Print database.ini
run: cat database.ini
- name: Create ConfigMap for DATABASE_INI
run: kubectl -n ${{ vars.K8S_NAMESPACE }} create configmap ${{ vars.DATABASE_INI }} --from-file=database.ini || true
- name: Replace configmap if it already exists for DATABASE_INI
run: kubectl -n ${{ vars.K8S_NAMESPACE }} create configmap ${{ vars.DATABASE_INI }} --from-file=database.ini -o yaml --dry-run=client | kubectl replace -f -
- name: Create ConfigMap for Logging INI
run: kubectl -n ${{ vars.K8S_NAMESPACE }} create configmap ${{ vars.LOGGING_INI }} --from-file=logging.ini || true
- name: Replace configmap if it already exists for Logging INI
run: kubectl -n ${{ vars.K8S_NAMESPACE }} create configmap ${{ vars.LOGGING_INI }} --from-file=logging.ini -o yaml --dry-run=client | kubectl replace -f -
- name: Substitute kubernetes variables by environment variables or variables
run: envsubst <.kubernetes.yml > kubernetes.yml
- name: Print kubernetes.yml
run: cat kubernetes.yml
- name: Deploy to Kubernetes
run: kubectl -n ${{ vars.K8S_NAMESPACE }} apply -f kubernetes.yml
- name: restart Pod in case if not pulling latest image
run: kubectl rollout restart deploy ${{ vars.APP_NAME }} -n ${{ vars.K8S_NAMESPACE }}