forked from PRIDE-Archive/crosslinking-api
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
66 lines (62 loc) · 2.77 KB
/
Copy path.gitlab-ci.yml
File metadata and controls
66 lines (62 loc) · 2.77 KB
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
variables:
DOCKER_PULL_SECRET: pride-gitlab-docker-secret
IMAGE: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA
docker_build:
variables:
DOCKER_TLS_CERTDIR: ""
image: docker:24.0.5
stage: build
services:
- docker:27.1.2-dind
script:
# Install tools
- apk add --update bash gettext tzdata coreutils wget curl
# Substitute variables in Dockerfile template and create Dockerfile
- envsubst < .Dockerfile > Dockerfile
- cat Dockerfile
- echo $CI_REGISTRY_IMAGE $CI_COMMIT_REF_SLUG $CI_COMMIT_SHA
- docker --debug info
# Build and push Docker image
- docker build -t $IMAGE .
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker push $IMAGE
# Deploy to cluster 44 (hh). Set CI/CD variables for environment prod-k8s-hh-44 (KUBE_CONFIG, k8s_namespace, etc.).
kube_deploy_prod_hh_44:
environment: prod-k8s-hh-44
extends: .kube_deploy_script
.kube_deploy_script:
stage: deploy
image: dtzar/helm-kubectl
script:
# Install tools
- apk add --update bash gettext tzdata coreutils
# Create kubeconfig
- mkdir -p ~/.kube
- echo $KUBE_CONFIG > kubeconfig
- base64 -d kubeconfig > ~/.kube/config
- kubectl config get-contexts
# Create a Namespace if not exists
- kubectl create namespace $K8S_NAMESPACE || true
# Delete the docker pull secrete if exist
- kubectl -n $K8S_NAMESPACE delete secret $DOCKER_PULL_SECRET || true
- echo $CI_REGISTRY $CI_DEPLOY_USER
# Create a Docker registry secret with new image
- kubectl -n $K8S_NAMESPACE create secret docker-registry $DOCKER_PULL_SECRET --docker-server=$CI_REGISTRY --docker-username=$CI_DEPLOY_USER --docker-password=$CI_DEPLOY_PASSWORD
# Substitute database variables by environment variables or variables
- envsubst < default.database.ini > database.ini
- cat database.ini
# Create ConfigMap for DATABASE_INI
- kubectl -n $K8S_NAMESPACE create configmap $DATABASE_INI --from-file=database.ini || true
# Replace configmap if it already exists for DATABASE_INI
- kubectl -n $K8S_NAMESPACE create configmap $DATABASE_INI --from-file=database.ini -o yaml --dry-run=client | kubectl replace -f -
# Create ConfigMap for Logging INI
- kubectl -n $K8S_NAMESPACE create configmap $LOGGING_INI --from-file=logging.ini || true
# Replace configmap if it already exists for Logging INI
- kubectl -n $K8S_NAMESPACE create configmap $LOGGING_INI --from-file=logging.ini -o yaml --dry-run=client | kubectl replace -f -
- envsubst < .kubernetes.yml > kubernetes.yml
- cat kubernetes.yml
# Deploy to Kubernetes
- kubectl -n $K8S_NAMESPACE apply -f kubernetes.yml
# restart Pod in case if not pulling latest image
- kubectl rollout restart deploy $app_name -n $K8S_NAMESPACE
when: manual