This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
180 lines (165 loc) · 5.4 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
180
stages:
- lint
- test
- build
- publish
.base_golang:
image: golang:1.16
variables:
GOPATH: $CI_PROJECT_DIR/.go
GOLANGCI_LINT_VERSION: v1.42.0
before_script:
- apt-get update -y
- apt-get install -y protobuf-compiler
- mkdir -p .go
- export PATH=$PATH:$(go env GOPATH)/bin
cache:
key: go-dependencies-cache
paths:
- .go/pkg/mod/
.base_docker_build:
image: docker:20.10.7
services:
- docker:20.10.7-dind
variables:
# Use TLS https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#tls-enabled
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
before_script:
- apk add bash
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_TOKEN
.base_gh_ssh_agent:
before_script:
## _Inspired by https://docs.gitlab.com/ee/ci/ssh_keys/_
##
## Install ssh-agent if not already installed.
- "command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )"
## Run ssh-agent
- eval $(ssh-agent -s)
## Add the private key file to ssh-agent
- echo "$GH_REPO_SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
## Create the SSH directory and give it the right permissions
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
## Using the set $SSH_KNOWN_HOSTS to be able to verify remote servers public keys
- echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
shellcheck:
image: koalaman/shellcheck-alpine:stable
stage: lint
before_script:
- shellcheck --version
script:
- shellcheck $(find . -name '*.sh' | xargs)
shfmt:
image: mvdan/shfmt:v3.1.0-alpine
stage: lint
before_script:
- shfmt -version
script:
- shfmt -i 2 -ci -d .
apache_licenses_check:
stage: lint
image: registry.gitlab.com/ai-r/apache-license-checker:latest
script:
- apache-license-checker
lint:
extends: .base_golang
stage: lint
script:
- wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin "${GOLANGCI_LINT_VERSION}"
- golangci-lint --version
- make lint
test:
extends: .base_golang
stage: test
script:
- make test-with-report
artifacts:
when: always
reports:
junit: report.xml
build_docker:
extends: .base_docker_build
stage: build
variables:
COGMENT_MODEL_REGISTRY_IMAGE_BUILD_CACHE: $CI_REGISTRY_IMAGE/build:latest
COGMENT_MODEL_REGISTRY_IMAGE_BUILD: $CI_REGISTRY_IMAGE/build:commit-$CI_COMMIT_SHORT_SHA
COGMENT_MODEL_REGISTRY_IMAGE: $CI_REGISTRY_IMAGE:commit-$CI_COMMIT_SHORT_SHA
script:
- ./scripts/build_docker.sh
- docker push $COGMENT_MODEL_REGISTRY_IMAGE_BUILD
build_binaries:
extends: .base_golang
stage: build
script:
- make build
artifacts:
expire_in: 1 week
paths:
- build
push_docker_latest_to_gitlab:
extends: .base_docker_build
stage: publish
variables:
# Reuse the 'commit-$CI_COMMIT_SHORT_SHA' image built in `build_docker`
COGMENT_MODEL_REGISTRY_IMAGE_BUILD_CACHE: $CI_REGISTRY_IMAGE/build:commit-$CI_COMMIT_SHORT_SHA
COGMENT_MODEL_REGISTRY_IMAGE_BUILD: $CI_REGISTRY_IMAGE/build:latest
COGMENT_MODEL_REGISTRY_IMAGE: $CI_REGISTRY_IMAGE:latest
script:
- ./scripts/build_docker.sh
- docker push $COGMENT_MODEL_REGISTRY_IMAGE_BUILD
- docker push $COGMENT_MODEL_REGISTRY_IMAGE
only:
- main
- develop
push_docker_latest_to_dockerhub:
extends: .base_docker_build
stage: publish
variables:
# Reuse the 'commit-$CI_COMMIT_SHORT_SHA' image built in `build_docker`
COGMENT_MODEL_REGISTRY_IMAGE_BUILD_CACHE: $CI_REGISTRY_IMAGE/build:commit-$CI_COMMIT_SHORT_SHA
COGMENT_MODEL_REGISTRY_IMAGE_BUILD: $CI_REGISTRY_IMAGE/build:latest
COGMENT_MODEL_REGISTRY_IMAGE: cogment/model-registry:latest
script:
- ./scripts/build_docker.sh
- docker push $COGMENT_MODEL_REGISTRY_IMAGE
only:
- main
push_docker_tag_to_gitlab:
extends: .base_docker_build
stage: publish
variables:
# Reuse the 'commit-$CI_COMMIT_SHORT_SHA' image built in `build_docker`
COGMENT_MODEL_REGISTRY_IMAGE_BUILD_CACHE: $CI_REGISTRY_IMAGE/build:commit-$CI_COMMIT_SHORT_SHA
COGMENT_MODEL_REGISTRY_IMAGE_BUILD: $CI_REGISTRY_IMAGE/build:latest
COGMENT_MODEL_REGISTRY_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
script:
- ./scripts/build_docker.sh
- docker push $COGMENT_MODEL_REGISTRY_IMAGE
only:
- /^v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+(?:-[[:alnum:]]+)?$/
push_docker_tag_to_dockerhub:
extends: .base_docker_build
stage: publish
variables:
# Reuse the 'commit-$CI_COMMIT_SHORT_SHA' image built in `build_docker`
COGMENT_MODEL_REGISTRY_IMAGE_BUILD_CACHE: $CI_REGISTRY_IMAGE/build:commit-$CI_COMMIT_SHORT_SHA
COGMENT_MODEL_REGISTRY_IMAGE_BUILD: $CI_REGISTRY_IMAGE/build:latest
COGMENT_MODEL_REGISTRY_IMAGE: cogment/model-registry:$CI_COMMIT_TAG
script:
- ./scripts/build_docker.sh
- docker push $COGMENT_MODEL_REGISTRY_IMAGE
only:
- /^v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+(?:-[[:alnum:]]+)?$/
publish_branch_to_github:
extends: .base_gh_ssh_agent
stage: publish
script:
- git checkout ${CI_COMMIT_BRANCH} # Checkout the branch not the sha1
- git remote add downstream [email protected]:cogment/cogment-model-registry.git
- git fetch downstream ${CI_COMMIT_BRANCH}
- git push --tags downstream ${CI_COMMIT_BRANCH}:${CI_COMMIT_BRANCH}
only:
- main