Skip to content

Commit b02e548

Browse files
geroplroboquat
authored andcommitted
[werft] Configure payment with installer
1 parent 29eb960 commit b02e548

10 files changed

+285
-5
lines changed

.werft/jobs/build/deploy-to-preview-environment.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,10 @@ async function deployToDevWithInstaller(werft: Werft, jobConfig: JobConfig, depl
317317
workspaceFeatureFlags: workspaceFeatureFlags,
318318
gitpodDaemonsetPorts: { registryFacade: registryNodePortMeta, wsDaemon: wsdaemonPortMeta },
319319
smithToken: token,
320+
withPayment: deploymentConfig.withPayment,
320321
})
321322
try {
323+
werft.log(phases.DEPLOY, "deploying using installer")
322324
installer.init(installerSlices.INSTALLER_INIT)
323325
installer.addPreviewConfiguration(installerSlices.PREVIEW_CONFIG)
324326
installer.validateConfiguration(installerSlices.VALIDATE_CONFIG)

.werft/jobs/build/installer/installer.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import * as fs from 'fs';
12
import { exec } from "../../../util/shell";
23
import { Werft } from "../../../util/werft";
34
import { getNodePoolIndex } from "../deploy-to-preview-environment";
5+
import { renderPayment } from "../payment/render";
46

57
const BLOCK_NEW_USER_CONFIG_PATH = './blockNewUsers';
68
const WORKSPACE_SIZE_CONFIG_PATH = './workspaceSizing';
@@ -34,6 +36,7 @@ export type InstallerOptions = {
3436
workspaceFeatureFlags: string[]
3537
gitpodDaemonsetPorts: GitpodDaemonsetPorts
3638
smithToken: string
39+
withPayment: boolean
3740
}
3841

3942
export class Installer {
@@ -69,6 +72,12 @@ export class Installer {
6972
} else {
7073
this.dontIncludeAnalytics(slice)
7174
}
75+
76+
if (this.options.withPayment) {
77+
// let installer know that there is a chargbee config
78+
exec(`yq w -i ${this.options.installerConfigPath} experimental.webapp.server.chargebeeSecret chargebee-config`, { slice: slice });
79+
}
80+
7281
} catch (err) {
7382
throw new Error(err)
7483
}
@@ -176,6 +185,7 @@ export class Installer {
176185

177186
this.configureLicense(slice)
178187
this.configureWorkspaceFeatureFlags(slice)
188+
this.configurePayment(slice)
179189
this.process(slice)
180190

181191
this.options.werft.done(slice)
@@ -200,7 +210,26 @@ export class Installer {
200210
})
201211
// post-process.sh looks for /tmp/defaultFeatureFlags
202212
// each "flag" string gets added to the configmap
213+
// also watches aout for /tmp/payment
214+
}
215+
}
216+
217+
private configurePayment(slice: string): void {
218+
// 1. Read versions from docker image
219+
this.options.werft.log(slice, "configuring withPayment...");
220+
try {
221+
exec(`docker run --rm eu.gcr.io/gitpod-core-dev/build/versions:${this.options.version} cat /versions.yaml > versions.yaml`);
222+
} catch (err) {
223+
this.options.werft.fail(slice, err);
203224
}
225+
const serviceWaiterVersion = exec("yq r ./versions.yaml 'components.serviceWaiter.version'").stdout.toString().trim();
226+
const paymentEndpointVersion = exec("yq r ./versions.yaml 'components.paymentEndpoint.version'").stdout.toString().trim();
227+
228+
// 2. render chargebee-config and payment-endpoint
229+
const paymentYamls = renderPayment(this.options.deploymentNamespace, paymentEndpointVersion, serviceWaiterVersion);
230+
fs.writeFileSync("/tmp/payment", paymentYamls);
231+
232+
this.options.werft.log(slice, "done configuring withPayment.");
204233
}
205234

