From 9e8c60730b2a11283be12ab906c5cc62be666ef5 Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Sat, 6 Feb 2021 14:23:44 +0200 Subject: [PATCH 1/8] Add integration tests for Arch, Ubuntu, Fedora --- .dockerignore | 3 ++- .github/workflows/tests.yml | 20 ++++++++++++++++- test.sh | 10 +++++++++ varia/Dockerfile.integration | 43 ++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100755 test.sh create mode 100644 varia/Dockerfile.integration diff --git a/.dockerignore b/.dockerignore index 86ea41e..f29e3d2 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,4 +3,5 @@ _local .idea .git .github -varia/Dockerfile.tests +test.sh +varia/Dockerfile.* diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8e963e1..134b4fe 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,7 +5,7 @@ on: pull_request: schedule: # 16:21 UTC on Tuesdays - - cron: "21 16 * * tue" + - cron: "21 16 * * TUE" repository_dispatch: types: [tests] @@ -24,3 +24,21 @@ jobs: run: docker run --rm ego-build cargo clippy --color=always - name: rustfmt run: docker run --rm ego-build cargo fmt -- --color=always --check + + test-archlinux: + runs-on: ubuntu-latest + steps: + - name: Test on Ubuntu + run: ./test archlinux --pull + + test-ubuntu: + runs-on: ubuntu-latest + steps: + - name: Test on Ubuntu + run: ./test ubuntu --pull + + test-fedora: + runs-on: ubuntu-latest + steps: + - name: Test on Fedora + run: ./test fedora --pull diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..ee18825 --- /dev/null +++ b/test.sh @@ -0,0 +1,10 @@ +#!/bin/sh +set -e +# ARGS=--pull +DISTRO=${1:-archlinux} +IMG=ego-$DISTRO + +export DOCKER_BUILDKIT=1 + +docker build . ${2-} -f varia/Dockerfile.integration --build-arg=distro=$DISTRO -t $IMG +docker run --rm $IMG sh -c 'id && ego --sudo id' diff --git a/varia/Dockerfile.integration b/varia/Dockerfile.integration new file mode 100644 index 0000000..86ecbce --- /dev/null +++ b/varia/Dockerfile.integration @@ -0,0 +1,43 @@ +# This Dockerfile is for integration testing in CI, see .github/workflows/tests.yml +# Run with --build-arg=channel=stable OR --build-arg=channel=nightly (default) +ARG distro=archlinux + +# Using Dockerfile conditionals +#### ARCH LINUX base image +FROM archlinux:base-devel AS ego-base-archlinux +RUN pacman --noconfirm -Sy cargo acl + +#### UBUNTU base image +FROM ubuntu:latest AS ego-base-ubuntu +RUN apt-get update && \ + apt-get install -y libacl1-dev cargo sudo && \ + rm -rf /var/lib/apt/lists/* + +#### FEDORA base image +FROM fedora:latest AS ego-base-fedora +RUN yum install -y libacl-devel cargo + +#### Common logic for base image +FROM ego-base-$distro AS cargo-build + +WORKDIR /root/build +# Make warnings fatal +ENV RUSTFLAGS="-D warnings" + +# Build Cargo dependencies for cache +COPY Cargo.toml Cargo.lock ./ +RUN mkdir src/ && \ + echo "pub fn main() {println!(\"dummy function\")}" > src/main.rs && \ + cargo build --bins --tests --color=always && \ + rm -rdv target/*/deps/ego-* \ + target/*/.fingerprint/ego-* + +# Do the actual build +COPY . . +RUN cargo install --root=/usr/local --path . --color=always + +RUN useradd ego --uid 155 --create-home && \ + useradd user --create-home && \ + mkdir -m 0700 -p /run/user/0 +# TODO: Get rid of XDG_RUNTIME_DIR requirement for command-line-only usage? (see #29) +ENV XDG_RUNTIME_DIR=/run/user/0 From da3a3274d0ac6c97022aa82b4fa05a5f23643cfb Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Sat, 6 Feb 2021 14:26:26 +0200 Subject: [PATCH 2/8] Fix --- .github/workflows/tests.yml | 6 +++--- test.sh | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 134b4fe..e3237d6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -29,16 +29,16 @@ jobs: runs-on: ubuntu-latest steps: - name: Test on Ubuntu - run: ./test archlinux --pull + run: ./test.sh archlinux --pull test-ubuntu: runs-on: ubuntu-latest steps: - name: Test on Ubuntu - run: ./test ubuntu --pull + run: ./test.sh ubuntu --pull test-fedora: runs-on: ubuntu-latest steps: - name: Test on Fedora - run: ./test fedora --pull + run: ./test.sh fedora --pull diff --git a/test.sh b/test.sh index ee18825..d99fbb6 100755 --- a/test.sh +++ b/test.sh @@ -1,4 +1,6 @@ #!/bin/sh +# TODO: Rename script to something more descriptive + set -e # ARGS=--pull DISTRO=${1:-archlinux} From c911070445c34b55f9778c94f11914ecfe20a677 Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Sat, 6 Feb 2021 14:33:58 +0200 Subject: [PATCH 3/8] Fix even more --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e3237d6..198fba2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,6 +28,7 @@ jobs: test-archlinux: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v1 - name: Test on Ubuntu run: ./test.sh archlinux --pull From 2e9dea17bcb26b7f493457cd517d7e29401d8539 Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Sat, 6 Feb 2021 14:41:00 +0200 Subject: [PATCH 4/8] Extreme fixing action! --- .github/workflows/tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 198fba2..3bc3092 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -29,17 +29,19 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - name: Test on Ubuntu + - name: Test on Arch Linux run: ./test.sh archlinux --pull test-ubuntu: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v1 - name: Test on Ubuntu run: ./test.sh ubuntu --pull test-fedora: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v1 - name: Test on Fedora run: ./test.sh fedora --pull From 009ef6e6cb7b7900de777db661faef569e5676a0 Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Sat, 6 Feb 2021 14:50:53 +0200 Subject: [PATCH 5/8] cleanup in yum --- varia/Dockerfile.integration | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/varia/Dockerfile.integration b/varia/Dockerfile.integration index 86ecbce..a5063a7 100644 --- a/varia/Dockerfile.integration +++ b/varia/Dockerfile.integration @@ -15,7 +15,9 @@ RUN apt-get update && \ #### FEDORA base image FROM fedora:latest AS ego-base-fedora -RUN yum install -y libacl-devel cargo +RUN yum install -y libacl-devel cargo && \ + yum clean all && \ + rm -rf /var/cache/yum #### Common logic for base image FROM ego-base-$distro AS cargo-build From 2bc53c8f1a25636f00267b664a01a5f5aff61cb8 Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Sat, 6 Feb 2021 19:22:54 +0200 Subject: [PATCH 6/8] WIP --- test.sh | 14 ++++++++++++++ varia/Dockerfile.integration | 18 +++++++++++++----- varia/console-getty-override.conf | 12 ++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 varia/console-getty-override.conf diff --git a/test.sh b/test.sh index d99fbb6..066592d 100755 --- a/test.sh +++ b/test.sh @@ -8,5 +8,19 @@ IMG=ego-$DISTRO export DOCKER_BUILDKIT=1 +if [ "$DISTRO" = ubuntu ]; then + SYSTEMD=/bin/systemd +else + SYSTEMD=/usr/lib/systemd/systemd +fi + docker build . ${2-} -f varia/Dockerfile.integration --build-arg=distro=$DISTRO -t $IMG docker run --rm $IMG sh -c 'id && ego --sudo id' +docker run --rm -it \ + -e container=docker \ + --tmpfs /run \ + --tmpfs /tmp \ + -v /sys/fs/cgroup:/sys/fs/cgroup:ro \ + --cap-add SYS_ADMIN \ + $IMG "$SYSTEMD" quiet systemd.firstboot=off \ + systemd.setenv="CMD='id && mkdir -p /run/user/0 && XDG_RUNTIME_DIR=/run/user/0 ego --machinectl id'" diff --git a/varia/Dockerfile.integration b/varia/Dockerfile.integration index a5063a7..8f0893f 100644 --- a/varia/Dockerfile.integration +++ b/varia/Dockerfile.integration @@ -5,17 +5,17 @@ ARG distro=archlinux # Using Dockerfile conditionals #### ARCH LINUX base image FROM archlinux:base-devel AS ego-base-archlinux -RUN pacman --noconfirm -Sy cargo acl +RUN pacman --noconfirm -Sy cargo acl systemd #### UBUNTU base image FROM ubuntu:latest AS ego-base-ubuntu RUN apt-get update && \ - apt-get install -y libacl1-dev cargo sudo && \ + apt-get install -y cargo libacl1-dev systemd systemd-container sudo && \ rm -rf /var/lib/apt/lists/* #### FEDORA base image FROM fedora:latest AS ego-base-fedora -RUN yum install -y libacl-devel cargo && \ +RUN yum install -y cargo libacl-devel systemd systemd-container && \ yum clean all && \ rm -rf /var/cache/yum @@ -35,11 +35,19 @@ RUN mkdir src/ && \ target/*/.fingerprint/ego-* # Do the actual build -COPY . . +COPY src src RUN cargo install --root=/usr/local --path . --color=always RUN useradd ego --uid 155 --create-home && \ useradd user --create-home && \ - mkdir -m 0700 -p /run/user/0 + mkdir -m 0700 -p /run/user/0 && \ + echo root:root | chpasswd # TODO: Get rid of XDG_RUNTIME_DIR requirement for command-line-only usage? (see #29) ENV XDG_RUNTIME_DIR=/run/user/0 + +# From https://www.brad-x.com/2014/12/27/running-systemd-within-a-docker-image/ +RUN systemctl mask swap.target +#RUN systemctl disable graphical.target; systemctl enable multi-user.target +RUN mkdir -p /etc/systemd/system/console-getty.service.d +COPY varia/console-getty-override.conf /etc/systemd/system/console-getty.service.d/override.conf +RUN echo -e '[Journal]\nStorage=none' > /etc/systemd/journald.conf diff --git a/varia/console-getty-override.conf b/varia/console-getty-override.conf new file mode 100644 index 0000000..4bdbec1 --- /dev/null +++ b/varia/console-getty-override.conf @@ -0,0 +1,12 @@ +# /etc/systemd/system/console-getty.service.d/override.conf +[Service] +ExecStart= +# ExecStart=-/usr/bin/sh -c '${CMD}' +ExecStart=-/usr/bin/bash +ExecStopPost=/usr/bin/systemctl poweroff --force +StandardInput=tty +StandardOutput=tty +Type=oneshot +Restart=no +# XXX? +KillMode=control-group From 6591f5f42c8c865c001409dca287b6e9a3fc571a Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Thu, 18 Feb 2021 23:21:18 +0200 Subject: [PATCH 7/8] WIP??? --- test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 066592d..b567fea 100755 --- a/test.sh +++ b/test.sh @@ -16,7 +16,7 @@ fi docker build . ${2-} -f varia/Dockerfile.integration --build-arg=distro=$DISTRO -t $IMG docker run --rm $IMG sh -c 'id && ego --sudo id' -docker run --rm -it \ +docker run --rm \ -e container=docker \ --tmpfs /run \ --tmpfs /tmp \ From 1772b7a67ca318c29ce4c0cd8f4bcf5198fe7126 Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Sun, 7 Mar 2021 05:33:34 +0200 Subject: [PATCH 8/8] Add run-host-command.service --- varia/run-host-command.service | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 varia/run-host-command.service diff --git a/varia/run-host-command.service b/varia/run-host-command.service new file mode 100644 index 0000000..6167a6a --- /dev/null +++ b/varia/run-host-command.service @@ -0,0 +1,12 @@ +# /etc/systemd/system/console-getty.service.d/override.conf +[Service] +#ExecStart= +# ExecStart=-/usr/bin/sh -c '${CMD}' +ExecStart=-/usr/bin/bash +ExecStopPost=/usr/bin/systemctl poweroff --force +StandardInput=tty +StandardOutput=tty +Type=oneshot +Restart=no +# XXX? +KillMode=control-group