Skip to content

Commit d255d07

Browse files
author
lijianguo
committed
chore(helmbroker): add drone
1 parent 0076aaa commit d255d07

15 files changed

Lines changed: 316 additions & 58 deletions

File tree

.drone/drone.yml

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
kind: pipeline
2+
type: docker
3+
name: linux-amd64
4+
5+
platform:
6+
arch: amd64
7+
os: linux
8+
9+
steps:
10+
- name: test
11+
image: docker.io/drycc/go-dev
12+
pull: always
13+
privileged: true
14+
commands:
15+
- make test-style upload-coverage
16+
environment:
17+
VERSION: ${DRONE_TAG:-latest}-linux-amd64
18+
DEV_REGISTRY: ${DEV_REGISTRY:-docker.io}
19+
DRYCC_REGISTRY: ${DRYCC_REGISTRY:-docker.io}
20+
CODECOV_TOKEN:
21+
from_secret: codecov_token
22+
when:
23+
event:
24+
- push
25+
- tag
26+
- pull_request
27+
volumes:
28+
- name: image_registries
29+
path: /etc/containers/registries.conf
30+
31+
- name: publish
32+
image: docker.io/drycc/go-dev
33+
pull: always
34+
privileged: true
35+
commands:
36+
- echo $DOCKER_PASSWORD | docker login $DRYCC_REGISTRY --username $DOCKER_USERNAME --password-stdin
37+
- make docker-build docker-immutable-push
38+
environment:
39+
VERSION: ${DRONE_TAG:-latest}-linux-amd64
40+
DEV_REGISTRY:
41+
from_secret: dev_registry
42+
DRYCC_REGISTRY:
43+
from_secret: drycc_registry
44+
DOCKER_USERNAME:
45+
from_secret: docker_username
46+
DOCKER_PASSWORD:
47+
from_secret: docker_password
48+
when:
49+
event:
50+
- push
51+
- tag
52+
volumes:
53+
- name: image_registries
54+
path: /etc/containers/registries.conf
55+
56+
trigger:
57+
event:
58+
- push
59+
- tag
60+
- pull_request
61+
62+
volumes:
63+
- name: image_registries
64+
host:
65+
path: /etc/containers/registries.conf
66+
67+
---
68+
kind: pipeline
69+
type: docker
70+
name: linux-arm64
71+
72+
platform:
73+
arch: arm64
74+
os: linux
75+
76+
steps:
77+
- name: publish
78+
image: docker.io/drycc/go-dev
79+
pull: always
80+
privileged: true
81+
commands:
82+
- echo $DOCKER_PASSWORD | docker login $DRYCC_REGISTRY --username $DOCKER_USERNAME --password-stdin
83+
- make docker-build docker-immutable-push
84+
environment:
85+
VERSION: ${DRONE_TAG:-latest}-linux-arm64
86+
DEV_REGISTRY:
87+
from_secret: dev_registry
88+
DRYCC_REGISTRY:
89+
from_secret: drycc_registry
90+
DOCKER_USERNAME:
91+
from_secret: docker_username
92+
DOCKER_PASSWORD:
93+
from_secret: docker_password
94+
volumes:
95+
- name: image_registries
96+
path: /etc/containers/registries.conf
97+
98+
trigger:
99+
event:
100+
- push
101+
- tag
102+
103+
volumes:
104+
- name: image_registries
105+
host:
106+
path: /etc/containers/registries.conf
107+
108+
---
109+
kind: pipeline
110+
type: docker
111+
name: manifest
112+
113+
steps:
114+
- name: generate manifest
115+
image: docker.io/library/alpine
116+
pull: always
117+
commands:
118+
- sed -i "s/docker.io/$${DRYCC_REGISTRY}/g" .drone/manifest.tmpl
119+
environment:
120+
DRYCC_REGISTRY:
121+
from_secret: drycc_registry
122+
123+
- name: publish
124+
image: plugins/manifest
125+
settings:
126+
spec: .drone/manifest.tmpl
127+
username:
128+
from_secret: docker_username
129+
password:
130+
from_secret: docker_password
131+
environment:
132+
DEV_REGISTRY:
133+
from_secret: dev_registry
134+
DRYCC_REGISTRY:
135+
from_secret: drycc_registry
136+
137+
trigger:
138+
event:
139+
- push
140+
- tag
141+
142+
depends_on:
143+
- linux-amd64
144+
- linux-arm64
145+
146+
---
147+
kind: pipeline
148+
type: docker
149+
name: chart
150+
151+
steps:
152+
- name: generate chart
153+
image: docker.io/drycc/python-dev
154+
commands:
155+
- IMAGE_TAG=$([ ! -z $DRONE_TAG ] && echo \"${DRONE_TAG:1}\" || echo \"canary\")
156+
- sed -i "s/image_tag:\ \"canary\"/image_tag:\ $IMAGE_TAG/g" charts/helmbroker/values.yaml
157+
- helm package charts/helmbroker --version ${DRONE_TAG:-v1.0.0}
158+
- curl -u $CHARTMUSEUM_USERNAME:$CHARTMUSEUM_PASSWORD -F chart=@helmbroker-${DRONE_TAG:-v1.0.0}.tgz "$CHARTMUSEUM_API/api/$([ -z $DRONE_TAG ] && echo testing || echo stable)/charts"
159+
environment:
160+
CHARTMUSEUM_USERNAME:
161+
from_secret: chartmuseum_username
162+
CHARTMUSEUM_PASSWORD:
163+
from_secret: chartmuseum_password
164+
CHARTMUSEUM_API:
165+
from_secret: chartmuseum_api
166+
167+
trigger:
168+
event:
169+
- push
170+
- tag

.drone/manifest.tmpl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
image: docker.io/drycc/helmbroker:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}canary{{/if}}
2+
{{#if build.tags}}
3+
tags:
4+
{{#each build.tags}}
5+
- {{this}}
6+
{{/each}}
7+
{{/if}}
8+
manifests:
9+
-
10+
image: docker.io/drycc/helmbroker:{{#if build.tag}}{{build.tag}}-{{else}}latest-{{/if}}linux-amd64
11+
platform:
12+
architecture: amd64
13+
os: linux
14+
-
15+
image: docker.io/drycc/helmbroker:{{#if build.tag}}{{build.tag}}-{{else}}latest-{{/if}}linux-arm64
16+
platform:
17+
architecture: arm64
18+
os: linux

charts/helmbroker/templates/helmbroker-ingress.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ metadata:
1414
{{- end }}
1515
spec:
1616
rules:
17-
- host: drycc.{{ .Values.platform_domain }}
17+
- host: drycc-helmbroker.{{ .Values.platform_domain }}
1818
http:
1919
paths:
2020
- pathType: Prefix
@@ -32,5 +32,5 @@ spec:
3232
tls:
3333
- secretName: drycc-helmbroker-certificate-auto
3434
hosts:
35-
- drycc.{{ .Values.platform_domain }}
35+
- drycc-helmbroker.{{ .Values.platform_domain }}
3636
{{- end }}

charts/helmbroker/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ingress_class: ""
2626
cluster_domain: "cluster.local"
2727
# The public resolvable hostname to build your cluster with.
2828
#
29-
# This will be the hostname that is used to build endpoints such as "drycc.$HOSTNAME"
29+
# This will be the hostname that is used to build endpoints such as "drycc-helmbroker.$HOSTNAME"
3030
platform_domain: ""
3131
# Whether cert_manager is enabled to automatically generate helmbroker certificates
3232
cert_manager_enabled: "true"

rootfs/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ RUN apk add --update --virtual .build-deps \
3131
&& /app/bin/install
3232

3333
CMD ["/app/bin/boot"]
34-
EXPOSE 8000
34+
EXPOSE 5000

rootfs/Dockerfile.test

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM docker.io/library/python:3.9-alpine
2+
3+
COPY requirements.txt /app/requirements.txt
4+
5+
ENV PATH="/app/.venv/bin:${PATH}"
6+
7+
COPY . /app
8+
9+
WORKDIR /app
10+
11+
RUN apk add --update --virtual .build-deps \
12+
musl-dev \
13+
openssl-dev \
14+
&& python3 -m venv /app/.venv \
15+
&& pip3 install --disable-pip-version-check --no-cache-dir -r /app/requirements.txt \
16+
&& pip3 install --disable-pip-version-check --no-cache-dir -r /app/dev_requirements.txt \
17+
&& runDeps="$( \
18+
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
19+
| tr ',' '\n' \
20+
| sort -u \
21+
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
22+
)" \
23+
&& apk add --update --virtual .helmbroker-rundeps \
24+
$runDeps \
25+
ca-certificates \
26+
su-exec \
27+
bash \
28+
shadow \
29+
curl \
30+
&& apk del .build-deps \
31+
&& chmod +x /app/bin/* \
32+
&& /app/bin/install
33+
COPY . /app
34+
35+
CMD ["/app/bin/boot"]
36+
EXPOSE 5000

rootfs/bin/install

100644100755
File mode changed.

rootfs/bin/test-style

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
#
3+
# This script is designed to be run inside the container
4+
#
5+
6+
# fail hard and fast even on pipelines
7+
set -eou pipefail
8+
9+
flake8 --show-source

rootfs/dev_requirements.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# test module
2+
# test
3+
# Run "make test-unit" for the % of code exercised during tests
4+
coverage==5.3
5+
6+
# Run "make test-style" to check python syntax and style
7+
flake8==3.8.3
8+
9+
# code coverage report at https://codecov.io/github/drycc/controller
10+
codecov==2.1.9
11+
12+
# mock out python-requests, mostly k8s
13+
requests-mock==1.8.0
14+
15+
# tail a log and pipe into tbgrep to find all tracebacks
16+
tbgrep==0.3.0

rootfs/helmbroker/broker.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import os
22
import shutil
3+
from typing import Union, List, Optional
34

45
from openbrokerapi.errors import ErrInstanceAlreadyExists, ErrAsyncRequired, \
56
ErrBindingAlreadyExists, ErrBadRequest, ErrInstanceDoesNotExist
6-
from openbrokerapi.service_broker import *
7+
from openbrokerapi.service_broker import ServiceBroker, Service, \
8+
ProvisionDetails, ProvisionedServiceSpec, ProvisionState, GetBindingSpec, \
9+
BindDetails, Binding, BindState, UnbindDetails, UnbindSpec, \
10+
UpdateDetails, UpdateServiceSpec, DeprovisionDetails, \
11+
DeprovisionServiceSpec, LastOperation
712

8-
from .meta import load_instance_meta, load_binding_meta, dump_binding_meta
13+
from .meta import load_instance_meta, load_binding_meta
914
from .utils import get_instance_path, get_chart_path, get_plan_path, \
1015
get_addon_path, get_addon_name, get_addon_updateable, get_addon_bindable
1116
from .tasks import provision, bind, deprovision, update
@@ -27,12 +32,12 @@ def provision(self,
2732
**kwargs) -> ProvisionedServiceSpec:
2833
instance_path = get_instance_path(instance_id)
2934
if os.path.exists(instance_path):
30-
raise ErrInstanceAlreadyExists("Instance %s already exists" % instance_id)
35+
raise ErrInstanceAlreadyExists("Instance %s already exists" % instance_id) # noqa
3136
if not async_allowed:
3237
raise ErrAsyncRequired()
3338
os.makedirs(instance_path, exist_ok=True)
34-
chart_path, plan_path =get_chart_path(instance_id), get_plan_path(instance_id)
35-
addon_chart_path, addon_plan_path = get_addon_path(details.service_id, details.plan_id)
39+
chart_path, plan_path = get_chart_path(instance_id), get_plan_path(instance_id) # noqa
40+
addon_chart_path, addon_plan_path = get_addon_path(details.service_id, details.plan_id) # noqa
3641
shutil.copy(addon_chart_path, chart_path)
3742
shutil.copy(addon_plan_path, plan_path)
3843
provision.delay(instance_id, details)
@@ -61,15 +66,15 @@ def bind(self,
6166
instance_meta = load_instance_meta(instance_id)
6267
if not (instance_meta and
6368
instance_meta['last_operation']['state'] == 'Ready'):
64-
raise ErrBadRequest(msg="This instance %s is not ready" % instance_id)
69+
raise ErrBadRequest(msg="This instance %s is not ready" % instance_id) # noqa
6570
if not async_allowed:
6671
raise ErrAsyncRequired()
6772
instance_path = get_instance_path(instance_id)
6873
if os.path.exists(f'{instance_path}/bind.yaml'):
6974
raise ErrBindingAlreadyExists()
70-
chart_path, plan_path = get_chart_path(instance_id), get_plan_path(instance_id)
75+
chart_path, plan_path = get_chart_path(instance_id), get_plan_path(instance_id) # noqa
7176
addon_name = get_addon_name(details.service_id)
72-
shutil.copy(f'{plan_path}/bind.yaml', f'{chart_path}/{addon_name}/templates')
77+
shutil.copy(f'{plan_path}/bind.yaml', f'{chart_path}/{addon_name}/templates') # noqa
7378
bind.delay(instance_id, binding_id, details, async_allowed, **kwargs)
7479
return Binding(state=BindState.IS_ASYNC)
7580

@@ -96,13 +101,13 @@ def update(self,
96101
raise ErrBadRequest("Instance %s does not exist" % instance_id)
97102
is_plan_updateable = get_addon_updateable(instance_id)
98103
if not is_plan_updateable:
99-
raise ErrBadRequest("Instance %s does not updateable" % instance_id)
104+
raise ErrBadRequest("Instance %s does not updateable" % instance_id) # noqa
100105
if not async_allowed:
101106
raise ErrAsyncRequired()
102107
plan_path = get_plan_path(instance_id)
103108
# delete the pre plan
104109
shutil.rmtree(plan_path)
105-
_, addon_plan_path = get_addon_path(details.service_id, details.plan_id)
110+
_, addon_plan_path = get_addon_path(details.service_id, details.plan_id) # noqa
106111
# add the new plan
107112
shutil.copy(addon_plan_path, plan_path)
108113
update.delay(instance_id, details)
@@ -115,7 +120,7 @@ def deprovision(self,
115120
**kwargs) -> DeprovisionServiceSpec:
116121
instance_path = get_instance_path(instance_id)
117122
if not os.path.exists(instance_path):
118-
raise ErrInstanceDoesNotExist("Instance %s not exists" % instance_id)
123+
raise ErrInstanceDoesNotExist("Instance %s not exists" % instance_id) # noqa
119124
if not async_allowed:
120125
raise ErrAsyncRequired()
121126

0 commit comments

Comments
 (0)