-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci.yml
140 lines (132 loc) · 5.7 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
variables:
APP_VERSION: "2.2.0"
API_VERSION: "2.2.0"
APPS_PROJECT_BRANCH_NAME: "${CI_COMMIT_REF_NAME}"
BUILD_NUMBER: "${CI_COMMIT_REF_NAME}-${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA}"
IMAGE_TAG: "${APP_VERSION}-${CI_COMMIT_REF_NAME}"
IMAGE_NAME: "${CI_REGISTRY_IMAGE}:${IMAGE_TAG}"
IMAGE_LATEST_TAG: "${CI_COMMIT_REF_NAME}-latest"
LATEST_IMAGE_NAME: "${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}-latest"
SIF_FILE_NAME: "${CI_PROJECT_NAME}_${APP_VERSION}_${CI_COMMIT_REF_NAME}.sif"
SIF_LATEST_FILE_NAME: "${CI_PROJECT_NAME}_${CI_COMMIT_REF_NAME}_latest.sif"
SIF_FILE_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}_sif/$APP_VERSION/$SIF_FILE_NAME"
SIF_LATEST_FILE_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}_sif/$CI_COMMIT_REF_NAME/$SIF_LATEST_FILE_NAME"
workflow:
rules:
- if: $CI_COMMIT_BRANCH == "test" || $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "development"
stages:
- build
- deploy
configuration_parameters:
stage: build
script:
- echo "CI_BUILDS_DIR $CI_BUILDS_DIR"
- echo "CI_REGISTRY_USER $CI_REGISTRY_USER"
- echo "CI_REGISTRY $CI_REGISTRY"
- echo "BRANCH $CI_COMMIT_REF_NAME"
- echo "CI_PIPELINE_ID $CI_PIPELINE_ID"
- echo "CI_COMMIT_SHORT_SHA $CI_COMMIT_SHORT_SHA"
- echo "CI_REGISTRY_IMAGE CI_REGISTRY_IMAGE"
- echo "APP_VERSION $APP_VERSION"
- echo "API_VERSION $API_VERSION"
- echo "BUILD_NUMBER $BUILD_NUMBER"
- echo "IMAGE_TAG $IMAGE_TAG"
- echo "IMAGE NAME $IMAGE_NAME"
- echo "IMAGE NAME (with latest tag) $LATEST_IMAGE_NAME"
- echo "APPS_ROOT_PATH $APPS_ROOT_PATH"
- echo "DEPLOYMENTS_FOLDER $DEPLOYMENTS_FOLDER"
- echo "APPS_PROJECT_URL $APPS_PROJECT_URL"
- echo "APPS_PROJECT_BRANCH_NAME $APPS_PROJECT_BRANCH_NAME"
- echo "MTBLS_NFS_USER_GROUP1_ID $MTBLS_NFS_USER_GROUP1_ID"
- echo "MTBLS_NFS_USER_GROUP2_ID $MTBLS_NFS_USER_GROUP2_ID"
- echo "MTBLS_NFS_USER_ID $MTBLS_NFS_USER_ID"
build_docker:
stage: build
script:
- docker image prune -f
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" "$CI_REGISTRY" --password-stdin
- echo "Build number $BUILD_NUMBER, commit name ${CI_COMMIT_REF_NAME}"
- echo "${BUILD_NUMBER}" > build_number
- echo "$APP_VERSION" | xargs > app_version
- echo "$API_VERSION" | xargs > api_version
- git status
- echo "docker build --build-arg GROUP1_ID=$MTBLS_NFS_USER_GROUP1_ID --build-arg GROUP2_ID=$MTBLS_NFS_USER_GROUP2_ID --build-arg USER_ID=$MTBLS_NFS_USER_ID -t $IMAGE_NAME ."
- docker build --build-arg GROUP1_ID=$MTBLS_NFS_USER_GROUP1_ID --build-arg GROUP2_ID=$MTBLS_NFS_USER_GROUP2_ID --build-arg USER_ID=$MTBLS_NFS_USER_ID -t $IMAGE_NAME .
- echo "docker build --build-arg GROUP1_ID=$MTBLS_NFS_USER_GROUP1_ID --build-arg GROUP2_ID=$MTBLS_NFS_USER_GROUP2_ID --build-arg USER_ID=$MTBLS_NFS_USER_ID -t $LATEST_IMAGE_NAME ."
- docker build --build-arg GROUP1_ID=$MTBLS_NFS_USER_GROUP1_ID --build-arg GROUP2_ID=$MTBLS_NFS_USER_GROUP2_ID --build-arg USER_ID=$MTBLS_NFS_USER_ID -t $LATEST_IMAGE_NAME .
- docker push $IMAGE_NAME
- docker push $LATEST_IMAGE_NAME
build_sif:
stage: build
script:
- singularity build $SIF_FILE_NAME docker-daemon://$IMAGE_NAME
- echo "$SIF_FILE_URL"
- |-
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file $SIF_FILE_NAME "$SIF_FILE_URL"
- echo "$SIF_LATEST_FILE_URL"
- |-
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file $SIF_FILE_NAME "$SIF_LATEST_FILE_URL"
deploy_metablsws_py:
variables:
CHART_NAME: metablsws-py
rules:
- if: $CI_COMMIT_BRANCH == "test" || $CI_COMMIT_BRANCH == "development"
when: on_success
- if: $CI_COMMIT_BRANCH == "main"
when: manual
extends: .kube_deploy_script
deploy_common_worker:
variables:
CHART_NAME: metablsws-py-common-worker
rules:
- if: $CI_COMMIT_BRANCH == "test" || $CI_COMMIT_BRANCH == "development"
when: on_success
- if: $CI_COMMIT_BRANCH == "main"
when: manual
extends: .kube_deploy_script
deploy_datamover_proxy:
variables:
CHART_NAME: metablsws-py-datamover-proxy
rules:
- if: $CI_COMMIT_BRANCH == "test"
when: on_success
- if: $CI_COMMIT_BRANCH == "main"
when: manual
extends: .kube_deploy_script
deploy_datamover_worker:
variables:
CHART_NAME: metablsws-py-datamover-worker
rules:
- if: $CI_COMMIT_BRANCH == "development"
when: on_success
extends: .kube_deploy_script
.kube_deploy_script:
stage: deploy
script:
- BUILD_PATH=$(realpath tmp)
- echo "BUILD_PATH $BUILD_PATH"
- mkdir -p $BUILD_PATH
- cd $BUILD_PATH
- APPS_ROOT_PATH="$BUILD_PATH/apps"
- rm -rf $APPS_ROOT_PATH
- echo git clone https://$CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD@${APPS_PROJECT_URL}
- git clone https://$CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD@${APPS_PROJECT_URL}
- cd $APPS_ROOT_PATH
- git switch $APPS_PROJECT_BRANCH_NAME
- git status
- git pull
- DEPLOYMENTS_FOLDER_SCRIPTS="$APPS_ROOT_PATH/$DEPLOYMENTS_FOLDER/scripts"
- echo "DEPLOYMENTS_FOLDER_SCRIPTS $DEPLOYMENTS_FOLDER_SCRIPTS"
- cd $DEPLOYMENTS_FOLDER_SCRIPTS
- cat initial_setup.sh
- bash initial_setup.sh
- DEPLOYMENTS_CHART_PATH="$APPS_ROOT_PATH/$DEPLOYMENTS_FOLDER/charts/$CHART_NAME"
- echo "DEPLOYMENTS_CHART_PATH $DEPLOYMENTS_CHART_PATH"
- cd $DEPLOYMENTS_CHART_PATH
- cat template.sh
- echo template.sh "image.repository=$CI_REGISTRY_IMAGE,image.tag=$IMAGE_TAG"
- bash template.sh "image.repository=$CI_REGISTRY_IMAGE,image.tag=$IMAGE_TAG"
- cat install.sh
- echo install.sh "image.repository=$CI_REGISTRY_IMAGE,image.tag=$IMAGE_TAG,sifImageFileUrl=$SIF_FILE_URL"
- bash install.sh "image.repository=$CI_REGISTRY_IMAGE,image.tag=$IMAGE_TAG,sifImageFileUrl=$SIF_FILE_URL"
- rm -rf $BUILD_PATH