Skip to content

Commit 61e502f

Browse files
committed
Attempts to have systemd working inside the container
1 parent b09da84 commit 61e502f

3 files changed

Lines changed: 41 additions & 18 deletions

File tree

.devcontainer/test/Dockerfile

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,30 @@
44

55
FROM --platform=linux/amd64 opensuse/leap:15.6
66

7-
RUN zypper -n install curl git tar gzip make gcc podman systemd systemd-sysvcompat
7+
RUN zypper -n install curl git tar gzip make gcc podman
88

99
# Install Go and Ginkgo
1010
RUN curl -LO https://go.dev/dl/go1.21.13.linux-amd64.tar.gz
11-
RUN tar -C /usr/local -xzf go1.21.13.linux-amd64.tar.gz
12-
ENV PATH="/usr/local/go/bin:$PATH"
11+
RUN tar -C /root -xzf go1.21.13.linux-amd64.tar.gz
12+
ENV PATH="/root/go/bin:$PATH"
1313
RUN go install github.com/onsi/ginkgo/v2/ginkgo@v2.20.1
1414

15+
ENV container=docker
16+
17+
RUN zypper install -y findutils iproute2 python3 sudo systemd
18+
19+
RUN find /etc/systemd/system \
20+
/lib/systemd/system \
21+
-path '*.wants/*' \
22+
-not -name '*journal*' \
23+
-not -name '*systemd-tmpfiles*' \
24+
-not -name '*systemd-user-sessions*' \
25+
-print0 | xargs -0 rm -vf
26+
27+
VOLUME [ "/sys/fs/cgroup" ]
28+
1529
WORKDIR /workspace
1630

17-
# /usr/sbin/init is the standard path for the systemd executable acting as init.
18-
CMD ["/usr/sbin/init"]
31+
ENTRYPOINT [ "/usr/sbin/init" ]
32+
33+
CMD ["/bin/bash"]

.devcontainer/test/devcontainer.json

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,17 @@
66
"build": { "dockerfile": "Dockerfile" },
77
"runArgs": [
88
"--privileged",
9-
"--tmpfs /tmp",
10-
"--tmpfs /run",
11-
"--cap-add=SYS_ADMIN",
12-
"--cap-add=AUDIT_WRITE",
13-
"--cap-add=AUDIT_CONTROL",
9+
"--cap-add=ALL",
1410
"--cgroupns=host",
15-
"--volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
11+
"--tmpfs /run",
12+
"--tmpfs /run/lock",
13+
"-v", "/sys/fs/cgroup:/sys/fs/cgroup:rw"
1614
],
17-
"init": true,
18-
"securityOpt": [ "seccomp=unconfined" ], // needed for systemd
1915
"containerEnv": {
2016
"container": "docker"
2117
},
2218
"remoteUser": "root",
23-
"customizations": {
24-
"vscode": {
25-
"extensions": ["golang.Go"]
26-
}
27-
},
19+
"containerUser": "root",
20+
"overrideCommand": false,
2821
"workspaceFolder": "/workspace"
2922
}

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,23 @@ Those are generated using the `locale/build.sh` script.
150150

151151
### To run End-To-End tests
152152

153+
Use podman machine as the container runtime and set it as `rootful`:
154+
```bash
155+
podman machine stop
156+
podman machine set --rootful=true --memory=8192
157+
podman machine start
158+
export DOCKER_HOST="unix://$(podman info --format '{{.Host.RemoteSocket.Path}}')"
159+
160+
```
161+
162+
Then, you can run the devcontainer commands to build and run the devcontainer for testing:
153163
```bash
154164
devcontainer up --workspace-folder . --config .devcontainer/test/devcontainer.json
165+
devcontainer exec --workspace-folder . bash
166+
```
167+
168+
Once inside the devcontainer, you can run the tests with:
169+
```bash
155170
cd /workspace
156171
go build -o bin/mgradm ./mgradm
157172
go build -o bin/mgrctl ./mgrctl

0 commit comments

Comments
 (0)