-
Notifications
You must be signed in to change notification settings - Fork 6
/
.gitlab-ci.yml
134 lines (120 loc) · 4.35 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
stages:
- test
- build
- publish
default:
interruptible: true
retry:
max: 2
when:
- runner_system_failure
- unknown_failure
- api_failure
variables:
CI_REGISTRY: "docker.io/paritytech"
GIT_STRATEGY: fetch
CI_IMAGE: node:16.10-alpine
DOCKERHUB_REPO: "paritytech"
IMAGE_NAME: docker.io/$DOCKERHUB_REPO/polkadot-basic-notification
DOCKERFILE: injected.Containerfile
.common-refs: &common-refs
rules:
- if: $CI_PIPELINE_SOURCE == "web"
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_COMMIT_REF_NAME == "master"
- if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/ # PRs
.test-refs: &test-refs
rules:
- if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/ # PRs
.publish-refs: &publish-refs
rules:
- if: $CI_COMMIT_REF_NAME == "master" # on commits to main branch
- if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/ # on tags (i.e. v1.0, v2.1rc1)
.kubernetes-env: &kubernetes-env
image: $CI_IMAGE
tags:
- kubernetes-parity-build
.collect-artifacts-short: &collect-artifacts-short
artifacts:
name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
when: on_success
expire_in: 1 days
paths:
- ./artifacts/
# test that docker image can build
.build-only-docker-image: &build-only-docker-image
image: quay.io/buildah/stable
script:
- buildah bud
--format=docker
--build-arg VCS_REF="${CI_COMMIT_SHA}"
--build-arg BUILD_DATE="$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
--build-arg PROJECT_NAME="${CI_PROJECT_NAME}"
--tag "$IMAGE_NAME:latest"
--file "$DOCKERFILE" .
check-linting:
stage: test
<<: *common-refs
<<: *kubernetes-env
script:
- npm ci --ignore-scripts
- npm run lint
# TODO: currently fails, need fix
allow_failure: True
build-npm:
stage: build
<<: *collect-artifacts-short
<<: *common-refs
<<: *kubernetes-env
script:
- npm ci --ignore-scripts
- npm run build
- mkdir -p artifacts
- cp -r build/ artifacts/
- ls artifacts/
build-docker:
stage: build
needs:
- job: build-npm
artifacts: true
<<: *test-refs
<<: *kubernetes-env
<<: *build-only-docker-image
#### stage: publish
build-push-image:
stage: publish
needs:
- job: build-npm
artifacts: true
<<: *kubernetes-env
<<: *publish-refs
image: quay.io/buildah/stable
variables:
DOCKER_USER: $Docker_Hub_User_Parity
DOCKER_PASS: $Docker_Hub_Pass_Parity
script:
# version is either "master-<short_sha>" or tag
- if [[ $CI_COMMIT_REF_NAME == "master" ]];
then
export VERSION=$CI_COMMIT_REF_NAME-${CI_COMMIT_SHORT_SHA};
else
export VERSION=$CI_COMMIT_REF_NAME;
fi
- test "$DOCKER_USER" -a "$DOCKER_PASS" ||
( echo "no docker credentials provided"; exit 1 )
- buildah bud
--format=docker
--build-arg VCS_REF="${CI_COMMIT_SHA}"
--build-arg BUILD_DATE="$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
--build-arg IMAGE_NAME="${IMAGE_NAME}"
--tag "$IMAGE_NAME:latest"
--tag "$IMAGE_NAME:$VERSION"
--file $DOCKERFILE .
# The job will success only on the protected branch
- echo "$DOCKER_PASS" |
buildah login --username "$DOCKER_USER" --password-stdin docker.io
- buildah info
- buildah push --format=v2s2 "$IMAGE_NAME:latest"
- buildah push --format=v2s2 "$IMAGE_NAME:$VERSION"
after_script:
- buildah logout --all