-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
158 lines (152 loc) · 6.14 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
before_script:
- rm -rf /root/.m2/settings.xml
- echo -e "<?xml version=\""1.0\"" encoding=\""UTF-8\""?><settings xmlns=\""http://maven.apache.org/SETTINGS/1.0.0\"" xmlns:xsi=\""http://www.w3.org/2001/XMLSchema-instance\"" xsi:schemaLocation=\""http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd\""><mirrors><mirror><id>mirror</id><name>mirror</name><url>https://maven.aliyun.com/nexus/content/groups/public</url><mirrorOf>central,jcenter,!rdc-releases,!rdc-snapshots</mirrorOf></mirror> </mirrors> <servers>
<server>
<id>rdc-releases</id>
<username>617d503fbc6f250a94c5d6ec</username>
<password>VDzlsL5jYZot</password>
</server>
<server>
<id>rdc-snapshots</id>
<username>617d503fbc6f250a94c5d6ec</username>
<password>VDzlsL5jYZot</password>
</server>
</servers>
<profiles>
<profile>
<id>rdc</id>
<properties>
<altReleaseDeploymentRepository>
rdc-releases::default::https://packages.aliyun.com/maven/repository/2150952-release-4Nd0Uf/
</altReleaseDeploymentRepository>
<altSnapshotDeploymentRepository>
rdc-snapshots::default::https://packages.aliyun.com/maven/repository/2150952-snapshot-LmgYUo/
</altSnapshotDeploymentRepository>
</properties>
<repositories>
<repository>
<id>central</id>
<url>https://maven.aliyun.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<url>https://maven.aliyun.com/nexus/content/groups/public</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>rdc-releases</id>
<url>https://packages.aliyun.com/maven/repository/2150952-release-4Nd0Uf/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>rdc-snapshots</id>
<url>https://packages.aliyun.com/maven/repository/2150952-snapshot-LmgYUo/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://maven.aliyun.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>snapshots</id>
<url>https://maven.aliyun.com/nexus/content/groups/public</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>rdc-releases</id>
<url>https://packages.aliyun.com/maven/repository/2150952-release-4Nd0Uf/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>rdc-snapshots</id>
<url>https://packages.aliyun.com/maven/repository/2150952-snapshot-LmgYUo/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>rdc</activeProfile>
</activeProfiles>
</settings>" > /root/.m2/settings.xml
# 定义一些变量, 下面各阶段会使用
variables:
jar_name: cloud-disk-0.0.1-SNAPSHOT.jar
java_path: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.el7_9.x86_64/bin
TAG: cloud-disk:v1.0 # 镜像名称
CONTAINER_NAME: cloud-disk-service
PORT: 8976
DOCKER_DRIVER: overlay2
# 定义执行的各个阶段及顺序
stages:
- build
- deploy
# 使用 maven 镜像打包项目
maven-build:
stage: build
image: maven:3.5.0-jdk-8
script:
- mvn package -B -Dmaven.test.skip=true
cache:
key: m2-repo
paths:
- .m2/repository
artifacts:
paths:
- ./target/$jar_name
build-main: # 定义的 Jobs 之一,用于构建 Docker 镜像。负责执行 deploy 这一流程。具体执行 build 和 run。
stage: deploy
tags:
- main deploy
script:
- docker stop $CONTAINER_NAME
- docker rmi -f $TAG
- docker build -t $TAG . # 构件镜像
- docker rm -f $CONTAINER_NAME || true # 删除容器
- docker run -d --name $CONTAINER_NAME -p $PORT:$PORT $TAG # 运行容器
only: # 指定哪些branch的push commit会触发执行该job,本例子指定只有master才会执行deploy这个job
- main