-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.yml
219 lines (207 loc) · 7.76 KB
/
build.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
default: "help"
expose: [
"info",
"docker",
"docker-tag",
"docker-push",
]
configuration: ["~/.dockerhub.yml", "~/.github.yml"] # DO NOT COMMIT THESE FILES
# ~/.dockerhub.yml should contains:
# DOCKERHUB_USER: <your dockerhub user>
# DOCKERHUB_PASS: <your dockerhub password or a dockerhub token>
# ~/.github.yml should contains:
# GITHUB_TOKEN: <your github token>
properties:
# Build Configuration (edit this section to override default values)
BY: "" # Leave empty to default to the user.email property in git configuration
MODULE: "" # Leave empty to default to the git remote url (e.g. "github.com/<usename>/<reponame>")
PROJECT: "" # Leave empty to default to the git repository name (e.g. "<reponame>")
DOCKERHUB_ORGANIZATION: "cgifr" # Image tag : cgi-fr/lino
# Build parameters (use the -props flag or change these default values)
tag: "" # Default to the current branch or tag, can be overriden
latest: false # Do not tag the Docker image with latest, specify othewise with `-props "{latest: true}"`
# If true, do not upload release when publish target is used
snapshot: false
# List of Dockerfiles to build, defined by a map of {key=Dockerfile name ; value=path to build context}, the image name will be determined by the extension of the Dockerfile
dockerfiles:
Dockerfile.debian: .
shell: ["sh", "-c"]
targets:
info:
doc: "Print build informations"
steps:
- if: tag == ""
then:
- $: "git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD"
1=: "tag"
3x: true
else:
- $: "echo -n ={tag}"
1=: "tag"
3x: true
- $: 'echo -n "={tag}" | sed -e s#/##'
1=: "tag"
3x: true
- $: 'echo -n "={tag}" | sed -e s/^v//'
1=: "version"
3x: true
- $: "git rev-parse HEAD 2>/dev/null"
1=: "commit"
3x: true
- "date = now()[0:10]"
- if: BY == ""
then:
- $: "git config user.email"
1=: "by"
3x: true
else:
- $: "echo -n ={BY}"
1=: "by"
3x: true
- $: 'if expr match "={version}" "v\?[0-9]\+\.[0-9]\+\.[0-9]\+" 1>/dev/null 2>&1; then echo -n "yes"; else echo -n "no"; fi'
1=: "is_release"
3x: true
- $: "cut -f1 -d."
<: "=version"
1=: "version_major"
3x: true
- $: "cut -f2 -d."
<: "=version"
1=: "version_minor"
3x: true
- $: "cut -f3 -d."
<: "=version"
1=: "version_patch"
3x: true
- if: MODULE == ""
then:
- $: "git config --local remote.origin.url | sed -n 's#^.*//\\(.*\\)\\.git$#\\1#p' | tr '[:upper:]' '[:lower:]'" # .*//(.*)\.git => https://github.com/<user>/<repo>.git => github.com/<user>/<repo>
1=: "mod"
3x: true
else:
- $: "echo -n ={MODULE}"
1=: "mod"
3x: true
- if: PROJECT == ""
then:
- $: "cut -f3 -d/"
<: "=mod"
1=: "project"
3x: true
else:
- $: "echo -n ={PROJECT}"
1=: "project"
3x: true
- print: |-
MODULE = ={mod}
PROJECT = ={project}
TAG = ={tag}
COMMIT = ={commit}
DATE = ={date}
BY = ={by}
RELEASE = ={is_release}
- if: 'is_release == "yes"'
then:
- print: |-
VERSION = ={version_major}.={version_minor}.={version_patch}
# run "neon -props '{dockerfiles: {"path/to/Dockerfile1": "path/to/root/build/context"}}' docker" to build specific Dockerfiles
# example : neon -props '{dockerfiles: {"Dockerfile": "."}}' docker
docker:
doc: "Build docker images"
depends: ["info"]
steps:
- try:
- $: "# ={DOCKERHUB_ORGANIZATION}"
3x: true
catch:
- print: |
To use this target, make sure your DOCKERHUB_ORGANIZATION is set.
- $: return 1
- $: "date -u +'%Y-%m-%dT%H:%M:%SZ'"
1=: "daterfc3339"
3x: true
- |
build_args = " --build-arg BUILD_DATE=" + daterfc3339
build_args += " --build-arg VERSION=" + version
build_args += " --build-arg REVISION=" + commit
- for: key
in: keys(dockerfiles)
do:
- |
keycomponents = split(key, ".")
suffix = ""
if len(keycomponents) > 1 {
suffix = "-" + keycomponents[len(keycomponents)-1]
}
- $: "sudo docker build --no-cache -q -t ={DOCKERHUB_ORGANIZATION}/={project}:={tag}={suffix} -f ={key} ={dockerfiles[key]}"
1x: true
# run "neon -props '{latest: true}' docker-tag" to include latest tag
docker-tag:
doc: "Tag docker images"
# unless: 'is_release != "yes"' => is_release unknown variable, issue to open
depends: ["info", "docker"]
steps:
- if: 'is_release == "yes"'
then:
- try:
- $: "# ={DOCKERHUB_ORGANIZATION}"
3x: true
catch:
- print: |
To use this target, make sure your DOCKERHUB_ORGANIZATION is set.
- $: return 1
- for: key
in: keys(dockerfiles)
do:
- |
keycomponents = split(key, ".")
suffix = ""
if len(keycomponents) > 1 {
suffix = "-" + keycomponents[len(keycomponents)-1]
}
- $: "sudo docker tag ={DOCKERHUB_ORGANIZATION}/={project}:={tag}={suffix} ={DOCKERHUB_ORGANIZATION}/={project}:v={version_major}={suffix}"
- $: "sudo docker tag ={DOCKERHUB_ORGANIZATION}/={project}:={tag}={suffix} ={DOCKERHUB_ORGANIZATION}/={project}:v={version_major}.={version_minor}={suffix}"
- if: "latest"
then:
- $: "sudo docker tag ={DOCKERHUB_ORGANIZATION}/={project}:={tag}={suffix} ={DOCKERHUB_ORGANIZATION}/={project}:latest={suffix}"
else:
- print: "Skipping release target (not a release)"
color: red
docker-login:
steps:
- try:
- $: "sudo docker login -u ={DOCKERHUB_USER} -p ={DOCKERHUB_PASS}"
2x: true
catch:
- print: |
To use this target, make sure your credentials are valid in the file ~/.dockerhub.yml
The content of the file should be :
DOCKERHUB_USER: <your dockerhub user>
DOCKERHUB_PASS: <your dockerhub password or a dockerhub token>
- $: return 1
# run "neon -props '{latest: true}' docker-push" to include latest tag
docker-push:
doc: "Push docker images to Dockerhub"
# unless: 'is_release != "yes"' => is_release unknown variable, issue to open
depends: ["docker", "docker-tag", "docker-login"]
steps:
- if: 'is_release == "yes"'
then:
- for: key
in: keys(dockerfiles)
do:
- |
keycomponents = split(key, ".")
suffix = ""
if len(keycomponents) > 1 {
suffix = "-" + keycomponents[len(keycomponents)-1]
}
- $: "sudo docker push ={DOCKERHUB_ORGANIZATION}/={project}:v={version_major}={suffix}"
- $: "sudo docker push ={DOCKERHUB_ORGANIZATION}/={project}:v={version_major}.={version_minor}={suffix}"
- $: "sudo docker push ={DOCKERHUB_ORGANIZATION}/={project}:v={version_major}.={version_minor}.={version_patch}={suffix}"
- if: "latest"
then:
- $: "sudo docker push ={DOCKERHUB_ORGANIZATION}/={project}:latest={suffix}"
else:
- print: "Skipping release target (not a release)"
color: red