-
Notifications
You must be signed in to change notification settings - Fork 19
/
.gitlab-ci.yml
165 lines (153 loc) · 4.89 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
variables:
CONTAINER_TEST_IMAGE: "${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG}"
CONTAINER_RELEASE_IMAGE: "${CI_REGISTRY_IMAGE}:0.5.0"
BUILDER_IMAGE: ghcr.io/nvidia/cloud-native-docs:0.2.0
PUBLISHER_IMAGE: "${CI_REGISTRY_PUBLISHER}/publisher:2.0.0"
stages:
- .pre
- build_image
- build_docs
- publish_docs
.build_image:
image: docker:23.0.6
stage: .pre
services:
- docker:23.0.6-dind
variables:
GIT_STRATEGY: clone
script:
- apk add git
- git fetch origin "${CI_DEFAULT_BRANCH}"
- docker login -u "${CI_REGISTRY_USER}" -p "${CI_REGISTRY_PASSWORD}" "${CI_REGISTRY}"
- if ! docker manifest inspect "${BUILDER_IMAGE}" 2>&1 > /dev/null ; then export NEEDS_IMAGE=true ; fi
- FILES=$(git diff --name-only "${CI_COMMIT_SHA}" "origin/${CI_DEFAULT_BRANCH}" | tr '\n' ' ')
- if echo "${FILES}" | grep -q "deps/\|Dockerfile\|repo.toml" ; then export NEEDS_IMAGE=true ; fi
- >
if [[ "${NEEDS_IMAGE}" ]]; then
docker build -t "${CONTAINER_TEST_IMAGE}" . -f docker/Dockerfile
docker push "${CONTAINER_TEST_IMAGE}"
echo "BUILDER_IMAGE=${CONTAINER_TEST_IMAGE}" >> build.env
else
echo "BUILDER_IMAGE=${BUILDER_IMAGE}" >> build.env
fi
- >
if [ "${NEEDS_IMAGE}" ] && [ "${CI_COMMIT_BRANCH}" == "${CI_DEFAULT_BRANCH}" ] && [ "${CI_PIPELINE_SOURCE}" == "push" ]; then
docker tag "${CONTAINER_TEST_IMAGE}" "${CONTAINER_RELEASE_IMAGE}"
docker push "${CONTAINER_RELEASE_IMAGE}"
fi
artifacts:
reports:
dotenv: build.env
.build_image_rules:
rules:
- if: ($CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH) || $CI_PIPELINE_SOURCE == "merge_request_event"
build_image_ext:
extends: .build_image
rules:
- if: $INTERNAL != null
when: never
- !reference [.build_image_rules, rules]
build_image_int:
extends: .build_image
tags:
- os/linux
- type/docker
rules:
- if: $INTERNAL == null
when: never
- !reference [.build_image_rules, rules]
.build:
stage: build_docs
image: "${BUILDER_IMAGE}"
script:
- ./repo docs
- echo "BUILDER_IMAGE=${BUILDER_IMAGE}" >> build.env
artifacts:
name: ${CI_PROJECT_NAME}-${CI_COMMIT_SHORT_SHA}
paths:
- _build
expire_in: 4w
reports:
dotenv: build.env
.build_rules:
rules:
- if: ($CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH) || $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_REF_NAME =~ /-v[0-9]/
build_ext:
extends: .build
variables:
APIURL: "${CI_API_V4_URL}/projects/${CI_MERGE_REQUEST_PROJECT_ID}/merge_requests/${CI_MERGE_REQUEST_IID}/discussions"
after_script:
- PROJPART=$(echo "${CI_PROJECT_PATH#$CI_PROJECT_ROOT_NAMESPACE}")
- BASEURL=$(echo "https://${CI_PROJECT_ROOT_NAMESPACE}.${CI_PAGES_DOMAIN}/-${PROJPART}")
- REVURL=$(echo "${BASEURL}/-/jobs/${CI_JOB_ID}/artifacts/_build/docs/review/latest/index.html")
- MSG=$(echo "{\"body\":\"<p><b>Review HTML</b></p><p><a href=\"${REVURL}\">${REVURL}</a></p>\"}")
- echo "${REVURL}"
- echo "${MSG}"
- 'curl -X POST -H "Authorization: Bearer ${MR_COMMENT}" "${APIURL}" -H "Content-Type: application/json" --data-raw "${MSG}"'
rules:
- if: $INTERNAL != null
when: never
- !reference [.build_rules, rules]
build_int:
extends: .build
tags:
- os/linux
- type/docker
rules:
- if: $INTERNAL == null
when: never
- !reference [.build_rules, rules]
pages:
image: "${CONTAINER_RELEASE_IMAGE}"
stage: publish_docs
script:
- rm -rf public
- cp -r _build/docs/ public
artifacts:
paths:
- public
expire_in: 1 week
dependencies:
- build_ext
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push" && $INTERNAL != 'true'
publish_docs:
image:
name: "${PUBLISHER_IMAGE}"
entrypoint: [ "" ]
stage: publish_docs
tags:
- os/linux
- type/docker
variables:
HTML_PATH: "_build/docs"
FORCE_LATEST: "true"
script:
- echo "Pushing docs live to https://docs.nvidia.com/datacenter/cloud-native"
- |+
if [[ "${CI_COMMIT_REF_NAME}" =~ (.+)-v([0-9]+\.[0-9]+\.[0-9]+) ]]; then
export DOCSET="${BASH_REMATCH[1]}"
export VERSION="${BASH_REMATCH[2]}"
fi
- |+
if [ -z "${DOCSET}" ] || [ -z "${VERSION}" ]; then
echo "Failed to determine the docset or version."
exit 1
fi
- |+
if [[ "${CI_COMMIT_MESSAGE}" =~ $'\n/not-latest\n' ]]; then
export FORCE_LATEST=false
fi
- echo "Publishing docs for ${DOCSET} and version ${VERSION}"
- pushd "${HTML_PATH}/${DOCSET}/latest"
- deploy_s3.sh --archive "${DOCSET}" "${VERSION}"
- |+
if [ "true" == "${FORCE_LATEST}" ]; then
deploy_s3.sh --latest "${DOCSET}"
fi
- deploy_s3.sh --flush "${DOCSET}"
dependencies:
- build_int
rules:
- if: $CI_COMMIT_TAG =~ /-v[0-9]/ && ($CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "web" ) && $INTERNAL