-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
87 lines (74 loc) · 2.53 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
stages:
- prebuild
- build
- deploy
version:
image: mcr.microsoft.com/dotnet/sdk:6.0
stage: prebuild
script:
- dotnet tool install -g minver-cli
- set_version
artifacts:
paths:
- version.sh
build:
image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
script:
- use_version
- docker_build
stage: build
dependencies:
- version
nuget:
stage: deploy
image: mcr.microsoft.com/dotnet/sdk:6.0
script:
- dotnet pack -c Release -o $PWD/nuget
- dotnet nuget add source "$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/packages/nuget/index.json" --name gitlab --username gitlab-ci-token --password $CI_JOB_TOKEN --store-password-in-clear-text
- dotnet nuget push "$PWD/nuget/*.nupkg" --source gitlab
only:
- master
- tags
.auto_devops: &auto_devops |
[[ "$TRACE" ]] && set -x
export CI_APPLICATION_REPOSITORY=$CI_REGISTRY_IMAGE
export CI_APPLICATION_TAG=$CI_COMMIT_SHA
export CI_CONTAINER_NAME=ci_job_build_${CI_JOB_ID}
set_version() {
export PATH="$PATH:/root/.dotnet/tools"
cd ${1-.}
echo "export APPLICATION_VERSION=\"$(minver)\"" > version.sh
}
use_version() {
[ -f version.sh ] && source ./version.sh
tag=${APPLICATION_VERSION/+/-}
export CI_APPLICATION_TAG=${tag:-$CI_APPLICATION_TAG}
}
docker_build() {
if [[ -n "$CI_REGISTRY" && -n "$CI_REGISTRY_USER" ]]; then
echo "Logging to GitLab Container Registry with CI credentials..."
echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin "$CI_REGISTRY"
fi
if [ -n "$APPLICATION_VERSION" ]; then
export CI_APPLICATION_TAG=$APPLICATION_VERSION
fi
image_previous="$CI_APPLICATION_REPOSITORY:$CI_COMMIT_BEFORE_SHA"
image_current="$CI_APPLICATION_REPOSITORY:$CI_COMMIT_SHA"
image_tagged="$CI_APPLICATION_REPOSITORY:$CI_APPLICATION_TAG"
image_latest="$CI_APPLICATION_REPOSITORY:latest"
echo "Attempting to pull a previously built image for use with --cache-from..."
docker image pull --quiet "$image_previous" || \
docker image pull --quiet "$image_latest" || \
echo "No previously cached image found. The docker build will proceed without using a cached image"
DOCKER_BUILDKIT=1 docker build --cache-from "$image_previous" --cache-from "$image_latest" \
--tag "$image_current" --tag "$image_tagged" --tag "$image_latest" .
docker push "$image_current"
docker push "$image_tagged"
docker push "$image_latest"
}
before_script:
- *auto_devops