-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
159 lines (144 loc) · 4.71 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
158
159
image: golang:1.23-alpine
variables:
CGO_ENABLED: 0
RELEASE_CLI_VERSION: "v0.18.0"
DEVELOPER_BRANCH: "features"
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${CI_COMMIT_TAG}/"
PLATFORMS: "linux/amd64 linux/arm64"
stages:
- test
- build
- upload
- release
- push
#sast:
# stage: test
test:
stage: test
script:
- apk add --no-cache build-base
- go fmt $(go list ./... | grep -v /vendor/)
- go vet $(go list ./... | grep -v /vendor/)
- go test -short $(go list ./... | grep -v /vendor/)
- CGO_ENABLED=1 go test -race -short $(go list ./... | grep -v /vendor/)
cache:
key: "$CI_COMMIT_REF_SLUG"
paths:
- .docker/
rules:
- if: $CI_COMMIT_BRANCH == $DEVELOPER_BRANCH
build:
stage: build
script:
- |
tag="dev"
if [[ -n "$CI_COMMIT_TAG" ]]; then
tag="${CI_COMMIT_TAG}"
fi
for PLATFORM in ${PLATFORMS}; do
GOOS=${PLATFORM%/*}
GOARCH=${PLATFORM#*/}
FILEPATH="${CI_PROJECT_DIR}/bin/${GOOS}-${GOARCH}"
mkdir -p ${FILEPATH}
BIN_FILE_NAME="${FILEPATH}/${CI_PROJECT_NAME}-${GOOS}-${GOARCH}-${tag}"
echo "Building ${BIN_FILE_NAME}"
GOOS=${GOOS} GOARCH=${GOARCH} go build -mod=vendor -ldflags="-s -X main.version=${tag}-${CI_COMMIT_SHORT_SHA}" -o ${BIN_FILE_NAME} ./server
done
artifacts:
paths:
- bin/
cache:
key: "$CI_COMMIT_REF_SLUG"
paths:
- .docker/
#rules:
# - if: $CI_COMMIT_TAG
upload:
stage: upload
image: curlimages/curl:latest
script:
- |
find ${CI_PROJECT_DIR}/bin/ -type f | while read filename; do
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file ${filename} ${PACKAGE_REGISTRY_URL}/$(basename ${filename})
done
rules:
- if: $CI_COMMIT_TAG
release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:$RELEASE_CLI_VERSION
script:
- |
ASSETS=""
for PLATFORM in ${PLATFORMS}; do
GOOS=${PLATFORM%/*}
GOARCH=${PLATFORM#*/}
BIN_FILE_NAME="${CI_PROJECT_NAME}-${GOOS}-${GOARCH}-${CI_COMMIT_TAG}"
if [[ "${GOOS}" == "windows" ]]; then
BIN_FILE_NAME="${BIN_FILE_NAME}.exe"
fi
echo "Adding asset ${BIN_FILE_NAME}"
ASSETS="${ASSETS} --assets-link {\"name\":\"${BIN_FILE_NAME}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${BIN_FILE_NAME}\"}"
done
release-cli create --name "Release ${CI_COMMIT_TAG}" --tag-name ${CI_COMMIT_TAG} ${ASSETS}
rules:
- if: $CI_COMMIT_TAG
# docker:
# stage: build
# image: docker:26
# before_script:
# - docker login -u "${CI_REGISTRY_USER}" -p "${CI_REGISTRY_PASSWORD}" ${CI_REGISTRY}
# script:
# - docker pull ${CI_REGISTRY_IMAGE}:latest || true
# - >
# docker build
# --pull
# --build-arg http_proxy=${http_proxy}
# --build-arg https_proxy=${https_proxy}
# --build-arg no_proxy=${no_proxy}
# --cache-from ${CI_REGISTRY_IMAGE}:latest
# --label "org.opencontainers.image.title=${CI_PROJECT_TITLE}"
# --label "org.opencontainers.image.url=${CI_PROJECT_URL}"
# --label "org.opencontainers.image.created=${CI_JOB_STARTED_AT}"
# --label "org.opencontainers.image.revision=${CI_COMMIT_SHA}"
# --label "org.opencontainers.image.version=${CI_COMMIT_REF_NAME}"
# --tag ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}
# .
# - docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}
#
# push tags 1/2:
# stage: push
# image: docker:26
# before_script:
# - docker login -u "${CI_REGISTRY_USER}" -p "${CI_REGISTRY_PASSWORD}" ${CI_REGISTRY}
# variables:
# GIT_STRATEGY: none
# script:
# - docker pull ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}
# - |
# if [[ "${CI_COMMIT_BRANCH}" == "${CI_DEFAULT_BRANCH}" ]]; then
# docker_tag="latest"
# else
# docker_tag="dev"
# fi
# - docker tag ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA} ${CI_REGISTRY_IMAGE}:${docker_tag}
# - docker push ${CI_REGISTRY_IMAGE}:${docker_tag}
#
# push tags 2/2:
# stage: push
# image: docker:26
# before_script:
# - docker login -u "${CI_REGISTRY_USER}" -p "${CI_REGISTRY_PASSWORD}" ${CI_REGISTRY}
# variables:
# GIT_STRATEGY: none
# script:
# - docker pull ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}
# - docker tag ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA} ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}
# - docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}
# rules:
# - if: $CI_COMMIT_TAG
secret_detection:
variables:
SECRET_DETECTION_HISTORIC_SCAN: "true"
include:
- template: Security/SAST.gitlab-ci.yml
- template: Security/Secret-Detection.gitlab-ci.yml