-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
97 lines (91 loc) · 3.25 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
variables:
IMAGE_NAME: "globalfit_prototyping"
# Either empty "" or contains "/" at the end (eg "imageparent/").
IMAGE_PARENT: ""
ARTIFACT_DIR: "./archive" # must be relative to the build directory - https://gitlab.com/gitlab-org/gitlab-foss/-/issues/15530
# For metrics. Git repositories separated by "|".
repo_list_to_count: "https://github.com/tlittenberg/ldasoft"
stages:
- build
- count-lines-of-code
- push
default:
before_script:
- |
export TAG
if test -n "${CI_COMMIT_TAG}" ; then
echo "Pipeline triggered by a tag ${CI_COMMIT_TAG}"
TAG="${CI_COMMIT_TAG}"
elif test -n "${CI_COMMIT_BRANCH}" ; then
echo "Pipeline triggered by a branch ${CI_COMMIT_BRANCH}"
if test "master" == "${CI_COMMIT_BRANCH}" || test "main" == "${CI_COMMIT_BRANCH}" ; then
# main/master branch are special and called latest.
TAG=latest
else
# Replaces all characters with issues and lowercasing.
TAG=$( echo "${CI_COMMIT_BRANCH}" | sed -e 's,[^a-zA-Z0-9_.\-],-,g' | tr '[:upper:]' '[:lower:]' )
fi
else
echo "Unknown case. CI_COMMIT_TAG and CI_COMMIT_BRANCH are empty!" >&2
exit 11
fi
- echo TAG set to $TAG
build:
stage: "build"
image:
# https://docs.gitlab.com/ee/ci/docker/using_kaniko.html
name: gcr.io/kaniko-project/executor:v1.9.1-debug
entrypoint: [""]
script:
- set -x
- |
mkdir -p "${ARTIFACT_DIR}"
mkdir -p /kaniko/.docker
echo "{\"auths\":{\"${CI_REGISTRY_IMAGE}\":{\"auth\":\"$(printf "%s:%s" "${CI_REGISTRY_USER}" "${CI_REGISTRY_PASSWORD}" | base64 | tr -d '\n')\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor
--context "./container_docker"
--dockerfile "./container_docker/Dockerfile"
--destination "${CI_REGISTRY_IMAGE}/${IMAGE_PARENT}${IMAGE_NAME}:${TAG}"
--no-push
--tarPath ${ARTIFACT_DIR}/${IMAGE_NAME}:${TAG}.tar
--cache=true
--cache-ttl=336h
--cache-repo="${CI_REGISTRY_IMAGE}/${IMAGE_PARENT}${IMAGE_NAME}_cache"
- ls -al "${ARTIFACT_DIR}"
artifacts:
name: "archive:${ARTIFACT_NAME}:${CI_JOB_ID}"
when: "on_success"
expire_in: "6h"
paths:
- "${ARTIFACT_DIR}/"
include:
remote: "https://gitlab.com/guided-explorations/code-metrics/ci-cd-extension-scc/-/raw/master/ci-cd-extension-scc.yml"
count-lines-of-code:
# Cleans because we only want metrics to the nested git clone.
before_script:
- |
pwd
id
ls -al
find
echo "Cleaning everyhing but ./archive for SCC of ${repo_list_to_count}..."
find -not -path ./archive -type f -delete
find -not -path ./archive -type d -delete
echo "Clean done."
find
stage: count-lines-of-code
extends: .ci-cd-extension-scc
push:
stage: "push"
image:
name: gcr.io/go-containerregistry/crane/debug:v0.12.1
entrypoint: [""]
# only:
# - "tags"
# - "main"
script:
- set -x
- crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- crane push "${ARTIFACT_DIR}/${IMAGE_NAME}:${TAG}.tar" "${CI_REGISTRY_IMAGE}/${IMAGE_PARENT}${IMAGE_NAME}:${TAG}"
dependencies:
- "build"