Skip to content

Commit c6fec61

Browse files
meysholdtroboquat
authored andcommitted
use docker hub
1 parent 062911e commit c6fec61

File tree

2 files changed

+56
-32
lines changed

2 files changed

+56
-32
lines changed

.werft/build.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ pod:
4545
- name: harvester-vm-ssh-keys
4646
secret:
4747
secretName: harvester-vm-ssh-keys
48+
- name: harvester-k3s-dockerhub-pull-account
49+
secret:
50+
secretName: harvester-k3s-dockerhub-pull-account
4851
- name: fluent-bit-external
4952
secret:
5053
secretName: fluent-bit-external
@@ -101,6 +104,8 @@ pod:
101104
mountPath: /mnt/secrets/harvester-kubeconfig
102105
- name: harvester-vm-ssh-keys
103106
mountPath: /mnt/secrets/harvester-vm-ssh-keys
107+
- name: harvester-k3s-dockerhub-pull-account
108+
mountPath: /mnt/secrets/harvester-k3s-dockerhub-pull-account
104109
- name: fluent-bit-external
105110
mountPath: /mnt/fluent-bit-external
106111
# - name: deploy-key

.werft/vm/manifests.ts

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1+
import * as fs from "fs";
2+
13
type NamespaceManifestOptions = {
2-
namespace: string
3-
}
4+
namespace: string;
5+
};
46

57
export function NamespaceManifest({ namespace }: NamespaceManifestOptions) {
6-
return `
8+
return `
79
apiVersion: v1
810
kind: Namespace
911
metadata:
1012
name: ${namespace}
11-
`
13+
`;
1214
}
1315

1416
type VirtualMachineManifestArguments = {
15-
vmName: string
16-
namespace: string
17-
claimName: string
18-
userDataSecretName: string
19-
}
17+
vmName: string;
18+
namespace: string;
19+
claimName: string;
20+
userDataSecretName: string;
21+
};
2022

21-
export function VirtualMachineManifest({ vmName, namespace, claimName, userDataSecretName }: VirtualMachineManifestArguments) {
22-
return `
23+
export function VirtualMachineManifest({
24+
vmName,
25+
namespace,
26+
claimName,
27+
userDataSecretName,
28+
}: VirtualMachineManifestArguments) {
29+
return `
2330
apiVersion: kubevirt.io/v1
2431
type: kubevirt.io.virtualmachine
2532
kind: VirtualMachine
@@ -89,16 +96,16 @@ spec:
8996
secretRef:
9097
name: ${userDataSecretName}
9198
92-
`
99+
`;
93100
}
94101

95102
type ServiceManifestOptions = {
96-
vmName: string
97-
namespace: string
98-
}
103+
vmName: string;
104+
namespace: string;
105+
};
99106

100107
export function ServiceManifest({ vmName, namespace }: ServiceManifestOptions) {
101-
return `
108+
return `
102109
apiVersion: v1
103110
kind: Service
104111
metadata:
@@ -137,12 +144,12 @@ spec:
137144
selector:
138145
harvesterhci.io/vmName: ${vmName}
139146
type: ClusterIP
140-
`
147+
`;
141148
}
142149

143150
type LBServiceManifestOptions = {
144-
name: string
145-
}
151+
name: string;
152+
};
146153

147154
export function LBServiceManifest({ name }: LBServiceManifestOptions) {
148155
return `
@@ -164,15 +171,15 @@ spec:
164171
selector:
165172
gitpod.io/lbName: ${name}
166173
type: LoadBalancer
167-
`
174+
`;
168175
}
169176

170177
type LBDeployManifestOptions = {
171-
name: string
172-
}
178+
name: string;
179+
};
173180

174181
export function LBDeployManifest({ name }: LBDeployManifestOptions) {
175-
return `
182+
return `
176183
apiVersion: apps/v1
177184
kind: Deployment
178185
metadata:
@@ -216,17 +223,20 @@ spec:
216223
mountPath: /mnt/kubeconfig/
217224
serviceAccount: proxy
218225
enableServiceLinks: false
219-
`
226+
`;
220227
}
221228

222229
type UserDataSecretManifestOptions = {
223-
vmName: string
224-
namespace: string,
225-
secretName: string
226-
}
230+
vmName: string;
231+
namespace: string;
232+
secretName: string;
233+
};
227234

228235
export function UserDataSecretManifest({ vmName, namespace, secretName }: UserDataSecretManifestOptions) {
229-
const userdata = Buffer.from(`#cloud-config
236+
const dockerhubUser = fs.readFileSync("/mnt/secrets/harvester-k3s-dockerhub-pull-account/username").toString();
237+
const dockerhubPasswd = fs.readFileSync("/mnt/secrets/harvester-k3s-dockerhub-pull-account/password").toString();
238+
const userdata = Buffer.from(
239+
`#cloud-config
230240
users:
231241
- name: ubuntu
232242
sudo: "ALL=(ALL) NOPASSWD: ALL"
@@ -255,6 +265,7 @@ write_files:
255265
permission: 0644
256266
owner: root
257267
content: 'Port 2200'
268+
258269
- path: /usr/local/bin/bootstrap-k3s.sh
259270
permissions: 0744
260271
owner: root
@@ -263,6 +274,13 @@ write_files:
263274
264275
set -eo pipefail
265276
277+
cat <<EOF >> /etc/containerd/config.toml
278+
[plugins."io.containerd.grpc.v1.cri".registry.configs."registry-1.docker.io".auth]
279+
username = "${dockerhubUser}"
280+
password = "${dockerhubPasswd}"
281+
EOF
282+
sudo systemctl restart containerd.service
283+
266284
# inspired by https://github.com/gitpod-io/ops/blob/main/deploy/workspace/templates/bootstrap.sh
267285
268286
# Install k3s
@@ -312,8 +330,9 @@ write_files:
312330
EOF
313331
runcmd:
314332
- bash /etc/disable-services.sh
315-
- bash /usr/local/bin/bootstrap-k3s.sh`).toString("base64")
316-
return `
333+
- bash /usr/local/bin/bootstrap-k3s.sh`,
334+
).toString("base64");
335+
return `
317336
apiVersion: v1
318337
type: secret
319338
kind: Secret
@@ -323,5 +342,5 @@ data:
323342
metadata:
324343
name: ${secretName}
325344
namespace: ${namespace}
326-
`
345+
`;
327346
}

0 commit comments

Comments
 (0)