-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.gitlab-ci.yml
107 lines (105 loc) · 4.07 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
stages:
- build
variables:
TAG_FULL: ${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA} # Warning duplication in IMAGE_FULL. It's here due to gitlab...
IMAGE_BRANCH: ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_REF_NAME}
IMAGE_FULL: ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}
go_build:
variables:
DOCKERVERSION: 18.09.3
# When using dind service we need to instruct docker, to talk with the
# daemon started inside of the service. The daemon is available with
# a network connection instead of the default /var/run/docker.sock socket.
#
# The 'docker' hostname is the alias of the service container as described at
# https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#accessing-the-services
#
# Note that if you're using Kubernetes executor, the variable should be set to
# tcp://localhost:2375 because of how Kubernetes executor connects services
# to the job container
DOCKER_HOST: tcp://docker:2375/
# When using dind, it's wise to use the overlayfs driver for
# improved performance.
# DOCKER_DRIVER: overlay2
CGO_ENABLED: 0
before_script:
- echo https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKERVERSION}.tgz
- curl -fsSLO https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKERVERSION}.tgz
- tar xzvf docker-${DOCKERVERSION}.tgz --strip 1 -C /usr/local/bin docker/docker
- docker info
- go env
- mkdir ~/.docker || true
- echo $DOCKER_CONFIG | base64 -d > ~/.docker/config.json
- cat ~/.docker/config.json | wc
- mkdir -p $GOPATH/src/github.com/KrakenSystems/
- cd $GOPATH/src/github.com/KrakenSystems/
- ln -s $CI_PROJECT_DIR
- export GO_PROJECT_PATH="$GOPATH/src/github.com/KrakenSystems/${CI_PROJECT_NAME}"
- echo $GO_PROJECT_PATH
- cd $GO_PROJECT_PATH
- pwd
- ls
- go get github.com/golang/dep/cmd/dep # Install dep
- cd $GO_PROJECT_PATH
- pwd
- ls
services:
- docker:dind
stage: build
image: golang:1.12
script:
- mkdir -p .cache
- export GOCACHE=${CI_PROJECT_DIR}/.cache
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN ${CI_REGISTRY}
- dep ensure -vendor-only -v
- go env
- go test ./...
- GOOS=linux GOARCH=amd64 go build -a -ldflags '-extldflags "-static"' -o build/${CI_PROJECT_NAME}-amd64 ./cmd/manager
- |
cat << EOF > pack.Dockerfile
FROM alpine
WORKDIR /bin
COPY build/${CI_PROJECT_NAME}-amd64 /bin/${CI_PROJECT_NAME}
ENTRYPOINT [ "/bin/${CI_PROJECT_NAME}" ]
EOF
- cat pack.Dockerfile
- docker build -t ${IMAGE_FULL}-amd64 -f pack.Dockerfile .
- docker push ${IMAGE_FULL}-amd64
- docker build -t ${IMAGE_BRANCH}-amd64 -f pack.Dockerfile .
- docker push ${IMAGE_BRANCH}-amd64
- echo "========="
- GOOS=linux GOARCH=arm GOARM=7 go build -a -ldflags '-extldflags "-static"' -o build/${CI_PROJECT_NAME}-arm32v7 ./cmd/manager
- |
cat << EOF > pack.Dockerfile
FROM arm32v7/alpine
WORKDIR /bin
COPY build/${CI_PROJECT_NAME}-arm32v7 /bin/${CI_PROJECT_NAME}
ENTRYPOINT [ "/bin/${CI_PROJECT_NAME}" ]
EOF
- cat pack.Dockerfile
- docker build -t ${IMAGE_FULL}-arm32v7 -f pack.Dockerfile .
- docker push ${IMAGE_FULL}-arm32v7
- docker build -t ${IMAGE_BRANCH}-arm32v7 -f pack.Dockerfile .
- docker push ${IMAGE_BRANCH}-arm32v7
- echo "========="
- GOOS=linux GOARCH=arm64 go build -a -ldflags '-extldflags "-static"' -o build/${CI_PROJECT_NAME}-arm64v8 ./cmd/manager
- |
cat << EOF > pack.Dockerfile
FROM arm64v8/alpine
WORKDIR /bin
COPY build/${CI_PROJECT_NAME}-arm64v8 /bin/${CI_PROJECT_NAME}
ENTRYPOINT [ "/bin/${CI_PROJECT_NAME}" ]
EOF
- cat pack.Dockerfile
- docker build -t ${IMAGE_FULL}-arm64v8 -f pack.Dockerfile .
- docker push ${IMAGE_FULL}-arm64v8
- docker build -t ${IMAGE_BRANCH}-arm64v8 -f pack.Dockerfile .
- docker push ${IMAGE_BRANCH}-arm64v8
artifacts:
paths:
- build/
expire_in: 1 week
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- .cache/