-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
166 lines (155 loc) · 5.49 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
include:
- file: /Scan/trivy.yml
project: jitesoft/gitlab-ci-lib
- file: /OCI/push-readme.yml
project: jitesoft/gitlab-ci-lib
workflow:
rules:
- if: "$CI_COMMIT_BRANCH == 'master'"
when: always
- when: never
stages:
- readme
- pre
- download
- containerize
- scan
variables:
LTS_VERSION: "22"
update-readme:
stage: readme
extends: .readme-check.v2
variables:
GIT_DEPTH: "3"
REGISTRIES: "docker.io/jitesoft/node-yarn"
PUSHRM_FILE: "$CI_PROJECT_DIR/README.md"
tags: [ protected ]
check:
image: registry.gitlab.com/jitesoft/dockerfiles/misc:latest
variables:
GIT_STRATEGY: none
stage: pre
parallel:
matrix:
- { NODE_MAJOR: "18", RELEASE_NAME: "hydrogen" }
- { NODE_MAJOR: "20", RELEASE_NAME: "iron" }
- { NODE_MAJOR: "22", RELEASE_NAME: "jod" }
- { NODE_MAJOR: "23", RELEASE_NAME: "latest" }
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: always
- if: '$CI_PIPELINE_SOURCE == "web"'
when: always
- when: never
script:
- touch versions.txt
- YARN_VERSION=$(wget -qO- https://api.github.com/repos/yarnpkg/yarn/releases | jq -r ".[0].tag_name")
- |
if [ ! -z "${FORCE_BUILD+x}" ] || [ "$(cat versions.txt)" != "${YARN_VERSION}" ]; then
echo "New version. Building new image."
curl -F token=${CI_JOB_TOKEN} -F ref=master -F "variables[NODE_MAJOR]=${NODE_MAJOR}" -F "variables[YARN_VERSION]=${YARN_VERSION}" -F "variables[RELEASE_NAME]=${RELEASE_NAME}" -F "variables[BUILD]=true" https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/trigger/pipeline
else
echo "Old image. Starting scan."
curl -F token=${CI_JOB_TOKEN} -F ref=master -F "variables[NODE_MAJOR]=${NODE_MAJOR}" -F "variables[SCAN]=true" https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/trigger/pipeline
fi
cache:
policy: pull
key: yarn-major-${NODE_MAJOR}
paths:
- versions.txt
# Trigger should always build, due to the fact that node image only triggers if there is a new node version!
trigger:
image: registry.gitlab.com/jitesoft/dockerfiles/misc:latest
variables:
GIT_STRATEGY: none
stage: pre
rules:
- if: '$CI_PIPELINE_SOURCE == "trigger"'
when: always
- when: never
script:
- echo "Triggered from node. Running full build."
- YARN_VERSION=$(wget -qO- https://api.github.com/repos/yarnpkg/yarn/releases | jq -r ".[0].tag_name")
- curl -F token=${CI_JOB_TOKEN} -F ref=master -F "variables[NODE_MAJOR]=${NODE_MAJOR}" -F "variables[YARN_VERSION]=${YARN_VERSION}" -F "variables[RELEASE_NAME]=${RELEASE_NAME}" -F "variables[BUILD]=true" https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/trigger/pipeline
download:
image: registry.gitlab.com/jitesoft/dockerfiles/misc:latest
stage: download
rules:
- if: "$BUILD"
when: always
- when: never
variables:
GIT_STRATEGY: none
script:
- wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --import
- wget -q https://yarnpkg.com/latest.tar.gz
- wget -q https://yarnpkg.com/latest.tar.gz.asc
- gpg --verify latest.tar.gz.asc
- mkdir binaries
- mv latest.tar.gz binaries/latest.tar.gz
artifacts:
expire_in: 1 day
when: on_success
paths:
- binaries/
containerize:
stage: containerize
parallel:
matrix:
- { IMAGE_TYPE: "slim", TAG_SUFFIX: "-slim", NODE_IMAGE: "node-base" }
- { IMAGE_TYPE: "full", NODE_IMAGE: "node-base/full" }
image: registry.gitlab.com/jitesoft/dockerfiles/misc:latest
rules:
- if: "$BUILD"
when: on_success
- when: never
needs:
- job: download
artifacts: true
script:
- TAGS=$(helper "${CI_REGISTRY_IMAGE},jitesoft/node-yarn,ghcr.io/jitesoft/node-yarn" "${NODE_MAJOR}${TAG_SUFFIX},${RELEASE_NAME}${TAG_SUFFIX}")
- |
if [ "$NODE_MAJOR" == "$LTS_VERSION" ]; then
EXTRA_TAGS=$(helper "${CI_REGISTRY_IMAGE},jitesoft/node-yarn,ghcr.io/jitesoft/node-yarn" "lts${TAG_SUFFIX}")
TAGS="${TAGS}${EXTRA_TAGS}"
fi
- docker buildx build --sbom=true --provenance=true --platform linux/arm64,linux/amd64 --push ${TAGS} --progress plain --build-arg BUILD_TIME="$(date -Iseconds)" --build-arg "YARN_VERSION=${YARN_VERSION}" --build-arg "NODE_IMAGE=${NODE_IMAGE}:${NODE_MAJOR}" .
tags:
- protected
- buildx
create:cache:
stage: .post
image: registry.gitlab.com/jitesoft/dockerfiles/alpine:latest
rules:
- if: "$BUILD"
when: on_success
script:
- echo "${YARN_VERSION}" > versions.txt
cache:
policy: push
key: yarn-major-${NODE_MAJOR}
paths:
- versions.txt
notify:trivy:
stage: .post
image: registry.gitlab.com/jitesoft/dockerfiles/misc:latest
rules:
- if: "$BUILD"
when: on_success
script:
- echo "Notifying scanner."
- curl -F token=${CI_JOB_TOKEN} -F ref=master -F "variables[NODE_MAJOR]=${NODE_MAJOR}" -F "variables[SCAN]=true" https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/trigger/pipeline
scan:
parallel:
matrix:
- { IMAGE_TYPE: "slim", ANNOYING_NILL_DATA: "aaa" }
- { IMAGE_TYPE: "full", ANNOYING_NILL_DATA: "aaa" }
stage: scan
rules:
- if: "$SCAN"
when: always
- when: never
extends: .container_scanning
before_script:
- if [ "${IMAGE_TYPE}" == "slim" ]; then TAG_SUFFIX="-slim"; fi
- export SCANNING_IMAGE_NAME="${CI_REGISTRY_IMAGE}:${FULL_VERSION:-$NODE_MAJOR}${TAG_SUFFIX}"