-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
110 lines (102 loc) · 3.59 KB
/
.gitlab-ci.yml
File metadata and controls
110 lines (102 loc) · 3.59 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
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:
# This will suppress any download for dependencies and plugins or upload messages which would clutter the console log.
# `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work.
# MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
# As of Maven 3.3.0 instead of this you may define these options in `.mvn/maven.config` so the same config is used
# when running from the command line.
# `installAtEnd` and `deployAtEnd` are only effective with recent version of the corresponding plugins.
# MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
image: docker:latest
#设置maven的环境变量
variables:
# Error response from daemon: client version 1.40 is too new. Maximum supported API version is 1.39
DOCKER_API_VERSION: "1.39"
DOCKER_DRIVER: overlay2
# 这个变量为了解决dind新版本不兼容的问题详见 https://gitlab.com/gitlab-org/gitlab-runner/issues/4501#workaround
DOCKER_TLS_CERTDIR: "/certs"
MAVEN_OPTS: "-Dmaven.repo.local=/srv/.m2/repository -Dmaven.test.skip=true"
REPOSITORY: ccr.ccs.tencentyun.com/lzuldr
SERVER_NAME: base-server
TAG: ${REPOSITORY}/${SERVER_NAME}:$CI_PIPELINE_ID
NET: Ldr
cache: &global_cache
paths:
- ./*/target/*.jar
stages:
- package
- build
- deploy
maven-package:
image: maven:3.6.3-jdk-11
tags:
- maven-build
stage: package
script:
- mvn clean package
# artifacts:
# paths:
# - ./*/target/*.jar # 将maven构建成功的jar包作为构建产出导出,可在下一个stage的任务中使用
cache:
<<: *global_cache
policy: push
build-deploy:
#services:
# - name: docker:stable-dind
# command: ["--insecure-registry=172.17.0.1:5000"] # 将本地Docker Registry私服设置为insecure,避免registry默认需要https才能访问
tags:
- docker-build
stage: build
script:
# - docker login -u $USERNAME -p $PASSWORD ccr.ccs.tencentyun.com
- cd resource-base-server
# - docker pull $TAG
- docker build -t $TAG .
# - docker push $TAG
- end=2
- for i in $(seq $end);do
echo -n "stopping... " && docker stop ${SERVER_NAME}$i || true;
echo -n "removing... " && docker rm ${SERVER_NAME}$i || true;
echo -n "creating... " && docker run --detach
--network=$NET
--add-host jwk.lzu.edu.cn:202.201.1.220
--name ${SERVER_NAME}$i
--restart always
--volume /srv/www/api.ldr.cool/public:/opt/data/static/upload
$TAG;
if [ $i -ne $end ];then
sleep 15;
fi
done
# when: manual
cache:
<<: *global_cache
policy: pull
# 并发缓存会有问题等流程结束再手动启动
# 相关issue:https://gitlab.com/gitlab-org/gitlab-runner/issues/1151
deploy:manual:
tags:
- deploy
stage: deploy
script:
- for var in `ls */Dockerfile`;do
dir=$(dirname ${var});
echo -e "$ cd ${dir}" && cd ${dir};
docker build
-t ${REPOSITORY}/${dir}
-t ${REPOSITORY}/${dir}:$CI_PIPELINE_ID
.
&& cd ..;
done
# - docker stop admin-server || true
# - docker rm admin-server || true
# - >
# docker run --detach
# -p 8769:8769
# --network=$NET
# --name admin-server
# --restart always
# ccr.ccs.tencentyun.com/lzuldr/admin-server:latest
when: manual
cache:
<<: *global_cache
policy: pull