Skip to content

Commit 9ae15b1

Browse files
authored
chore: Jmeter build into action (#113)
* build: add jmeter build to workflow * build: move the base image to artifact repo * chore: a simple script for moving the images from old gcr registry to new artifact repo * fix: move the auth file to secret * fix: move the engine agent config into configmap * chore: update some comments to explain the logic * fix: deal with nil config * fix: running image should have ca
1 parent c6ecf23 commit 9ae15b1

File tree

13 files changed

+121
-56
lines changed

13 files changed

+121
-56
lines changed

.github/workflows/build-publish.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ jobs:
102102
run: |-
103103
cd shibuya && make controller_image component=controller
104104
105+
- name: build jmeter agent
106+
env:
107+
tag_name: ${{ needs.release-please.outputs.tag_name }}
108+
# we specify the jmeter version we are using in the component name
109+
# So we can cleary know which jmeter version we are using
110+
run: |-
111+
cd shibuya && make jmeter_agent_image component=jmeter-3.3
105112
106113
107114

makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ shibuya: local_api local_controller
5252

5353
.PHONY: jmeter
5454
jmeter: shibuya/engines/jmeter
55-
cp shibuya/config_tmpl.json shibuya/config.json
5655
cd shibuya && sh build.sh jmeter
57-
docker build -t shibuya:jmeter -f shibuya/docker-local/Dockerfile.engines.jmeter shibuya
56+
docker build -t shibuya:jmeter -f shibuya/Dockerfile.engines.jmeter shibuya
5857
kind load docker-image shibuya:jmeter --name shibuya
5958

6059
.PHONY: expose

shibuya/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
FROM ubuntu:18.04
22

3+
RUN apt-get update && apt-get install -y ca-certificates
34
ARG binary_name=shibuya
45
ADD ./build/${binary_name} /usr/local/bin/${binary_name}
56

shibuya/Dockerfile.engines.jmeter

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,18 @@
11
ARG jmeter_ver=3.3
22

3-
FROM gcr.io/shibuya-214807/alpine:3.10.2 AS jmeter
3+
FROM asia-northeast1-docker.pkg.dev/shibuya-214807/shibuya/alpine:3.10.2 AS jmeter
44
ARG jmeter_ver
55
ENV JMETER_VERSION=$jmeter_ver
66
RUN wget archive.apache.org/dist/jmeter/binaries/apache-jmeter-${JMETER_VERSION}.zip
77
RUN unzip -qq apache-jmeter-${JMETER_VERSION}
88

9-
FROM gcr.io/shibuya-214807/golang:1.13.6-stretch AS shibuya-agent
10-
WORKDIR /go/src/shibuya
11-
ENV GO111MODULE on
12-
ADD go.mod .
13-
ADD go.sum .
14-
RUN go mod download
15-
16-
COPY . /go/src/shibuya
17-
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o /go/bin/shibuya-agent /go/src/shibuya/engines/jmeter
18-
19-
FROM gcr.io/shibuya-214807/openjdk:8u212-jdk
9+
FROM asia-northeast1-docker.pkg.dev/shibuya-214807/shibuya/openjdk:8u212-jdk
2010
ARG jmeter_ver
2111
ENV JMETER_VERSION=$jmeter_ver
2212
RUN mkdir /test-conf /test-result
2313
COPY --from=jmeter /apache-jmeter-${JMETER_VERSION} /apache-jmeter-${JMETER_VERSION}
24-
COPY --from=shibuya-agent /go/bin/shibuya-agent /usr/local/bin/shibuya-agent
25-
COPY config.json config.json
14+
ADD build/shibuya-agent /usr/local/bin/shibuya-agent
2615
ADD engines/jmeter/shibuya.properties /test-conf/shibuya.properties
2716
ADD engines/jmeter/jmeter.sh /apache-jmeter-${JMETER_VERSION}/bin/jmeter
28-
RUN mkdir /auth
29-
ADD ./shibuya-gcp.json /auth/shibuya-gcp.json
30-
ENV GOOGLE_APPLICATION_CREDENTIALS /auth/shibuya-gcp.json
31-
CMD ["shibuya-agent"]
17+
18+
CMD ["shibuya-agent"]

shibuya/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,14 @@ controller_image: controller_build
3131
.PHONY: helm_charts
3232
helm_charts:
3333
helm package install/shibuya
34+
35+
.PHONY: jmeter_agent
36+
jmeter_agent:
37+
sh build.sh jmeter
38+
39+
.PHONY: jmeter_agent_image
40+
jmeter_agent_image: jmeter_agent
41+
docker build -t $(img) -f Dockerfile.engines.jmeter .
42+
docker push $(img)
43+
44+

shibuya/config/init.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ import (
1313
apiv1 "k8s.io/api/core/v1"
1414
)
1515

16+
const (
17+
ConfigFileName = "config.json"
18+
)
19+
20+
var (
21+
ConfigFilePath = path.Join("/", ConfigFileName)
22+
)
23+
1624
type LdapConfig struct {
1725
BaseDN string `json:"base_dn"`
1826
SystemUser string `json:"system_user"`
@@ -92,6 +100,12 @@ type ObjectStorage struct {
92100
Password string `json:"password"`
93101
Bucket string `json:"bucket"`
94102
RequireProxy bool `json:"require_proxy"`
103+
// This is the secret name created in the cluster for authenticating with object storage
104+
SecretName string `json:"secret_name"`
105+
// This is the mounted keys file name. e.g. /auth/shibuya-gcp.json
106+
AuthFileName string `json:"auth_file_name"`
107+
// This is the configuration file
108+
ConfigMapName string `json:"config_map_name"`
95109
}
96110

97111
type LogFormat struct {
@@ -178,15 +192,17 @@ func applyJsonLogging() {
178192
func setupLogging() {
179193
log.SetOutput(os.Stdout)
180194
log.SetReportCaller(true)
181-
if SC.LogFormat.Json {
182-
applyJsonLogging()
195+
if SC.LogFormat != nil {
196+
if SC.LogFormat.Json {
197+
applyJsonLogging()
198+
}
183199
}
184200
}
185201

186202
func loadConfig() *ShibuyaConfig {
187203
sc := new(ShibuyaConfig)
188204
sc.IngressConfig = &defaultIngressConfig
189-
f, err := os.Open("/config.json")
205+
f, err := os.Open(ConfigFilePath)
190206
if err != nil {
191207
log.Fatal("Cannot find config file")
192208
}
@@ -199,8 +215,9 @@ func loadConfig() *ShibuyaConfig {
199215
}
200216
sc.Context = loadContext()
201217
sc.DevMode = sc.Context == "local"
202-
sc.makeHTTPClients()
203-
218+
if sc.HttpConfig != nil {
219+
sc.makeHTTPClients()
220+
}
204221
// In jmeter agent, we also rely on this module, therefore we need to check whether this is nil or not. As jmeter
205222
// configuration might provide an empty struct here
206223
// TODO: we should not let jmeter code rely on this part

shibuya/docker-local/Dockerfile.engines.jmeter

Lines changed: 0 additions & 21 deletions
This file was deleted.

shibuya/docker-local/README.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

shibuya/install/shibuya/templates/configmap.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ data:
8686
{{- with .Values.runtime.object_storage.url }}
8787
"url": {{ . | quote }},
8888
{{- end }}
89-
"bucket": {{ .Values.runtime.object_storage.bucket | quote }}
89+
"bucket": {{ .Values.runtime.object_storage.bucket | quote }},
90+
"secret_name": {{ .Values.runtime.object_storage.secret_name | quote }},
91+
"auth_file_name": {{ .Values.runtime.object_storage.auth_file_name | quote }},
92+
"config_map_name": {{ .Values.runtime.object_storage.config_map_name | quote }}
9093
},
9194
"log_format": {
9295
"json": false

shibuya/install/shibuya/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,6 @@ runtime:
9797
user: ""
9898
password: ""
9999
bucket: ""
100+
secret_name: ""
101+
auth_file_name: ""
102+
config_map_name: "shibuya-config-local"

shibuya/move_images.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
new_registry=asia-northeast1-docker.pkg.dev/shibuya-214807/shibuya
4+
old_registry=gcr.io/shibuya-214807
5+
6+
component=$1
7+
old_image=$old_registry/$component
8+
new_image=$new_registry/$component
9+
docker pull $old_image
10+
docker tag $old_image $new_image
11+
docker push $new_image

shibuya/object_storage/factory.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ func factoryConfig() PlatformConfig {
4747
}
4848
}
4949

50+
func IsProviderGCP() bool {
51+
return config.SC.ObjectStorage.Provider == gcpStorageProvider
52+
}
53+
5054
var Client PlatformConfig
5155

5256
func init() {

shibuya/scheduler/k8s.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/rakutentech/shibuya/shibuya/config"
1515
model "github.com/rakutentech/shibuya/shibuya/model"
16+
"github.com/rakutentech/shibuya/shibuya/object_storage"
1617
smodel "github.com/rakutentech/shibuya/shibuya/scheduler/model"
1718
log "github.com/sirupsen/logrus"
1819
appsv1 "k8s.io/api/apps/v1"
@@ -150,6 +151,54 @@ func (kcm *K8sClientManager) makeHostAliases() []apiv1.HostAlias {
150151
func (kcm *K8sClientManager) generatePlanDeployment(planName string, replicas int, labels map[string]string, containerConfig *config.ExecutorContainer,
151152
affinity *apiv1.Affinity, tolerations []apiv1.Toleration) appsv1.StatefulSet {
152153
t := true
154+
volumes := []apiv1.Volume{}
155+
volumeMounts := []apiv1.VolumeMount{}
156+
envvars := []apiv1.EnvVar{}
157+
if object_storage.IsProviderGCP() {
158+
volumeName := "shibuya-gcp-auth"
159+
secretName := config.SC.ObjectStorage.SecretName
160+
authFileName := config.SC.ObjectStorage.AuthFileName
161+
mountPath := fmt.Sprintf("/auth/%s", authFileName)
162+
v := apiv1.Volume{
163+
Name: volumeName,
164+
VolumeSource: apiv1.VolumeSource{
165+
Secret: &apiv1.SecretVolumeSource{
166+
SecretName: secretName,
167+
},
168+
},
169+
}
170+
volumes = append(volumes, v)
171+
vm := apiv1.VolumeMount{
172+
Name: volumeName,
173+
MountPath: mountPath,
174+
SubPath: authFileName,
175+
}
176+
volumeMounts = append(volumeMounts, vm)
177+
envvar := apiv1.EnvVar{
178+
Name: "GOOGLE_APPLICATION_CREDENTIALS",
179+
Value: mountPath,
180+
}
181+
envvars = append(envvars, envvar)
182+
}
183+
cmVolumeName := "shibuya-config"
184+
cmName := config.SC.ObjectStorage.ConfigMapName
185+
cmVolume := apiv1.Volume{
186+
Name: cmVolumeName,
187+
VolumeSource: apiv1.VolumeSource{
188+
ConfigMap: &apiv1.ConfigMapVolumeSource{
189+
LocalObjectReference: apiv1.LocalObjectReference{
190+
Name: cmName,
191+
},
192+
},
193+
},
194+
}
195+
volumes = append(volumes, cmVolume)
196+
cmVolumeMounts := apiv1.VolumeMount{
197+
Name: cmVolumeName,
198+
MountPath: config.ConfigFilePath,
199+
SubPath: config.ConfigFileName,
200+
}
201+
volumeMounts = append(volumeMounts, cmVolumeMounts)
153202
deployment := appsv1.StatefulSet{
154203
ObjectMeta: metav1.ObjectMeta{
155204
Name: planName,
@@ -178,6 +227,7 @@ func (kcm *K8sClientManager) generatePlanDeployment(planName string, replicas in
178227
},
179228
TerminationGracePeriodSeconds: new(int64),
180229
HostAliases: kcm.makeHostAliases(),
230+
Volumes: volumes,
181231
Containers: []apiv1.Container{
182232
{
183233
Name: planName,
@@ -200,6 +250,8 @@ func (kcm *K8sClientManager) generatePlanDeployment(planName string, replicas in
200250
ContainerPort: 8080,
201251
},
202252
},
253+
VolumeMounts: volumeMounts,
254+
Env: envvars,
203255
},
204256
},
205257
},

0 commit comments

Comments
 (0)