Skip to content

Commit def301f

Browse files
author
Joe Ellis
committed
Add Docker image for testing Parsec as a systemd service
Signed-off-by: Joe Ellis <[email protected]>
1 parent 9530d64 commit def301f

File tree

4 files changed

+181
-0
lines changed

4 files changed

+181
-0
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,11 @@ jobs:
4242
run: docker build -t tpm-provider e2e_tests/provider_cfg/tpm
4343
- name: Run the container to execute the test script
4444
run: docker run -v $(pwd):/tmp/parsec -w /tmp/parsec tpm-provider /tmp/parsec/ci.sh tpm
45+
46+
installation-tests:
47+
name: Installation tests
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v1
51+
- name: Build and run the container
52+
run: e2e_tests/install/run-installation-tests.sh
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
FROM ubuntu:18.04
2+
3+
ENV container docker
4+
5+
RUN apt-get update
6+
RUN apt-get install -y git make gcc python3 python curl wget cmake \
7+
automake autoconf libtool pkg-config libssl-dev \
8+
# These libraries are needed for bindgen as it uses
9+
# libclang.so
10+
clang libclang-dev libc6-dev-i386
11+
RUN apt-get install -y systemd systemd-sysv
12+
RUN apt-get clean
13+
14+
RUN useradd -m parsec
15+
RUN groupadd parsec-clients
16+
RUN usermod -a -G parsec-clients parsec
17+
18+
USER parsec
19+
WORKDIR /home/parsec
20+
21+
# Install Rust toolchain.
22+
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
23+
ENV PATH "/home/parsec/.cargo/bin:$PATH"
24+
25+
# Install Parsec.
26+
RUN cargo install parsec-service --features mbed-crypto-provider
27+
RUN git clone https://github.com/parallaxsecond/parsec.git
28+
RUN cp parsec/config.toml config.toml
29+
30+
# Install the systemd unit files.
31+
RUN mkdir -p .config/systemd/user
32+
RUN cp parsec/systemd-daemon/parsec.service .config/systemd/user/parsec.service
33+
34+
USER root
35+
WORKDIR /root
36+
COPY context/run-tests.sh ./
37+
VOLUME [ "/sys/fs/cgroup" ]
38+
CMD [ "/lib/systemd/systemd" ]
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
function test_ping_parsec() {
6+
# Creates a new test user, adds them to the parsec-clients group, and
7+
# checks that the Parsec service can be pinged.
8+
9+
useradd -m test-user-1
10+
usermod -a -G parsec-clients test-user-1
11+
12+
su test-user-1 <<' EOSU'
13+
set -eu
14+
cd ${HOME}
15+
curl https://sh.rustup.rs -sSf | bash -s -- -y
16+
export PATH="${HOME}/.cargo/bin:$PATH"
17+
18+
git clone https://github.com/parallaxsecond/parsec-tool.git
19+
cd parsec-tool
20+
cargo build
21+
22+
set +e
23+
cargo run -- ping
24+
25+
# This test passes if the above command pinged the Parsec service
26+
# successfully.
27+
[ $? -eq 0 ]
28+
EOSU
29+
}
30+
31+
function test_ping_parsec_not_in_group() {
32+
# Creates a new test user, and tries to ping the Parsec service. This
33+
# should fail, since the user is not in the appropriate group.
34+
35+
useradd -m test-user-2
36+
37+
su test-user-2 <<' EOSU'
38+
set -eu
39+
cd ${HOME}
40+
curl https://sh.rustup.rs -sSf | bash -s -- -y
41+
export PATH="${HOME}/.cargo/bin:$PATH"
42+
43+
git clone https://github.com/parallaxsecond/parsec-tool.git
44+
cd parsec-tool
45+
cargo build
46+
47+
set +e
48+
cargo run -- ping
49+
50+
# This test passes if the above command failed to ping the Parsec service.
51+
[ $? -ne 0 ]
52+
EOSU
53+
}
54+
55+
function install_parsec() {
56+
mkdir /tmp/parsec
57+
chown parsec:parsec-clients /tmp/parsec
58+
chmod 750 /tmp/parsec
59+
60+
# Configure and start the Parsec service as user `parsec`.
61+
su parsec << ' EOSU'
62+
set -eu
63+
export PATH="${HOME}/.cargo/bin:$PATH"
64+
cargo install --path ${HOME}/parsec --features 'mbed-crypto-provider'
65+
mkdir -p ${HOME}/.config/systemd/user
66+
cp ${HOME}/parsec/systemd-daemon/parsec.service \
67+
${HOME}/.config/systemd/user/parsec.service
68+
69+
systemctl --user daemon-reload
70+
systemctl --user start parsec
71+
EOSU
72+
}
73+
74+
function main() {
75+
install_parsec
76+
77+
# Register tests.
78+
declare -a TESTS
79+
TESTS[1]="test_ping_parsec"
80+
TESTS[2]="test_ping_parsec_not_in_group"
81+
82+
# Run tests.
83+
NUM_FAILED=0
84+
for i in "${!TESTS[@]}"; do
85+
TEST_NAME="${TESTS[$i]}"
86+
echo "=== RUNNING TEST ${TEST_NAME} ==="
87+
if ${TESTS[$i]}; then
88+
echo "${TEST_NAME} passed."
89+
else
90+
echo "${TEST_NAME} failed!"
91+
NUM_FAILED=$((NUM_FAILED + 1))
92+
fi
93+
echo "" # spacing
94+
done
95+
96+
if [[ ${NUM_FAILED} -eq 0 ]]; then
97+
echo "All tests passed!"
98+
else
99+
echo "${NUM_FAILED} test(s) failed!"
100+
fi
101+
102+
return ${NUM_FAILED}
103+
}
104+
105+
main "${@}" || exit 1
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
6+
7+
DOCKER_IMAGE_DIR="$SCRIPT_DIR"
8+
DOCKER_IMAGE_NAME="parsec"
9+
10+
docker build -t ${DOCKER_IMAGE_NAME} ${DOCKER_IMAGE_DIR}
11+
DOCKER_CONTAINER_ID=$(docker run -d \
12+
--rm \
13+
--tmpfs /run \
14+
--tmpfs /run/lock \
15+
--tmpfs /tmp:exec \
16+
-v /sys/fs/cgroup:/sys/fs/cgroup:ro \
17+
-v $(git rev-parse --show-toplevel):/home/parsec/parsec \
18+
${DOCKER_IMAGE_NAME})
19+
20+
# Give the systemd daemon some time to spin up.
21+
sleep 3
22+
23+
echo "Running tests inside container..."
24+
docker exec ${DOCKER_CONTAINER_ID} /root/run-tests.sh
25+
TEST_STATUS=$?
26+
27+
echo "Testing complete, stopping container."
28+
docker stop ${DOCKER_CONTAINER_ID}
29+
30+
exit ${TEST_STATUS}

0 commit comments

Comments
 (0)