-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
97 lines (91 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
96
97
stages:
- test
- build
- release
variables:
IMAGE_REPO:
description: "The container registry where the built image will be pushed."
value: "registry.gitlab.com/${GITLAB_USER_LOGIN}/go-hello-world"
USE_KO:
description: "Whether to use ko for building."
value: "yes"
go-test:
stage: test
image:
name: golang:1.19
entrypoint: [""]
script:
- go test -v ./...
go-build:
stage: build
image:
name: golang:1.19
entrypoint: [""]
variables:
KO_DOCKER_REPO:
value: "$IMAGE_REPO"
script: |
curl -sfL https://goreleaser.com/static/run |\
VERSION=v1.16.2 DISTRIBUTION=oss bash -s -- build --clean --snapshot
artifacts:
paths:
- dist
rules:
- if: $USE_KO == "no"
ko-build:
stage: build
image: docker.io/kameshsampath/kube-dev-tools:0.1.5
variables:
KO_DOCKER_REPO:
value: "$IMAGE_REPO"
before_script:
- echo "$CI_REGISTRY_PASSWORD" | ko auth login registry.gitlab.com -u "$CI_REGISTRY_USER" --password-stdin
script: |
ko build --bare --platform=linux/amd64 --platform=linux/arm64 --tags "$CI_COMMIT_SHORT_SHA" .
rules:
- if: $USE_KO == "yes"
docker-build:
stage: build
needs:
- go-build
image: docker:20.10.23-git
services:
- docker:20.10.23-dind
variables:
BUILDER_NAME: "buildx-multi-arch"
DOCKER_REGISTRY: $CI_REGISTRY
DOCKER_USERNAME: $CI_REGISTRY_USER
DOCKER_PASSWORD: $CI_REGISTRY_PASSWORD
before_script:
- echo "$DOCKER_PASSWORD" | docker login $DOCKER_REGISTRY -u $DOCKER_USERNAME --password-stdin
script:
- docker buildx inspect $BUILDER_NAME || docker buildx create --name=$BUILDER_NAME --driver=docker-container --driver-opt=network=host
- docker buildx build --builder=$BUILDER_NAME --push --platform=linux/arm64 --platform=linux/amd64 -t $IMAGE_REPO:$CI_COMMIT_SHORT_SHA -f Dockerfile .
rules:
- if: $USE_KO == "no"
exists:
- Dockerfile
release:
stage: release
services:
- docker:20.10.23-dind
only:
refs:
- tags
image:
name: docker:stable
entrypoint: [""]
variables:
DOCKER_REGISTRY: $CI_REGISTRY
DOCKER_USERNAME: $CI_REGISTRY_USER
DOCKER_PASSWORD: $CI_REGISTRY_PASSWORD
GIT_DEPTH: 0
script: |
docker run --rm --privileged \
-v $PWD:/go/src/gitlab.com/$GITLAB_USER_LOGIN/go-hello-world \
-w /go/src/gitlab.com/$GITLAB_USER_LOGIN/go-hello-world \
-v /var/run/docker.sock:/var/run/docker.sock \
-e DOCKER_USERNAME -e DOCKER_PASSWORD -e DOCKER_REGISTRY \
-e GITLAB_TOKEN \
-e GITLAB_USER_LOGIN \
goreleaser/goreleaser release --clean