-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci.yml
95 lines (86 loc) · 2.57 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
stages:
- lint
- test
- build
include:
template: Dependency-Scanning.gitlab-ci.yml
variables:
ARCH_DEFAULT: "amd64"
ARCHES: amd64 arm64
APP_BUILD_VERSION: 0.0.0
APP_BUILD_MODE: development
IMAGE_GOLANG_ALPINE: docker.io/golang:1.17.0-alpine3.14
IMAGE_ALPINE: docker.io/alpine:3.14
IMAGE_DOCKER: docker.io/docker:20.10.6
.container-registry-login-ko: &container-registry-login-ko |
ko login "${CI_REGISTRY}" -u "${CI_REGISTRY_USER}" -p "${CI_REGISTRY_PASSWORD}"
.image-build-taggable-name: &image-build-taggable-name |
echo "Commit made on '${CI_COMMIT_TIMESTAMP}'"
export APP_BUILD_HASH="$CI_COMMIT_SHORT_SHA"
export APP_BUILD_DATE=$(date --date="${CI_COMMIT_TIMESTAMP//[T+]/ }" '+%Y.%m.%d.%H%M')
if [[ -z "$CI_COMMIT_TAG" ]]; then
PRINTABLE_COMMIT_HASH="-$APP_BUILD_HASH"
fi
if [[ ! "$CI_COMMIT_BRANCH" = "$CI_DEFAULT_BRANCH" ]] && [[ -z "$CI_COMMIT_TAG" ]]; then
BRANCH_NAME="-$CI_COMMIT_BRANCH"
fi
PROJECT_PATH=$(echo $CI_PROJECT_PATH | tr '[:upper:]' '[:lower:]')
.image-pre-build-release-version: &image-pre-build-release-version |
export APP_BUILD_VERSION=0.0.0
export APP_BUILD_MODE=development
if [[ ! -z "$CI_COMMIT_TAG" ]]; then
export APP_BUILD_VERSION="$CI_COMMIT_TAG"
export APP_BUILD_MODE=production
export IMAGE_RELEASE_DESTINATIONS="$APP_BUILD_VERSION"
fi
export IMAGE_DESTINATIONS="latest$BRANCH_NAME"
.image-build: &image-build |
ko publish \
--push \
--jobs 100 \
--bare \
--platform all \
--tags "${IMAGE_DESTINATIONS},${IMAGE_RELEASE_DESTINATIONS:-latest}" \
.
build-container:
stage: build
image:
name: $IMAGE_GOLANG_ALPINE
entrypoint: [""]
retry: 2
variables:
KO_DOCKER_REPO: "$CI_REGISTRY_IMAGE"
before_script:
- set -x
- go install github.com/google/ko@latest
- *container-registry-login-ko
- *image-build-taggable-name
- *image-pre-build-release-version
script:
- *image-build
test:
image: $IMAGE_GOLANG_ALPINE
stage: test
variables:
CGO_ENABLED: "0"
before_script:
- apk add --no-cache git gcc
- go get -v ./...
- go get github.com/onsi/ginkgo/[email protected]
- go get github.com/onsi/gomega/[email protected]
- touch config.yaml
- go run main.go &
script:
- ginkgo -r --randomizeAllSpecs --randomizeSuites --failOnPending --cover --trace --progress test/
lint:
stage: lint
image: $IMAGE_GOLANG_ALPINE
allow_failure: true
before_script:
- apk add git gcc
- go get -u golang.org/x/lint/golint
script:
- echo -e "GOLINT\n"
- golint -set_exit_status ./...
- echo -e "GOFMT\n"
- gofmt -d .