Skip to content

Commit a47a37d

Browse files
committed
forgejo: runner rootless dind (v2)
1 parent 9998556 commit a47a37d

File tree

1 file changed

+60
-16
lines changed

1 file changed

+60
-16
lines changed

manifests/apps/by-cluster/rgst/forgejo.jsonnet

+60-16
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ local all = {
138138
redis: { enabled: true },
139139
},
140140
),
141-
runner: k._Object('apps/v1', 'Deployment', name + '-runner', namespace) {
141+
runner: k._Object('apps/v1', 'StatefulSet', name + '-runner', namespace) {
142142
spec: {
143143
replicas: 2,
144144
selector: { matchLabels: { app: name + '-runner' } },
145145
strategy: {
146-
type: 'Recreate',
146+
type: 'RollingUpdate',
147147
},
148148
template: {
149149
metadata: {
@@ -155,17 +155,15 @@ local all = {
155155
nodeSelector: {
156156
'kubernetes.io/hostname': 'mocha',
157157
},
158-
restartPolicy: 'Always',
159158
volumes: [
160159
{
161-
name: 'docker-socket',
160+
name: name,
162161
emptyDir: {},
163-
},
164-
{
165-
name: 'runner-data',
166-
emptyDir: {},
167-
},
162+
}
163+
for name in ['dind-sock', 'dind-etc', 'dind-home', 'runner-data']
168164
],
165+
local dind_sock_dir = '/run/docker',
166+
local dind_sock = dind_sock_dir + '/docker.sock',
169167
initContainers: [
170168
{
171169
name: 'runner-register',
@@ -212,17 +210,62 @@ local all = {
212210
mountPath: '/data',
213211
}],
214212
},
213+
{
214+
name: 'setup-dind',
215+
command: ['sh', '-ex', '-c'],
216+
args: [
217+
|||
218+
cp -a /etc/. /dind-etc/
219+
echo 'runner:x:1000:1000:runner:/home/runner:/bin/ash' >> /dind-etc/passwd
220+
echo 'runner:x:1000:' >> /dind-etc/group
221+
echo 'runner:100000:65536' >> /dind-etc/subgid
222+
echo 'runner:100000:65536' >> /dind-etc/subuid
223+
chmod 755 /dind-etc;
224+
chmod u=rwx,g=rx+s,o=rx /dind-home
225+
chown 1000:1000 /dind-home
226+
||| % { dock_sock: dind_sock },
227+
],
228+
securityContext: { runAsUser: 0 },
229+
volumeMounts: [
230+
{
231+
name: 'dind-etc',
232+
mountPath: '/dind-etc',
233+
},
234+
{
235+
name: 'dind-home',
236+
mountPath: '/dind-home',
237+
},
238+
],
239+
},
215240
{
216241
name: 'docker',
217242
image: 'docker:28.0.1-dind-rootless',
218243
command: ['dockerd'],
219-
args: ['-H', 'unix:///docker-socket/docker.sock'],
220-
securityContext: { privileged: true },
244+
args: [
245+
'--host',
246+
'unix://' + dind_sock,
247+
],
248+
securityContext: {
249+
privileged: true,
250+
runAsUser: '1000',
251+
runAsGroup: '1000',
252+
fsGroups: [1000],
253+
},
221254
restartPolicy: 'Always', // sidecar
222-
volumeMounts: [{
223-
name: 'docker-socket',
224-
mountPath: '/docker-socket/',
225-
}],
255+
volumeMounts: [
256+
{
257+
name: 'dind-sock',
258+
mountPath: dind_sock_dir,
259+
},
260+
{
261+
name: 'dind-etc',
262+
mountPath: '/etc',
263+
},
264+
{
265+
name: 'dind-home',
266+
mountPath: '/home/runner',
267+
},
268+
],
226269
},
227270
],
228271
containers: [{
@@ -232,7 +275,8 @@ local all = {
232275
volumeMounts: [
233276
{
234277
name: 'docker-socket',
235-
mountPath: '/var/run',
278+
mountPath: dind_sock_dir,
279+
readOnly: true,
236280
},
237281
{
238282
name: 'runner-data',

0 commit comments

Comments
 (0)