-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
160 lines (146 loc) · 3.55 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
stages:
- build
- test
- publish
- release
variables:
APP_NAME: cellar-api
APP_VERSION: 2.0.0
IMAGE_NAME: ${CI_REGISTRY_IMAGE}
PACKAGE_REGISTRY_URL: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic
.api:
image: golang:1.15-buster
cache:
key:
files:
- cellar/go.mod
- cellar/go.sum
prefix: ${CI_PIPELINE_IID}
paths:
- /go
tags:
- gitlab-org-docker
.docker:
image: docker:stable
services:
- name: docker:dind
alias: docker
before_script:
- apk add --no-cache make
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- make docker-build IMAGE_NAME=${IMAGE_NAME} IMAGE_TAG=${APP_VERSION}
after_script:
- docker logout $CI_REGISTRY
build-binary:
extends: .api
stage: build
script:
- make build
build-docker:
extends: .docker
stage: build
script:
- make docker-build APP_VERSION=${APP_VERSION} IMAGE_NAME=${IMAGE_NAME} IMAGE_TAG=${APP_VERSION}
test-unit:
extends: .api
stage: test
script:
- make test-unit
.api-test-depends:
extends: .api
variables:
REDIS_HOST: "redis"
REDIS_PORT: 6379
VAULT_DEV_ROOT_TOKEN_ID: vault-admin
VAULT_DEV_LISTEN_ADDRESS: 0.0.0.0:8200
VAULT_LOCAL_ADDR: http://vault:8200
VAULT_ADDRESS: http://vault:8200
VAULT_ROOT_TOKEN: vault-admin
VAULT_ENCRYPTION_TOKEN_NAME: cellar-testing
VAULT_AUTH_MOUNT_PATH: approle
services:
- name: redis:6.0-alpine
alias: redis
- name: vault:1.5.5
alias: vault
before_script:
- apt-get update && apt-get install -y jq
- make vault-configure
- export VAULT_AUTH_APPROLE_ROLE_ID=$(make vault-role-id)
- export VAULT_AUTH_APPROLE_SECRET_ID=$(make vault-secret-id)
test-integration:
extends: .api-test-depends
stage: test
script:
- make test-integration
test-acceptance:
extends: .api-test-depends
stage: test
script:
- make run-daemon
- make test-acceptance
after_script:
- make stop-daemon
pages:
stage: publish
image: node:alpine
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manual
before_script:
- apk add --no-cache make
script:
- make redoc
APP_VERSION=${APP_VERSION}
REDOC_FILE=public/index.html
artifacts:
paths:
- public
publish-binary:
extends: .api
stage: publish
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manual
script:
- make publish
APP_VERSION=${APP_VERSION}
PACKAGE_ARCH=linux-amd64
PACKAGE_NAME=${APP_NAME}
PACKAGE_REGISTRY_URL=${PACKAGE_REGISTRY_URL}
PACKAGE_TOKEN=${CI_JOB_TOKEN}
artifacts:
name: cellar-api-${APP_VERSION}
paths:
- cellar-api
publish-docker:
extends: .docker
stage: publish
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manual
script:
- make docker-publish APP_VERSION=${APP_VERSION} IMAGE_NAME=${IMAGE_NAME} IMAGE_TAG=${APP_VERSION}
- make docker-publish APP_VERSION=${APP_VERSION} IMAGE_NAME=${IMAGE_NAME} IMAGE_TAG=latest
release:
stage: release
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
needs:
- job: publish-binary
artifacts: true
- job: pages
artifacts: true
- job: publish-docker
image: registry.gitlab.com/gitlab-org/release-cli:latest
before_script:
- apk add --no-cache make
script:
- make release
APP_VERSION=${APP_VERSION}
IMAGE_NAME=${IMAGE_NAME}
IMAGE_TAG=${APP_VERSION}
PACKAGE_ARCH=linux-amd64
PACKAGE_NAME=${APP_NAME}
PACKAGE_REGISTRY_URL=${PACKAGE_REGISTRY_URL}