forked from bestarch-ae/cacherpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
179 lines (167 loc) · 5.31 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
variables:
APPNAME_SHORT: cacherpc
REGISTRY_PROJECT: zubrdevops/cacherpc
ARTIFACTS_PATH: dev-cacherpc-artifacts
RPM_DEB_REPO_PATH: dev-cacherpc-apt
BIN_NAME: cache-rpc
BIN_PATH: /usr/sbin
BUILD_IMAGE: $REGISTRY_PROJECT:build-$CI_COMMIT_REF_SLUG
CARGO_HOME: /cache/cacherpc/.cargo
CARGO_TARGET_DIR: "/cache/cacherpc/$CI_COMMIT_REF_SLUG/$CI_JOB_NAME"
CARGO_TARGET_DIR_MASTER: "/cache/cacherpc/master/$CI_JOB_NAME"
stages:
- pre_build
- lint
- rustfmt
- build_version
- build_artifact
- build
- deploy_dev
- ready_sbx
- notify
include:
- project: 'shared/tasks'
ref: master
file: 'vars/default-zubr.yml'
- project: 'shared/tasks'
ref: master
file: 'vars/upver-tag-naming.yml'
- project: 'shared/tasks'
ref: master
file: 'notify/up-version.yml'
- project: 'shared/tasks'
ref: master
file: 'notify/send-failed.yml'
- project: 'shared/tasks'
ref: 'master'
file: 'deb/build_rust_app_v2.yml' #build deb
- project: 'shared/tasks'
ref: 'master'
file: 'deploy/ready-sbx.yml'
- project: 'shared/tasks'
ref: 'master'
file: 'upload/s3_binary.yml'
- project: 'shared/tasks'
ref: 'master'
file: 'upload/github_binary.yml'
create_build_image:
stage: pre_build
image: docker
tags: [docker_19_nocache]
before_script:
- docker login -u $REGISTRY_LOGIN -p $REGISTRY_PASS
script:
- docker pull $REGISTRY_PROJECT:build-master || true
- docker build --cache-from $REGISTRY_PROJECT:build-master --pull -t $BUILD_IMAGE -f Dockerfile.build .
- docker push $BUILD_IMAGE
- echo "Pushed $BUILD_IMAGE"
clear_cache:
stage: pre_build
image: docker
when: manual
tags: [docker_19_cache]
script:
- rm -rf /cache/cacherpc/$CI_COMMIT_REF_SLUG
lint:
stage: lint
image: $BUILD_IMAGE
tags: [docker_19_cache]
before_script:
- "[ ! -d $CARGO_TARGET_DIR ] && if [ -d $CARGO_TARGET_DIR_MASTER ]; then mkdir -p $CARGO_TARGET_DIR && cp -rp $CARGO_TARGET_DIR_MASTER $CARGO_TARGET_DIR; else mkdir -p $CARGO_TARGET_DIR; fi"
- mkdir -p $CARGO_HOME
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
script:
- cargo clippy --version
- cargo clippy --all-targets --all-features -- -D warnings -D rust_2018_idioms
- "cargo metadata --format-version 1 | jq '.packages | map(.dependencies) | flatten | map(select(.source != null)) | map(select(.source | test(\"zubr.dev\"))) | unique_by(.source) | group_by(.name) | map(select(length > 1)) | .[] | {(.[0].name): [.[] | .source]}' | tee /tmp/1"
- if [ -s /tmp/1 ]; then echo Version mismatch; exit 2; fi
rustfmt:
stage: rustfmt
image: $BUILD_IMAGE
tags: [docker_19_cache]
before_script:
- "[ ! -d $CARGO_TARGET_DIR ] && if [ -d $CARGO_TARGET_DIR_MASTER ]; then mkdir -p $CARGO_TARGET_DIR && cp -rp $CARGO_TARGET_DIR_MASTER $CARGO_TARGET_DIR; else mkdir -p $CARGO_TARGET_DIR; fi"
- mkdir -p $CARGO_HOME
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
script:
- cargo fmt -- --check
build_artifact:
stage: build_artifact
image: $BUILD_IMAGE
tags: [docker_19_cache]
variables:
UPLOAD_ARTIFACT: "rpm-source.tar.gz"
before_script:
- "[ ! -d $CARGO_TARGET_DIR ] && if [ -d $CARGO_TARGET_DIR_MASTER ]; then mkdir -p $CARGO_TARGET_DIR && cp -rp $CARGO_TARGET_DIR_MASTER $CARGO_TARGET_DIR; else mkdir -p $CARGO_TARGET_DIR; fi"
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
script:
- cargo build --release
- echo $CARGO_TARGET_DIR
- mkdir -p artifact${BIN_PATH}
- ls -la $CARGO_TARGET_DIR
- cp $CARGO_TARGET_DIR/release/$BIN_NAME artifact${BIN_PATH}/
- ls -la artifact${BIN_PATH}
- du artifact
- tar -czf $UPLOAD_ARTIFACT artifact
artifacts:
paths:
- ./${UPLOAD_ARTIFACT}
expire_in: 1 day
build_docker:
stage: build
tags: [docker_19_cache]
before_script:
- docker login -u $REGISTRY_LOGIN -p $REGISTRY_PASS
- apk update && apk add git make curl
script:
- PIPELINE_ID_VERSION=$(curl --user "$REPO_LOGIN:$REPO_PASS" https://$REPO_SRV/repository/$ARTIFACTS_PATH/$APPNAME_SHORT/pipelin-id/$CI_PIPELINE_ID/$VERSION_FILE)
- tar -xzf rpm-source.tar.gz
- >
docker build
--build-arg BIN_NAME=${BIN_NAME}
--tag $REGISTRY_PROJECT:$PIPELINE_ID_VERSION
--tag $REGISTRY_PROJECT:latest
-f Dockerfile.dist
.
- docker push $REGISTRY_PROJECT:$PIPELINE_ID_VERSION
- docker push $REGISTRY_PROJECT:latest
# only:
# - tags
# - develop
# - master
# - web
Deploy DEB to Dev:
stage: deploy_dev
tags:
- deploy_rpm_dev
script:
- find . -mindepth 1 -maxdepth 1 -exec rm -rf {} \;
- git clone https://git.zubr.dev/shared/ci-scripts.git
- chmod 0700 ci-scripts/deploy_deb.sh
- ci-scripts/deploy_deb.sh DEV
only:
- develop
- master
- tags
- web
deploy_dev_not_master:
stage: deploy_dev
tags:
- deploy_rpm_dev
script:
- find . -mindepth 1 -maxdepth 1 -exec rm -rf {} \;
- git clone https://git.zubr.dev/shared/ci-scripts.git
- chmod 0700 ci-scripts/deploy_deb.sh
- ci-scripts/deploy_deb.sh DEV
when: manual
except:
- master