-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
99 lines (93 loc) · 3.56 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
---
variables:
DOCKER_HUB_IMAGE: "${DOCKER_HUB_USERNAME}/${CI_PROJECT_NAME}"
VERSION: "2.9.4.4539"
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_BRANCH
stages:
- prepare
- test
- build
- docs
source-check:
artifacts:
reports:
dotenv: source.env
image:
name: curlimages/curl:8.11.1
entrypoint:
- /bin/sh
script:
- master=$(curl --head --output /dev/null --silent --write-out "%{http_code}" "https://github.com/Lidarr/Lidarr/releases/download/v${VERSION}/Lidarr.master.${VERSION}.linux-core-x64.tar.gz")
- test "${master}" == "404" && echo "SOURCE_CHANNEL=develop" >> source.env || echo "SOURCE_CHANNEL=master" >> source.env
- test "${master}" == "404" && echo "IMAGE_SUFFIX=-pre" >> source.env || echo "IMAGE_SUFFIX=" >> source.env
stage: prepare
tags:
- kubernetes
kaniko-check:
dependencies:
- source-check
image:
name: gcr.io/kaniko-project/executor:v1.23.2-debug
entrypoint: [""]
rules:
- if: $CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH
script:
- /kaniko/executor --build-arg="SOURCE_CHANNEL=${SOURCE_CHANNEL}" --build-arg="VERSION=${VERSION}" --context="${CI_PROJECT_DIR}" --dockerfile="${CI_PROJECT_DIR}/Dockerfile" --no-push
- echo "Would publish new image ${CI_REGISTRY_IMAGE}:${VERSION}.${CI_PIPELINE_IID}${IMAGE_SUFFIX}"
- echo "Would publish new image ${DOCKER_HUB_IMAGE}:${VERSION}.${CI_PIPELINE_IID}${IMAGE_SUFFIX}"
stage: test
tags:
- kubernetes
kaniko:
dependencies:
- source-check
image:
name: gcr.io/kaniko-project/executor:v1.23.2-debug
entrypoint: [""]
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
script:
- mkdir --parents /kaniko/.docker
- |
echo "{
\"auths\": {
\"${CI_REGISTRY}\": {
\"username\": \"${CI_REGISTRY_USER}\",
\"password\": \"${CI_REGISTRY_PASSWORD}\"
},
\"${DOCKER_HUB_URL}\": {
\"username\": \"${DOCKER_HUB_USERNAME}\",
\"password\": \"${DOCKER_HUB_PASSWORD}\"
}
}
}" > /kaniko/.docker/config.json
- /kaniko/executor --build-arg="SOURCE_CHANNEL=${SOURCE_CHANNEL}" --build-arg="VERSION=${VERSION}" --context="${CI_PROJECT_DIR}" --destination="${CI_REGISTRY_IMAGE}:${VERSION}.${CI_PIPELINE_IID}${IMAGE_SUFFIX}" --destination="${DOCKER_HUB_IMAGE}:${VERSION}.${CI_PIPELINE_IID}${IMAGE_SUFFIX}" --dockerfile="${CI_PROJECT_DIR}/Dockerfile"
- echo "Successfully published new image ${CI_REGISTRY_IMAGE}:${VERSION}.${CI_PIPELINE_IID}${IMAGE_SUFFIX}"
- echo "Successfully published new image ${DOCKER_HUB_IMAGE}:${VERSION}.${CI_PIPELINE_IID}${IMAGE_SUFFIX}"
stage: build
tags:
- kubernetes
docker-hub:
image: alpine/curl:8.11.1
rules:
- changes:
- README.md
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
script:
- apk add jq
- |
DOCKER_HUB_TOKEN="$(curl --request POST --header "content-type: application/json" "${DOCKER_HUB_API_URL}users/login" --data-raw "{\"username\": \"${DOCKER_HUB_USERNAME}\", \"password\": \"${DOCKER_HUB_PASSWORD}\"}" | jq -r .token)"
README_CONTENT="$(cat README.md)"
echo "${README_CONTENT}"
README_CONTENT="${README_CONTENT//$'\\'/\\\\}"
README_CONTENT="${README_CONTENT//$'\n'/\\n}"
echo "${README_CONTENT}"
curl --request PATCH --header "Authorization: Bearer ${DOCKER_HUB_TOKEN}" --header "content-type: application/json" "${DOCKER_HUB_API_URL}repositories/${DOCKER_HUB_USERNAME}/${CI_PROJECT_NAME}/" --data-raw "{\"full_description\": \"${README_CONTENT}\"}"
stage: docs
tags:
- kubernetes