forked from OpenCSGs/csghub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
76 lines (68 loc) · 2.1 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
image: docker:24.0.6
include:
- template: Security/Secret-Detection.gitlab-ci.yml
variables:
CI_USER: $GITLAB_USER
CI_TOKEN: $GITLAB_USER_TOKEN_HIVEER
GIT_DEPTH: 100
stages:
- test
- build
- deploy
# 判断是不是正确的project,正确的branch,以及是不是forked repo过来的MR
.if-csghub-staging-original-repo: &if-csghub-staging-original-repo
if: '$CI_COMMIT_REF_NAME == "csghub-staging" && $CI_PROJECT_ID == "32" && $CI_MERGE_REQUEST_SOURCE_PROJECT_ID == null'
# for production docker image build
# e.g., v1.0.0
.if-production-tag-build: &if-production-tag-build
if: '$CI_PROJECT_ID == "32" && $CI_COMMIT_TAG =~ /^v(\d+(?:\.\d+.\d+)*)$/'
csghub-build:
stage: build
services:
- docker:24.0.6-dind
tags:
- linux-medium-amd64
rules:
- <<: *if-csghub-staging-original-repo
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
script:
- docker login $CI_REGISTRY -u $CI_USER -p $CI_TOKEN
- docker build -t $IMAGE_TAG .
- docker push $IMAGE_TAG
csghub-deploy:
stage: deploy
tags:
- linux-medium-amd64
rules:
- <<: *if-csghub-staging-original-repo
before_script:
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$OPEN_PORTAL_STAGING_PEM" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $OPEN_PORTAL_STAGING_HOST >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- |
ssh root@$OPEN_PORTAL_STAGING_HOST "/bin/bash -s" << EOT
cd /root/csghub_open_portal/
docker compose -f docker_compose_csghub.yml pull
docker compose -f docker_compose_csghub.yml up -d --force-recreate web
docker image prune -f
EOT
production-tag-build:
stage: build
services:
- docker:24.0.6-dind
tags:
- linux-medium-amd64
rules:
- <<: *if-production-tag-build
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
script:
- docker login $CI_REGISTRY -u $CI_USER -p $CI_TOKEN
- docker build -t $IMAGE_TAG .
- docker push $IMAGE_TAG