Skip to content

Add quadlet #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ RUN set -ex; \
mv bin/podman /usr/local/bin/podman; \
podman --help >/dev/null; \
! ldd /usr/local/bin/podman
RUN set -ex; \
# overwrites the default bin directory so quadlet looks for the podman binary in /usr/local/bin
export LDFLAGS_QUADLET="-X github.com/containers/podman/v5/pkg/systemd/quadlet._binDir=/usr/local/bin"; \
CGO_ENABLED=0 make bin/quadlet LDFLAGS_PODMAN="-s -w -extldflags '-static' ${LDFLAGS_QUADLET}" BUILDTAGS='${PODMAN_BUILDTAGS}'; \
mkdir -p /usr/local/libexec/podman; \
mv bin/quadlet /usr/local/libexec/podman/quadlet; \
! ldd /usr/local/libexec/podman/quadlet
RUN set -ex; \
CGO_ENABLED=0 make bin/rootlessport BUILDFLAGS=" -mod=vendor -ldflags=\"-s -w -extldflags '-static'\""; \
mkdir -p /usr/local/lib/podman; \
Expand Down Expand Up @@ -188,6 +195,7 @@ COPY conf/crun-containers.conf /etc/containers/containers.conf
FROM rootlesspodmanbase AS podmanall
RUN apk add --no-cache iptables ip6tables
COPY --from=catatonit /catatonit/catatonit /usr/local/lib/podman/catatonit
COPY --from=podman /usr/local/libexec/podman/quadlet /usr/local/libexec/podman/quadlet
COPY --from=runc /usr/local/bin/runc /usr/local/bin/runc
COPY --from=aardvark-dns /aardvark-dns/target/release/aardvark-dns /usr/local/lib/podman/aardvark-dns
COPY --from=podman /etc/containers/seccomp.json /etc/containers/seccomp.json
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@ tar: .podman-from-container
.podman-from-container: podman
rm -rf $(ASSET_DIR)
mkdir -p $(ASSET_DIR)/etc $(ASSET_DIR)/usr/local
mkdir -p $(ASSET_DIR)/etc $(ASSET_DIR)/usr/lib/systemd/user-generators/
mkdir -p $(ASSET_DIR)/etc $(ASSET_DIR)/usr/lib/systemd/system-generators/
cp -r $(IMAGE_ROOTFS)/etc/containers $(ASSET_DIR)/etc/containers
cp -r $(IMAGE_ROOTFS)/usr/local/lib $(ASSET_DIR)/usr/local/lib
cp -r $(IMAGE_ROOTFS)/usr/local/libexec $(ASSET_DIR)/usr/local/libexec
ln -s ../../../local/libexec/podman/quadlet $(ASSET_DIR)/usr/lib/systemd/user-generators/podman-user-generator
ln -s ../../../local/libexec/podman/quadlet $(ASSET_DIR)/usr/lib/systemd/system-generators/podman-system-generator
cp -r $(IMAGE_ROOTFS)/usr/local/bin $(ASSET_DIR)/usr/local/bin
cp README.md $(ASSET_DIR)/

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,6 @@ sudo rm -rf /usr/lib/systemd/system/podman*
sudo rm -rf /usr/lib/systemd/user/podman*
sudo rm -rf /usr/local/bin/{crun,fuse-overlayfs,fusermount3,pasta,pasta.avx2,podman,runc}
sudo rm -rf /usr/local/lib/podman
sudo rm -rf /usr/local/libexec/podman
sudo rm /usr/lib/systemd/{user,system}-generators/podman-user-generator
```
19 changes: 19 additions & 0 deletions test/quadlet/hello_world.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[Unit]
Description=hello_world
After=local-fs.target

[Container]
Image=docker.io/hello-world
ContainerName=hello_world

# Network
PublishPort=8080:8080

# Environment
Environment=HELLO=WORLD

[Service]
Restart=on-failure

[Install]
WantedBy=multi-user.target default.target
22 changes: 22 additions & 0 deletions test/rootful.bats
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,25 @@ skipIfDockerUnavailableAndNotRunAsRoot() {
skipIfDockerUnavailableAndNotRunAsRoot
testPortForwarding -u root:root -v "$PODMAN_ROOT_DATA_DIR:/var/lib/containers/storage" "${PODMAN_IMAGE}"
}

@test "$TEST_PREFIX quadlet - generate service" {
if [ "${TEST_SKIP_QUADLET:-}" = true ]; then
skip "TEST_SKIP_QUADLET=true"
fi
$DOCKER run --rm -u podman:podman \
-v "$BATS_TEST_DIRNAME/quadlet/hello_world.container:/etc/containers/systemd/hello_world.container" \
--pull=never "${PODMAN_IMAGE}" \
/usr/local/libexec/podman/quadlet -dryrun > /tmp/test.service # this goes to tmp because we are not root below

expected_values=(
"--name hello_world"
"--publish 8080:8080"
"--env HELLO=WORLD"
"docker.io/hello-world"
)

for value in "${expected_values[@]}"; do
run grep -q -- "$value" "/tmp/test.service"
[ "$status" -eq 0 ] || fail "Expected '$value' not found in /tmp/test.service"
done
}
Loading