206235
private process(slice: string): void {

.werft/jobs/build/installer/post-process.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ echo "Use node pool index $NODE_POOL_INDEX"
2828
LICENSE=$(cat /tmp/license)
2929
# default, no, we do not add feature flags, file is empty
3030
DEFAULT_FEATURE_FLAGS=$(cat /tmp/defaultFeatureFlags)
31-
32-
31+
# if payment is configured: Append the YAML objects
32+
if [[ -f "/tmp/payment" ]] ; then
33+
echo "found /tmp/payment, appending to k8s.yaml now"
34+
# do not make any assumptions about new lines
35+
printf \\n'---'\\n >> k8s.yaml
36+
cat "/tmp/payment" >> k8s.yaml
37+
fi
3338

3439
# count YAML like lines in the k8s manifest file
3540
MATCHES="$(grep -c -- --- k8s.yaml)"
@@ -380,9 +385,6 @@ while [ "$documentIndex" -le "$DOCS" ]; do
380385
# yq m -x -i -d "$documentIndex" k8s.yaml /tmp/"$NAME"-"$KIND".yaml
381386
# fi
382387

383-
# TODO: integrate with chargebees
384-
# won't fix now, use Helm
385-
386388
documentIndex=$((documentIndex + 1))
387389
done
388390

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v1
2+
data:
3+
providerOptions: eyJzaXRlIjogImdpdHBvZC10ZXN0IiwiYXBpX2tleSI6ICJ0ZXN0X1hheTY0eVJYY2RHR2N1NG1haVhlSTNsY3VZNXlzTmVIWlFwIn0=
4+
kind: Secret
5+
metadata:
6+
name: chargebee-config
7+
namespace: ${NAMESPACE}
8+
type: Opaque
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
labels:
5+
app: gitpod
6+
component: payment-endpoint
7+
name: payment-endpoint
8+
namespace: ${NAMESPACE}
9+
spec:
10+
replicas: 1
11+
selector:
12+
matchLabels:
13+
app: gitpod
14+
component: payment-endpoint
15+
strategy:
16+
rollingUpdate:
17+
maxSurge: 1
18+
maxUnavailable: 0
19+
type: RollingUpdate
20+
template:
21+
metadata:
22+
labels:
23+
app: gitpod
24+
component: payment-endpoint
25+
name: payment-endpoint
26+
spec:
27+
affinity:
28+
nodeAffinity:
29+
requiredDuringSchedulingIgnoredDuringExecution:
30+
nodeSelectorTerms:
31+
- matchExpressions:
32+
- key: gitpod.io/workload_meta
33+
operator: Exists
34+
containers:
35+
- env:
36+
- name: KUBE_NAMESPACE
37+
valueFrom:
38+
fieldRef:
39+
apiVersion: v1
40+
fieldPath: metadata.namespace
41+
- name: GITPOD_REGION
42+
value: local
43+
- name: GITPOD_INSTALLATION_SHORTNAME
44+
value: ""
45+
- name: DB_HOST
46+
value: mysql
47+
- name: DB_PORT
48+
value: "3306"
49+
- name: DB_PASSWORD
50+
valueFrom:
51+
secretKeyRef:
52+
key: password
53+
name: mysql
54+
- name: DB_USERNAME
55+
valueFrom:
56+
secretKeyRef:
57+
key: username
58+
name: mysql
59+
- name: DB_ENCRYPTION_KEYS
60+
valueFrom:
61+
secretKeyRef:
62+
key: encryptionKeys
63+
name: mysql
64+
- name: DB_DELETED_ENTRIES_GC_ENABLED
65+
value: "false"
66+
- name: CHARGEBEE_WEBHOOK
67+
value: '{"id":"whv2_Hr55137RIX0bgV1e96","password":"0\"cR4M,;nV=$m9izAHEah","user":"chargebee"}'
68+
- name: GITPOD_GITHUB_APP_ENABLED
69+
value: "false"
70+
# - name: GITPOD_GITHUB_APP_ID
71+
# value: "23613"
72+
# - name: GITPOD_GITHUB_APP_WEBHOOK_SECRET
73+
# value: ea3t2QvbJqUFhGqrAJxCQQJ4mmABru
74+
# - name: GITPOD_GITHUB_APP_AUTH_PROVIDER_ID
75+
# value: Public-GitHub
76+
# - name: GITPOD_GITHUB_APP_CERT_PATH
77+
# value: /github-app-cert/cert
78+
# - name: GITPOD_GITHUB_APP_MKT_NAME
79+
# value: gitpod-staging
80+
- name: JAEGER_ENDPOINT
81+
value: http://otel-collector.cluster-monitoring.svc:14268/api/traces
82+
- name: JAEGER_SAMPLER_PARAM
83+
value: "5.0"
84+
- name: JAEGER_SAMPLER_TYPE
85+
value: ratelimiting
86+
- name: LOG_LEVEL
87+
value: info
88+
image: eu.gcr.io/gitpod-core-dev/build/payment-endpoint:${PAYMENT_ENDPOINT_VERSION}
89+
name: main
90+
ports:
91+
- containerPort: 3002
92+
name: http
93+
resources:
94+
requests:
95+
cpu: 100m
96+
memory: 512Mi
97+
securityContext:
98+
privileged: false
99+
volumeMounts:
100+
# - mountPath: /github-app-cert
101+
# name: github-app-cert-secret
102+
# readOnly: true
103+
- mountPath: /chargebee
104+
name: chargebee-config
105+
readOnly: true
106+
dnsPolicy: ClusterFirst
107+
initContainers:
108+
- args:
109+
- -v
110+
- database
111+
env:
112+
- name: DB_ENCRYPTION_KEYS
113+
valueFrom:
114+
secretKeyRef:
115+
key: encryptionKeys
116+
name: mysql
117+
- name: DB_HOST
118+
value: mysql
119+
- name: DB_PASSWORD
120+
valueFrom:
121+
secretKeyRef:
122+
key: password
123+
name: mysql
124+
- name: DB_PORT
125+
value: "3306"
126+
- name: DB_USERNAME
127+
valueFrom:
128+
secretKeyRef:
129+
key: username
130+
name: mysql
131+
image: eu.gcr.io/gitpod-core-dev/build/service-waiter:${SERVICE_WAITER_VERSION}
132+
name: database-waiter
133+
resources: {}
134+
securityContext:
135+
privileged: false
136+
runAsUser: 31001
137+
restartPolicy: Always
138+
securityContext:
139+
runAsUser: 31006
140+
serviceAccountName: payment-endpoint
141+
terminationGracePeriodSeconds: 30
142+
volumes:
143+
# - name: github-app-cert-secret
144+
# secret:
145+
# secretName: github-app-cert
146+
- name: chargebee-config
147+
secret:
148+
secretName: chargebee-config
149+
150+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: NetworkPolicy
3+
metadata:
4+
name: payment-endpoint-deny-all-allow-explicit
5+
namespace: ${NAMESPACE}
6+
labels:
7+
app: gitpod
8+
component: payment-endpoint
9+
spec:
10+
podSelector:
11+
matchLabels:
12+
app: gitpod
13+
component: payment-endpoint
14+
policyTypes:
15+
- Ingress
16+
ingress:
17+
- ports:
18+
- protocol: TCP
19+
port: 3002
20+
from:
21+
# Allow ingress on port 3002 from component:
22+
- podSelector:
23+
matchLabels:
24+
app: gitpod
25+
component: proxy
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
kind: RoleBinding
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
metadata:
4+
name: payment-endpoint
5+
namespace: ${NAMESPACE}
6+
labels:
7+
app: gitpod
8+
component: payment-endpoint
9+
subjects:
10+
- kind: ServiceAccount
11+
name: payment-endpoint
12+
roleRef:
13+
kind: ClusterRole
14+
name: ${NAMESPACE}-ns-psp:unprivileged
15+
apiGroup: rbac.authorization.k8s.io
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: payment-endpoint
5+
namespace: ${NAMESPACE}
6+
labels:
7+
app: gitpod
8+
component: payment-endpoint
9+
automountServiceAccountToken: false
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
labels:
5+
app: gitpod
6+
component: payment-endpoint
7+
name: payment-endpoint
8+
namespace: ${NAMESPACE}
9+
spec:
10+
ports:
11+
- name: http
12+
port: 3002
13+
protocol: TCP
14+
targetPort: 3002
15+
selector:
16+
app: gitpod
17+
component: payment-endpoint
18+
type: ClusterIP

.werft/jobs/build/payment/render.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const fs = require("fs");
2+
import * as path from "path";
3+
4+
export function renderPayment(
5+
namespace: string,
6+
paymentEndpointVersion: String,
7+
serviceAwaiterVersion: string,
8+
): string {
9+
const output: string[] = [];
10+
for (const file of fs.readdirSync(__dirname)) {
11+
if (!file.endsWith(".yaml")) {
12+
continue;
13+
}
14+
let content = fs.readFileSync(path.join(__dirname, file), { encoding: "utf-8" });
15+
content = content
16+
.replaceAll("${NAMESPACE}", namespace)
17+
.replaceAll("${PAYMENT_ENDPOINT_VERSION}", paymentEndpointVersion)
18+
.replaceAll("${SERVICE_WAITER_VERSION}", serviceAwaiterVersion);
19+
output.push(content);
20+
}
21+
return output.join("\n---\n");
22+
}

0 commit comments

Comments
 (0)