-
Notifications
You must be signed in to change notification settings - Fork 16
/
.gitlab-ci.yml
72 lines (68 loc) · 1.74 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
image:
name: golang:1.13
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
variables:
GO111MODULE: 'on'
GOOS: 'linux'
GOARCH: 'amd64'
stages:
- build_binary
- build_docker
# This builds and tests the binary prior to building an image.
build_binary:
stage: build_binary
image: golang:1.13
before_script:
- cd $GOPATH/src
- mkdir -p github.com/grab
- cd github.com/grab
- ln -s $CI_PROJECT_DIR
- cd $CI_PROJECT_NAME
script:
- go test ./...
- go build .
artifacts:
untracked: true
paths:
- talaria
only:
refs:
- merge_requests
- master
# This builds a docker for the merge request. The docker image can be fetched under 'talariadb/db:testing' tag.
build_docker_mr:
stage: build_docker
image: docker:stable
dependencies:
- build_binary
services:
- docker:dind
tags:
- docker
script:
- docker build . --build-arg GO_BINARY=talaria -t="talariadb/db:testing"
- docker login --username="$DOCKER_USERNAME" --password="$DOCKER_PASSWORD"
- docker push talariadb/db:testing
only:
refs:
- merge_requests
# This builds the final docker image that can be deployed. It creates 'talariadb/db:latest' and 'talariadb/db:$COMMIT' tags.
build_docker:
stage: build_docker
image: docker:stable
dependencies:
- build_binary
services:
- docker:dind
tags:
- docker
script:
- docker build . --build-arg GO_BINARY=talaria -t="talariadb/db:$CI_COMMIT_SHORT_SHA" -t="talariadb/db:latest"
- docker login --username="$DOCKER_USERNAME" --password="$DOCKER_PASSWORD"
- docker push talariadb/db:$CI_COMMIT_SHORT_SHA
- docker push talariadb/db:latest
only:
refs:
- master