Skip to content

Add integration tests for Arch, Ubuntu, Fedora #45

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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ _local
.idea
.git
.github
varia/Dockerfile.tests
test.sh
varia/Dockerfile.*
23 changes: 22 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -24,3 +24,24 @@ 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:
- uses: actions/checkout@v1
- 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
26 changes: 26 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
# TODO: Rename script to something more descriptive

set -e
# ARGS=--pull
DISTRO=${1:-archlinux}
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 \
-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'"
53 changes: 53 additions & 0 deletions varia/Dockerfile.integration
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 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 systemd

#### UBUNTU base image
FROM ubuntu:latest AS ego-base-ubuntu
RUN apt-get update && \
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 cargo libacl-devel systemd systemd-container && \
yum clean all && \
rm -rf /var/cache/yum

#### 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 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 && \
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
12 changes: 12 additions & 0 deletions varia/console-getty-override.conf
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions varia/run-host-command.service
Original file line number Diff line number Diff line change
@@ -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