Skip to content

Commit cabb44e

Browse files
committed
add first golang
0 parents  commit cabb44e

File tree

8 files changed

+328
-0
lines changed

8 files changed

+328
-0
lines changed

.drone.star

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
def main(ctx):
2+
versions = [
3+
'latest',
4+
]
5+
6+
arches = [
7+
'amd64',
8+
'arm32v7',
9+
'arm64v8',
10+
]
11+
12+
config = {
13+
'version': None,
14+
'arch': None,
15+
'trigger': [],
16+
'repo': ctx.repo.name
17+
}
18+
19+
stages = []
20+
21+
for version in versions:
22+
config['version'] = version
23+
24+
if config['version'] == 'latest':
25+
config['path'] = 'latest'
26+
else:
27+
config['path'] = 'v%s' % config['version']
28+
29+
m = manifest(config)
30+
inner = []
31+
32+
for arch in arches:
33+
config['arch'] = arch
34+
35+
if config['version'] == 'latest':
36+
config['tag'] = arch
37+
else:
38+
config['tag'] = '%s-%s' % (config['version'], arch)
39+
40+
if config['arch'] == 'amd64':
41+
config['platform'] = 'amd64'
42+
43+
if config['arch'] == 'arm64v8':
44+
config['platform'] = 'arm64'
45+
46+
if config['arch'] == 'arm32v7':
47+
config['platform'] = 'arm'
48+
49+
config['internal'] = '%s-%s' % (ctx.build.commit, config['tag'])
50+
51+
d = docker(config)
52+
m['depends_on'].append(d['name'])
53+
54+
inner.append(d)
55+
56+
inner.append(m)
57+
stages.extend(inner)
58+
59+
after = [
60+
notification(config),
61+
]
62+
63+
for s in stages:
64+
for a in after:
65+
a['depends_on'].append(s['name'])
66+
67+
return stages + after
68+
69+
def docker(config):
70+
return {
71+
'kind': 'pipeline',
72+
'type': 'docker',
73+
'name': '%s-%s' % (config['arch'], config['path']),
74+
'platform': {
75+
'os': 'linux',
76+
'arch': config['platform'],
77+
},
78+
'steps': steps(config),
79+
'image_pull_secrets': [
80+
'registries',
81+
],
82+
'depends_on': [],
83+
'trigger': {
84+
'ref': [
85+
'refs/heads/master',
86+
'refs/pull/**',
87+
],
88+
},
89+
}
90+
91+
def manifest(config):
92+
return {
93+
'kind': 'pipeline',
94+
'type': 'docker',
95+
'name': 'manifest-%s' % config['path'],
96+
'platform': {
97+
'os': 'linux',
98+
'arch': 'amd64',
99+
},
100+
'steps': [
101+
{
102+
'name': 'manifest',
103+
'image': 'plugins/manifest',
104+
'settings': {
105+
'username': {
106+
'from_secret': 'public_username',
107+
},
108+
'password': {
109+
'from_secret': 'public_password',
110+
},
111+
'spec': '%s/manifest.tmpl' % config['path'],
112+
'ignore_missing': 'true',
113+
},
114+
},
115+
],
116+
'depends_on': [],
117+
'trigger': {
118+
'ref': [
119+
'refs/heads/master',
120+
'refs/tags/**',
121+
],
122+
},
123+
}
124+
125+
def notification(config):
126+
steps = [{
127+
'name': 'notify',
128+
'image': 'plugins/slack',
129+
'settings': {
130+
'webhook': {
131+
'from_secret': 'private_rocketchat',
132+
},
133+
'channel': 'builds',
134+
},
135+
'when': {
136+
'status': [
137+
'success',
138+
'failure',
139+
],
140+
},
141+
}]
142+
143+
downstream = [{
144+
'name': 'downstream',
145+
'image': 'plugins/downstream',
146+
'settings': {
147+
'token': {
148+
'from_secret': 'drone_token',
149+
},
150+
'server': 'https://drone.owncloud.com',
151+
'repositories': config['trigger'],
152+
},
153+
'when': {
154+
'status': [
155+
'success',
156+
],
157+
},
158+
}]
159+
160+
if config['trigger']:
161+
steps = downstream + steps
162+
163+
return {
164+
'kind': 'pipeline',
165+
'type': 'docker',
166+
'name': 'notification',
167+
'platform': {
168+
'os': 'linux',
169+
'arch': 'amd64',
170+
},
171+
'clone': {
172+
'disable': True,
173+
},
174+
'steps': steps,
175+
'depends_on': [],
176+
'trigger': {
177+
'ref': [
178+
'refs/heads/master',
179+
'refs/tags/**',
180+
],
181+
'status': [
182+
'success',
183+
'failure',
184+
],
185+
},
186+
}
187+
188+
def dryrun(config):
189+
return [{
190+
'name': 'dryrun',
191+
'image': 'plugins/docker',
192+
'settings': {
193+
'dry_run': True,
194+
'tags': config['tag'],
195+
'dockerfile': '%s/Dockerfile.%s' % (config['path'], config['arch']),
196+
'repo': 'owncloudci/%s' % config['repo'],
197+
'context': config['path'],
198+
},
199+
'when': {
200+
'ref': [
201+
'refs/pull/**',
202+
],
203+
},
204+
}]
205+
206+
def publish(config):
207+
return [{
208+
'name': 'publish',
209+
'image': 'plugins/docker',
210+
'settings': {
211+
'username': {
212+
'from_secret': 'public_username',
213+
},
214+
'password': {
215+
'from_secret': 'public_password',
216+
},
217+
'tags': config['tag'],
218+
'dockerfile': '%s/Dockerfile.%s' % (config['path'], config['arch']),
219+
'repo': 'owncloudci/%s' % config['repo'],
220+
'context': config['path'],
221+
'pull_image': False,
222+
},
223+
'when': {
224+
'ref': [
225+
'refs/heads/master',
226+
'refs/tags/**',
227+
],
228+
},
229+
}]
230+
231+
def steps(config):
232+
return dryrun(config) + publish(config)

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 ownCloud GmbH
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is furnished
10+
to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice (including the next
13+
paragraph) shall be included in all copies or substantial portions of the
14+
Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
19+
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
21+
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
IMAGE_NAME ?= owncloudci/golang:latest
2+
3+
BUILD_VERSION ?= latest
4+
BUILD_ARCH ?= amd64
5+
BUILD_DATE ?= $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
6+
7+
VCS_REF ?= $(shell git rev-parse HEAD)
8+
VCS_URL ?= $(shell git remote get-url origin)
9+
10+
DOCKER_CMD ?= docker
11+
12+
.PHONY: build
13+
build:
14+
cd $(BUILD_VERSION) && $(DOCKER_CMD) build -f Dockerfile.$(BUILD_ARCH) --label org.label-schema.version=$(BUILD_VERSION) --label org.label-schema.build-date=$(BUILD_DATE) --label org.label-schema.vcs-url=$(VCS_URL) --label org.label-schema.vcs-ref=$(VCS_REF) -t $(IMAGE_NAME) .

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Go
2+
3+
[![Build Status](https://drone.owncloud.com/api/badges/owncloud-ci/golang/status.svg)](https://drone.owncloud.com/owncloud-ci/golang)
4+
5+
Go image for CI pipelines.
6+
7+
## License
8+
9+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

latest/Dockerfile.amd64

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM --platform=linux/amd64 golang:1.16-alpine@sha256:12d5f94cd4d2840e538e82e26a5dfddf711b30cc98a9f6e01bcf65d7aaf7ccd8
2+
3+
LABEL maintainer="ownCloud GmbH <[email protected]>" \
4+
org.opencontainers.image.title="ownCloud CI Go" \
5+
org.opencontainers.image.vendor="ownCloud GmbH" \
6+
org.opencontainers.image.authors="ownCloud GmbH" \
7+
org.opencontainers.image.description="ownCloud CI Go" \
8+
org.opencontainers.image.documentation="https://github.com/owncloud-ci/golang.git" \
9+
org.opencontainers.image.url="https://github.com/owncloud-ci/golang" \
10+
org.opencontainers.image.source="https://github.com/owncloud-ci/golang"
11+
12+
RUN apk add bash make git curl gcc musl-dev

latest/Dockerfile.arm32v7

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM --platform=linux/arm32/v7 golang:1.16-alpine@sha256:6f7bcdb508aab1815cae87fba19bce654dc86162c59b7b5b5298896e832115f0
2+
3+
LABEL maintainer="ownCloud GmbH <[email protected]>" \
4+
org.opencontainers.image.title="ownCloud CI Go" \
5+
org.opencontainers.image.vendor="ownCloud GmbH" \
6+
org.opencontainers.image.authors="ownCloud GmbH" \
7+
org.opencontainers.image.description="ownCloud CI Go" \
8+
org.opencontainers.image.documentation="https://github.com/owncloud-ci/golang.git" \
9+
org.opencontainers.image.url="https://github.com/owncloud-ci/golang" \
10+
org.opencontainers.image.source="https://github.com/owncloud-ci/golang"
11+
12+
RUN apk add bash make git curl gcc musl-dev

latest/Dockerfile.arm64v8

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM --platform=linux/arm64/v8 golang:1.16-alpine@sha256:d139df25369b0041837d156863d2502187a4e7d93c7af4f25202b10a099abd02
2+
3+
LABEL maintainer="ownCloud GmbH <[email protected]>" \
4+
org.opencontainers.image.title="ownCloud CI Go" \
5+
org.opencontainers.image.vendor="ownCloud GmbH" \
6+
org.opencontainers.image.authors="ownCloud GmbH" \
7+
org.opencontainers.image.description="ownCloud CI Go" \
8+
org.opencontainers.image.documentation="https://github.com/owncloud-ci/golang.git" \
9+
org.opencontainers.image.url="https://github.com/owncloud-ci/golang" \
10+
org.opencontainers.image.source="https://github.com/owncloud-ci/golang"
11+
12+
RUN apk add bash make git curl gcc musl-dev

latest/manifest.tmpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
image: owncloudci/golang:latest
2+
manifests:
3+
- image: owncloudci/golang:amd64
4+
platform:
5+
architecture: amd64
6+
os: linux
7+
- image: owncloudci/golang:arm64v8
8+
platform:
9+
architecture: arm64
10+
variant: v8
11+
os: linux
12+
- image: owncloudci/golang:arm32v7
13+
platform:
14+
architecture: arm
15+
variant: v7
16+
os: linux

0 commit comments

Comments
 (0)