-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
157 lines (147 loc) · 4.62 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
151
152
153
154
155
156
157
stages:
- lint
- build
- deploy
variables:
APP_BUILD_VERSION: 0.0.0
APP_BUILD_MODE: development
.kaniko-build-pre-script: &kaniko-build-pre-script |
set -x
mkdir -p /kaniko/.docker
echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
.kaniko-build-taggable-name: &kaniko-build-taggable-name |
set -x
COMMIT_HASH="???"
BUILD_DATE="$(date -u +%Y-%m-%d_%I:%M:%S%p)"
if [[ -z "$CI_COMMIT_TAG" ]]; then
COMMIT_HASH="$CI_COMMIT_SHORT_SHA"
PRINTABLE_COMMIT_HASH="-$COMMIT_HASH"
fi
if [[ ! "$CI_COMMIT_BRANCH" = "$CI_DEFAULT_BRANCH" ]] && [[ -z "$CI_COMMIT_TAG" ]]; then
BRANCH_NAME="-$CI_COMMIT_BRANCH"
fi
.kaniko-pre-build-release-version: &kaniko-pre-build-release-version |
if [[ ! -z "$CI_COMMIT_TAG" ]]; then
export APP_BUILD_VERSION="$CI_COMMIT_TAG"
export APP_BUILD_MODE=production
export KANIKO_EXTRA_DESTINATION="--destination $CI_REGISTRY_IMAGE/$APP:$APP_BUILD_VERSION"
fi
build-reconciler-container:
stage: build
image:
name: gcr.io/kaniko-project/executor:debug-v1.3.0
entrypoint: [""]
retry: 2
variables:
APP: reconciler
APP_PATH_NAME: reconciler
before_script:
- *kaniko-build-pre-script
- *kaniko-build-taggable-name
- *kaniko-pre-build-release-version
script:
- |
/kaniko/executor \
--snapshotMode=redo \
--context $CI_PROJECT_DIR/apps/$APP_PATH_NAME \
--dockerfile $CI_PROJECT_DIR/apps/$APP_PATH_NAME/Dockerfile \
--destination $CI_REGISTRY_IMAGE/$APP:latest$BRANCH_NAME \
$KANIKO_EXTRA_DESTINATION \
--build-arg AppBuildVersion="$APP_BUILD_VERSION" \
--build-arg AppBuildDate="$BUILD_DATE" \
--build-arg AppBuildHash="$COMMIT_HASH" \
--build-arg AppBuildMode="$APP_BUILD_MODE"
build-cluster-api-manager-container:
stage: build
image:
name: gcr.io/kaniko-project/executor:debug-v1.3.0
entrypoint: [""]
retry: 2
variables:
APP: clusterapimanager
APP_PATH_NAME: cluster-api-manager
before_script:
- *kaniko-build-pre-script
- *kaniko-build-taggable-name
- *kaniko-pre-build-release-version
script:
- |
/kaniko/executor \
--snapshotMode=redo \
--context $CI_PROJECT_DIR/apps/$APP_PATH_NAME \
--dockerfile $CI_PROJECT_DIR/apps/$APP_PATH_NAME/Dockerfile \
--destination $CI_REGISTRY_IMAGE/$APP:latest$BRANCH_NAME \
$KANIKO_EXTRA_DESTINATION \
--build-arg AppBuildVersion="$APP_BUILD_VERSION" \
--build-arg AppBuildDate="$BUILD_DATE" \
--build-arg AppBuildHash="$COMMIT_HASH" \
--build-arg AppBuildMode="$APP_BUILD_MODE"
build-client-container:
stage: build
image:
name: gcr.io/kaniko-project/executor:debug-v1.3.0
entrypoint: [""]
retry: 2
variables:
APP: client
APP_PATH_NAME: client
before_script:
- *kaniko-build-pre-script
- *kaniko-build-taggable-name
- *kaniko-pre-build-release-version
script:
- |
/kaniko/executor \
--context $CI_PROJECT_DIR/apps/$APP_PATH_NAME \
--dockerfile $CI_PROJECT_DIR/apps/$APP_PATH_NAME/Dockerfile \
--destination $CI_REGISTRY_IMAGE/$APP:latest$BRANCH_NAME \
$KANIKO_EXTRA_DESTINATION
spell-check:
stage: lint
image: golang:1.16.0-alpine3.13
allow_failure: true
before_script:
- go get -u github.com/client9/misspell/cmd/misspell
script:
- misspell -error apps charts infra org README*
lint-backend:
stage: lint
image: golang:1.16.0-alpine3.13
allow_failure: true
before_script:
- apk add git gcc
- go get -u golang.org/x/lint/golint
script:
- golint -set_exit_status ./apps/cluster-api-manager/... ./apps/reconciler/...
deploy:
stage: deploy
image:
name: alpine:3.12
entrypoint: [""]
variables:
KUBECTL_VERSION: v1.20.2
KUBECTL_HASH: 2583b1c9fbfc5443a722fb04cf0cc83df18e45880a2cf1f6b52d9f595c5beb88
MANIFEST_FOLDER: $CI_PROJECT_DIR/manifests
before_script:
- apk add --no-cache curl gettext
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl
- echo "$KUBECTL_HASH kubectl" | sha256sum -c -
- chmod +x kubectl
- mv kubectl /usr/local/bin/kubectl
- mkdir -p $HOME/.kube
- echo ${KUBECONFIG_FROM_ENV} | base64 -d > $HOME/.kube/config
- cd $MANIFEST_FOLDER
- export SHARINGIO_PAIR_TAG=$CI_COMMIT_TAG
script:
- |
for MANIFEST in $MANIFEST_FOLDER/*; do
if cat $MANIFEST | grep -q ci-sa:noapply=true; then
continue
fi
envsubst < $MANIFEST | kubectl apply -f -
done
only:
refs:
- tags
variables:
- $KUBECONFIG_FROM_ENV