-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.gitlab-ci.yml
150 lines (127 loc) · 3.97 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
---
# do not use "latest" here, if you want this to work in the future
image:
name: docker:19
stages:
- init_checks
- build
- push
- compare
- trigger_downstream
# - sync
- notify
variables:
DOCKERHUB_REGISTRY: "docker.io"
DOCKERHUB_IMAGE: "hestio/awsh"
services:
- docker:dind
include:
- project: 'hest-io/hestio-product/hestio-worx/autoworx/ci/templates'
file:
- 'Jobs/Docker/docker-compare-image-sizes.gitlab-ci.yml'
- 'Jobs/Notifications/release-slack-notify.gitlab-ci.yml'
###############################################################################
# Task Templates
###############################################################################
.dockerfile_lint:
allow_failure: true
image: "hadolint/hadolint:latest-debian"
stage: init_checks
script:
- mkdir -p reports
- hadolint --no-fail -f gitlab_codeclimate .docker/Dockerfile.py3_alpine > reports/hadolint-$(md5sum .docker/Dockerfile.py3_alpine | cut -d" " -f1).json
artifacts:
name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
expire_in: 1 day
when: always
reports:
codequality:
- "reports/*"
paths:
- "reports/*"
.build_image:
variables:
DOCKER_FILE: ".docker/Dockerfile.py3_alpine"
IMAGE_TAG: "${CI_COMMIT_REF_NAME}"
stage: build
script:
- echo -n $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
- echo "Building using ${CI_PROJECT_DIR}/${DOCKER_FILE}"
- >
docker build
--tag ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA}
--build-arg "AWSH_BUILD_VERSION=${CI_COMMIT_REF_NAME}"
--file "${CI_PROJECT_DIR}/${DOCKER_FILE}" .
- docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA}
# Here, the goal is to tag the "master" branch as "latest"
.push_image:
variables:
# We are just playing with Docker here.
# We do not need GitLab to clone the source code.
GIT_STRATEGY: none
IMAGE_TAG: "${CI_COMMIT_REF_NAME}"
stage: push
script:
- echo -n $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
# Because we have no guarantee that this job will be picked up by the same runner
# that built the image in the previous step, we pull it again locally
- docker pull ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA}
- docker tag ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA} ${CI_REGISTRY_IMAGE}:${IMAGE_TAG}
- docker push ${CI_REGISTRY_IMAGE}:${IMAGE_TAG}
# We also want to push the ${IMAGE_TAG} release into DockerHub
- echo -n ${DOCKERHUB_REGISTRY_PASS} | docker login -u ${DOCKERHUB_REGISTRY_LOGIN} --password-stdin ${DOCKERHUB_REGISTRY}
- docker tag ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA} ${DOCKERHUB_IMAGE}:${IMAGE_TAG}
- docker push ${DOCKERHUB_IMAGE}:${IMAGE_TAG}
###############################################################################
# Tasks
###############################################################################
dockerfile_lint:
extends:
- .dockerfile_lint
build-image-alpine:
extends:
- .build_image
variables:
DOCKER_FILE: ".docker/Dockerfile.py3_alpine"
IMAGE_TAG: "${CI_COMMIT_REF_NAME}"
# Here, the goal is to tag the "master" branch as "latest"
push-latest:
extends:
- .push_image
variables:
IMAGE_TAG: latest
only:
# Only "master" should be tagged "latest"
- master
push-label:
extends:
- .push_image
only:
# We want this job to be run on tags only.
- tags
- develop
compare_image_sizes:
stage: compare
trigger_blox_pipeline:
stage: trigger_downstream
before_script:
- apk add --update curl
script:
- >
curl
-X POST
--fail
-F token=${BLOX_PIPELINE_TRIGGER_TOKEN}
-F ref=master
https://gitlab.com/api/v4/projects/24214318/trigger/pipeline
only:
- master
# sync_gitlab_to_github:
# stage: sync
# variables:
# GITHUB_REPO: "hest-io/awsh"
# GITLAB_REPO: "hest-io/hestio-product/hestio-worx/awsh"
# only:
# - master
release_slack_notify:
stage: notify