-
Notifications
You must be signed in to change notification settings - Fork 0
/
.drone.yml
118 lines (100 loc) · 3.87 KB
/
.drone.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
# -----------------------------------------------------------------------------
# SETTINGS
# -----------------------------------------------------------------------------
# Drone matrix: Additional ENV vars for substitution - http://docs.drone.io/matrix-builds/
# Will be evaluated BEFORE the YAML is parsed, ONLY strings allowed, NO substitutions ${XXX} here.
matrix:
include:
- BUILD_ENV: all
# The name of the k8s namespaces that these pipelines will target.
# K8S_DEPLOY_NS_DEV:
# K8S_DEPLOY_NS_STAGING:
# K8S_DEPLOY_NS_PRODUCTION:
# YAML Configuration anchors - https://learnxinyminutes.com/docs/yaml/
# Will be evaluated WHILE the YAML is parsed, any valid yaml allowed, substitutions ${XXX} allowed.
alias:
# The image will be tagged with this, pushed to gcr and referenced with this key in the k8s deployment
- &IMAGE_DEPLOY_TAG ${DRONE_COMMIT_SHA}
# The image name, defaults to lowercase repo name <owner>/<project>, e.g. aw/aaa-cab-kubernetes-test
- &IMAGE_DEPLOY_NAME ${DRONE_REPO,,}
# The full uniquely tagged app image name
- &IMAGE_DEPLOY_ID ${DRONE_REPO,,}:${DRONE_COMMIT_SHA}
# Defines which branches will trigger a docker image push our Google Cloud Registry (tags are always published)
- &GCR_PUBLISH_BRANCHES [main, dev]
# Docker registry publish default settings
- &GCR_REGISTRY_SETTINGS
image: plugins/gcr
repo: a3cloud-192413/${DRONE_REPO,,}
registry: eu.gcr.io
secrets:
- source: AAA_GCR_SERVICE_ACCOUNT_JSON
target: google_credentials
# local short-time-cache: don't cleanup any image layers after pushing
purge: false
# force compress of docker build context
compress: true
volumes: # mount needed to push the already build container
- /var/run/docker.sock:/var/run/docker.sock
# ENV variables for executing within the test env (similar to the env in docker-compose.yml)
- &TEST_ENV
CI: ${CI}
# Which build events should trigger the main pipeline (defaults to all)
- &BUILD_EVENTS [push, pull_request, tag]
# Pipeline merge helper: only execute if build event received
- &WHEN_BUILD_EVENT
when:
event: *BUILD_EVENTS
# The actual pipeline building our product
pipeline:
# ---------------------------------------------------------------------------
# BUILD
# ---------------------------------------------------------------------------
"docker build":
group: build-app
image: docker:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
IMAGE_TAG: *IMAGE_DEPLOY_ID
commands:
- "docker build --compress -t $${IMAGE_TAG} ."
<<: *WHEN_BUILD_EVENT
# ---------------------------------------------------------------------------
# PUBLISH
# ---------------------------------------------------------------------------
# Built a allowed branch? Push to cloud registry
"publish ${DRONE_BRANCH}_${DRONE_COMMIT_SHA:0:10}":
group: publish
<<: *GCR_REGISTRY_SETTINGS
tags:
- build_${DRONE_BUILD_NUMBER}
- ${DRONE_BRANCH/\//-}_${DRONE_COMMIT_SHA:0:10}
- *IMAGE_DEPLOY_TAG
- latest
- ${DRONE_BRANCH/\//-}
- "${DRONE_COMMIT_SHA:0:10}"
when:
branch: *GCR_PUBLISH_BRANCHES
event: *BUILD_EVENTS
# Built a tag? Push to cloud registry
"publish tag_${DRONE_COMMIT_SHA:0:10}":
group: publish
<<: *GCR_REGISTRY_SETTINGS
tags:
- build_${DRONE_BUILD_NUMBER}
- tag_${DRONE_COMMIT_SHA:0:10}
- *IMAGE_DEPLOY_TAG
- latest
- ${DRONE_TAG}
- ${DRONE_COMMIT_SHA:0:10}
when:
event: tag
# Long living services where the startup order does not matter (otherwise use detach: true)
services:
# ---------------------------------------------------------------------------
# SERVICES
# ---------------------------------------------------------------------------
"env":
image: alpine
commands:
- "env | sort"