-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
110 lines (104 loc) · 4.13 KB
/
.gitlab-ci.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
variables:
GIT_SUBMODULE_STRATEGY: recursive
IMAGE_NAME: ${CI_REGISTRY_IMAGE}/oais
IS_DEVELOP: "false"
stages:
- update
- build
- deploy
push-update:
stage: update
image: ubuntu:20.04
# Only execute this job when the pipeline is triggered by the upstream repositories
rules:
- if: '$CI_PIPELINE_SOURCE == "pipeline"'
script:
- apt-get update
- apt-get install -y git
- cd /tmp
- git clone --recurse-submodules "https://gitlab-ci:${GIT_ACCESS_TOKEN}@gitlab.cern.ch/digitalmemory/openshift-deploy.git"
- cd openshift-deploy
- git config user.name "GitLab CI"
- git config user.email "ci@gitlab.cern.ch"
- git submodule update --remote
- git add .
- git commit -am "Updating submodules" || true
- git push
# Build and publish docker image using Kaniko.
# From https://gitlab.cern.ch/gitlabci-examples/build_docker_image/
build-docker-dev:
stage: build
rules:
- if: '$CI_PIPELINE_SOURCE == "push"'
image:
name: gitlab-registry.cern.ch/ci-tools/docker-image-builder
entrypoint: [""]
script:
- echo "Commit branch is $CI_COMMIT_BRANCH, Context file is $CI_PROJECT_DIR/$CI_COMMIT_BRANCH and dockerfile is in $CI_PROJECT_DIR/Dockerfile"
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --cache=false --context $CI_PROJECT_DIR/develop --dockerfile $CI_PROJECT_DIR/Dockerfile --destination "${IMAGE_NAME}_dev":latest --destination "${IMAGE_NAME}_dev":$CI_COMMIT_SHA
- echo "Image pushed to ${IMAGE_NAME}:latest and ${IMAGE_NAME}:$CI_COMMIT_SHA"
build-docker-master:
stage: build
rules:
- if: '$CI_PIPELINE_SOURCE == "push"'
image:
name: gitlab-registry.cern.ch/ci-tools/docker-image-builder
entrypoint: [""]
script:
- echo "Commit branch is $CI_COMMIT_BRANCH, Context file is $CI_PROJECT_DIR/$CI_COMMIT_BRANCH and dockerfile is in $CI_PROJECT_DIR/Dockerfile"
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --cache=false --context $CI_PROJECT_DIR/master --dockerfile $CI_PROJECT_DIR/Dockerfile --destination "${IMAGE_NAME}_master":latest --destination "${IMAGE_NAME}_master":$CI_COMMIT_SHA
- echo "Image pushed to ${IMAGE_NAME}:latest and ${IMAGE_NAME}:$CI_COMMIT_SHA"
deploy-dev:
stage: deploy
rules:
- if: '$CI_PIPELINE_SOURCE == "push"'
image: ubuntu:20.04
environment:
name: luteus
url: https://dm-luteus.web.cern.ch/
script:
- apt-get update
- apt-get install -y curl
# Download OpenShift client
- curl https://mirror.openshift.com/pub/openshift-v4/clients/ocp/4.8.4/openshift-client-linux.tar.gz -o oc.tar.gz
- tar -xf oc.tar.gz
- mv ./oc /usr/bin/oc
# Download Helm
- curl https://get.helm.sh/helm-v3.6.3-linux-amd64.tar.gz -o helm.tar.gz
- tar -xf helm.tar.gz
- mv ./linux-amd64/helm /usr/bin/helm
# Login
- oc login --server="$DEV_OPENSHIFT_SERVER" --token="$DEV_OPENSHIFT_TOKEN"
# Upgrade
- oc project dm-luteus
- >-
helm upgrade -f ./develop/values.yaml "$DEV_HELM_NAME" ./oais-openshift --install
--set oais.image="${IMAGE_NAME}_dev":${CI_COMMIT_SHA}
deploy-master:
stage: deploy
rules:
- if: '$CI_PIPELINE_SOURCE == "push"'
image: ubuntu:20.04
environment:
name: galanos
url: https://dm-galanos.web.cern.ch/
script:
- apt-get update
- apt-get install -y curl
# Download OpenShift client
- curl https://mirror.openshift.com/pub/openshift-v4/clients/ocp/4.8.4/openshift-client-linux.tar.gz -o oc.tar.gz
- tar -xf oc.tar.gz
- mv ./oc /usr/bin/oc
# Download Helm
- curl https://get.helm.sh/helm-v3.6.3-linux-amd64.tar.gz -o helm.tar.gz
- tar -xf helm.tar.gz
- mv ./linux-amd64/helm /usr/bin/helm
# Login
- oc login --server="$DEV_OPENSHIFT_SERVER" --token="$DEV_OPENSHIFT_TOKEN"
# Upgrade
- oc project dm-galanos
- >-
helm upgrade -f ./master/values.yaml "$DEV_HELM_NAME" ./oais-openshift --install
--set oais.image="${IMAGE_NAME}_master":${CI_COMMIT_SHA}