This repository has been archived by the owner on May 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
87 lines (79 loc) · 2.4 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
services:
- postgres:13-alpine
variables:
POSTGRES_DB: biblebotinternal
POSTGRES_USER: biblebotinternal
POSTGES_PASSWORD: dev
POSTGRES_HOST_AUTH_METHOD: trust
DOCKER_IMAGE: $CI_REGISTRY_IMAGE:prod-latest
include:
- template: Container-Scanning.gitlab-ci.yml
- template: Dependency-Scanning.gitlab-ci.yml
stages:
- build
- test
- tag
test:
image: golang:1.16
stage: test
script:
- go fmt $(go list ./... | grep -v /vendor/)
- go vet $(go list ./... | grep -v /vendor/)
- go test -v $(go list ./... | grep -v /vendor/)
build:dev:
image: docker:dind
stage: build
before_script:
- echo -n $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
script:
- >
docker build
--cache-from $CI_REGISTRY_IMAGE:dev-latest
--pull
--file Dockerfile
--tag $CI_REGISTRY_IMAGE:dev-latest
.
- docker push $CI_REGISTRY_IMAGE:dev-latest
build:prod:
image: docker:dind
stage: build
before_script:
- echo -n $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
script:
- >
docker build
--cache-from $CI_REGISTRY_IMAGE:prod-latest
--pull
--file Dockerfile
--build-arg DOMAIN=api.biblebot.xyz
--tag $CI_REGISTRY_IMAGE:prod-latest
.
- docker push $CI_REGISTRY_IMAGE:prod-latest
tag:dev:
needs: ["build:dev"]
image: docker:dind
stage: tag
variables:
GIT_STRATEGY: none
only:
- tags
before_script:
- echo -n $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
script:
- docker pull $CI_REGISTRY_IMAGE:dev-latest
- docker tag $CI_REGISTRY_IMAGE:dev-latest $CI_REGISTRY_IMAGE:dev-$CI_COMMIT_REF_NAME
- docker push $CI_REGISTRY_IMAGE:dev-$CI_COMMIT_REF_NAME
tag:prod:
needs: ["build:prod"]
image: docker:dind
stage: tag
variables:
GIT_STRATEGY: none
only:
- tags
before_script:
- echo -n $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
script:
- docker pull $CI_REGISTRY_IMAGE:prod-latest
- docker tag $CI_REGISTRY_IMAGE:prod-latest $CI_REGISTRY_IMAGE:prod-$CI_COMMIT_REF_NAME
- docker push $CI_REGISTRY_IMAGE:prod-$CI_COMMIT_REF_NAME