Skip to content

Commit aae8d15

Browse files
authored
Merge pull request #257 from chriskuehl/github-actions
Switch to GitHub Actions for CI
2 parents 57f7eeb + 16ba926 commit aae8d15

16 files changed

+115
-110
lines changed

.github/workflows/ci.yaml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: CI
2+
on: push
3+
jobs:
4+
build-and-test:
5+
runs-on: ubuntu-20.04
6+
strategy:
7+
fail-fast: false
8+
matrix:
9+
include:
10+
- arch: amd64
11+
docker_image: debian:buster
12+
13+
- arch: arm64
14+
docker_image: arm64v8/debian:buster
15+
16+
- arch: ppc64le
17+
docker_image: ppc64le/debian:buster
18+
19+
- arch: s390x
20+
docker_image: s390x/debian:buster
21+
22+
env:
23+
BASE_IMAGE: ${{ matrix.docker_image }}
24+
25+
steps:
26+
- uses: actions/checkout@v2
27+
28+
- name: Set up QEMU
29+
id: qemu
30+
uses: docker/setup-qemu-action@v1
31+
if: ${{ matrix.arch != 'amd64' }}
32+
with:
33+
image: tonistiigi/binfmt:latest
34+
35+
- name: Build Docker image
36+
run: make docker-image
37+
38+
- name: Run python tests
39+
run: docker run --rm -v $(pwd):/mnt:rw dumb-init-build /mnt/ci/docker-python-test
40+
41+
- name: Build Debian package
42+
run: docker run --init --rm -v $(pwd):/mnt:rw dumb-init-build make -C /mnt builddeb
43+
44+
- name: Test built Debian package
45+
# XXX: This uses the clean base image (not the build one) to make
46+
# sure it installs in a clean image without any hidden dependencies.
47+
run: docker run --rm -v $(pwd):/mnt:rw ${{ matrix.docker_image }} /mnt/ci/docker-deb-test
48+
49+
- name: Upload build artifacts
50+
uses: actions/upload-artifact@v2
51+
with:
52+
name: ${{ matrix.arch }}
53+
path: dist

.travis.yml

-29
This file was deleted.

Dockerfile

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
FROM debian:buster
1+
ARG BASE_IMAGE=debian:buster
2+
FROM $BASE_IMAGE
23

34
LABEL maintainer="Chris Kuehl <[email protected]>"
45

5-
# The default mirrors are too flaky to run reliably in CI.
6-
RUN sed -E \
7-
'/security\.debian/! s@http://[^/]+/@http://mirrors.kernel.org/@' \
8-
-i /etc/apt/sources.list
9-
106
# Install the bare minimum dependencies necessary for working with Debian
117
# packages. Build dependencies should be added under "Build-Depends" inside
128
# debian/control instead.
@@ -17,6 +13,9 @@ RUN : \
1713
devscripts \
1814
equivs \
1915
lintian \
16+
python3-distutils \
17+
python3-setuptools \
18+
python3-pip \
2019
&& apt-get clean \
2120
&& rm -rf /var/lib/apt/lists/*
2221
WORKDIR /tmp/mnt
@@ -27,5 +26,3 @@ RUN : \
2726
&& mk-build-deps --install --tool 'apt-get -y --no-install-recommends' /control \
2827
&& apt-get clean \
2928
&& rm -rf /var/lib/apt/lists/*
30-
31-
ENTRYPOINT make builddeb

Makefile

+2-22
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ builddeb:
5454
.PHONY: builddeb-docker
5555
builddeb-docker: docker-image
5656
mkdir -p dist
57-
docker run --user $$(id -u):$$(id -g) -v $(PWD):/tmp/mnt dumb-init-build
57+
docker run --init --user $$(id -u):$$(id -g) -v $(PWD):/tmp/mnt dumb-init-build make builddeb
5858

5959
.PHONY: docker-image
6060
docker-image:
61-
docker build -t dumb-init-build .
61+
docker build $(if $(BASE_IMAGE),--build-arg BASE_IMAGE=$(BASE_IMAGE)) -t dumb-init-build .
6262

6363
.PHONY: test
6464
test:
@@ -68,23 +68,3 @@ test:
6868
.PHONY: install-hooks
6969
install-hooks:
7070
tox -e pre-commit -- install -f --install-hooks
71-
72-
ITEST_TARGETS = itest_focal itest_buster
73-
74-
.PHONY: itest $(ITEST_TARGETS)
75-
itest: $(ITEST_TARGETS)
76-
77-
itest_focal: _itest-ubuntu-focal
78-
itest_buster: _itest-debian-buster
79-
80-
itest_tox:
81-
$(DOCKER_RUN_TEST) debian:buster /mnt/ci/docker-tox-test
82-
83-
_itest-%: _itest_deb-% _itest_python-%
84-
@true
85-
86-
_itest_python-%:
87-
$(DOCKER_RUN_TEST) $(shell sed 's/-/:/' <<< "$*") /mnt/ci/docker-python-test
88-
89-
_itest_deb-%: builddeb-docker
90-
$(DOCKER_RUN_TEST) $(shell sed 's/-/:/' <<< "$*") /mnt/ci/docker-deb-test

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
dumb-init
22
========
33

4-
[![Travis CI](https://travis-ci.org/Yelp/dumb-init.svg?branch=master)](https://travis-ci.org/Yelp/dumb-init/)
54
[![PyPI version](https://badge.fury.io/py/dumb-init.svg)](https://pypi.python.org/pypi/dumb-init)
65

76

ci/docker

-18
This file was deleted.

ci/docker-deb-test

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/bin/bash -eux
22
set -o pipefail
33

4-
. /mnt/ci/docker
4+
apt-get update
5+
apt-get -y --no-install-recommends install python3-pip procps
56

7+
cd /mnt
68
dpkg -i dist/*.deb
79
pip3 install -r requirements-dev.txt
810
pytest tests/

ci/docker-python-test

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/bin/bash -eux
2-
set -o pipefail
2+
set -euo pipefail
33

4-
. /mnt/ci/docker
4+
cd /mnt
55

66
python3 setup.py clean
77
python3 setup.py sdist
88
pip3 install -vv dist/*.tar.gz
99
pip3 install -r requirements-dev.txt
10-
pytest tests/
10+
pytest-3 -vv tests/
1111

1212
exec dumb-init /mnt/tests/test-zombies

ci/docker-tox-test

-12
This file was deleted.

pytest.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[pytest]
2-
timeout = 5
2+
timeout = 20

setup.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import print_function
2-
31
import os.path
42
import subprocess
53
import tempfile

testing/__init__.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,16 @@ def child_pids(pid):
5252
for p in LocalPath('/proc').listdir():
5353
try:
5454
stat = open(p.join('stat').strpath).read()
55-
m = re.match(r'^\d+ \(.+?\) [a-zA-Z] (\d+) ', stat)
55+
m = re.match(
56+
r'^\d+ \(.+?\) '
57+
# This field, state, is normally a single letter, but can be
58+
# "0" if there are some unusual security settings that prevent
59+
# reading the process state (happens under GitHub Actions with
60+
# QEMU for some reason).
61+
'[0a-zA-Z] '
62+
r'(\d+) ',
63+
stat,
64+
)
5665
assert m, stat
5766
ppid = int(m.group(1))
5867
if ppid == pid:

testing/print_signals.py

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
Since all signals are printed and otherwise ignored, you'll need to send
55
SIGKILL (kill -9) to this process to actually end it.
66
"""
7-
from __future__ import print_function
8-
97
import os
108
import signal
119
import sys

tests/cli_test.py

+25-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,34 @@ def current_version():
1212
return open('VERSION').read().strip()
1313

1414

15+
def normalize_stderr(stderr):
16+
# dumb-init prints out argv[0] in its usage message. This should always be
17+
# just "dumb-init" under regular test scenarios here since that is how we
18+
# call it, but in CI the use of QEMU causes the argv[0] to be replaced with
19+
# the full path.
20+
#
21+
# This is supposed to be avoidable by:
22+
# 1) Setting the "P" flag in the binfmt register:
23+
# https://en.wikipedia.org/wiki/Binfmt_misc#Registration
24+
# This can be done by setting the QEMU_PRESERVE_PARENT env var when
25+
# calling binfmt.
26+
#
27+
# 2) Setting the "QEMU_ARGV0" env var to empty string for *all*
28+
# processes:
29+
# https://bugs.launchpad.net/qemu/+bug/1835839
30+
#
31+
# I can get it working properly in CI outside of Docker, but for some
32+
# reason not during Docker builds. This doesn't affect the built executable
33+
# so I decided to just punt on it.
34+
return re.sub(rb'(^|(?<=\s))[a-z/.]+/dumb-init', b'dumb-init', stderr)
35+
36+
1537
@pytest.mark.usefixtures('both_debug_modes', 'both_setsid_modes')
1638
def test_no_arguments_prints_usage():
1739
proc = Popen(('dumb-init'), stderr=PIPE)
1840
_, stderr = proc.communicate()
1941
assert proc.returncode != 0
20-
assert stderr == (
42+
assert normalize_stderr(stderr) == (
2143
b'Usage: dumb-init [option] program [args]\n'
2244
b'Try dumb-init --help for full usage.\n'
2345
)
@@ -28,7 +50,7 @@ def test_exits_invalid_with_invalid_args():
2850
proc = Popen(('dumb-init', '--yolo', '/bin/true'), stderr=PIPE)
2951
_, stderr = proc.communicate()
3052
assert proc.returncode == 1
31-
assert stderr in (
53+
assert normalize_stderr(stderr) in (
3254
b"dumb-init: unrecognized option '--yolo'\n", # glibc
3355
b'dumb-init: unrecognized option: yolo\n', # musl
3456
)
@@ -43,7 +65,7 @@ def test_help_message(flag, current_version):
4365
proc = Popen(('dumb-init', flag), stderr=PIPE)
4466
_, stderr = proc.communicate()
4567
assert proc.returncode == 0
46-
assert stderr == (
68+
assert normalize_stderr(stderr) == (
4769
b'dumb-init v' + current_version.encode('ascii') + b'\n'
4870
b'Usage: dumb-init [option] command [[arg] ...]\n'
4971
b'\n'

tests/cwd_test.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import os
22
import shutil
3-
from subprocess import run, PIPE
3+
from subprocess import PIPE
4+
from subprocess import run
45

56
import pytest
67

8+
79
@pytest.mark.usefixtures('both_debug_modes', 'both_setsid_modes')
810
def test_working_directories():
911
"""The child process must start in the working directory in which
@@ -14,9 +16,13 @@ def test_working_directories():
1416
# predictable output - so we can't rely on dumb-init being found
1517
# in the "." directory.
1618
dumb_init = os.path.realpath(shutil.which('dumb-init'))
17-
proc = run((dumb_init,
18-
'sh', '-c', 'readlink /proc/$PPID/cwd && readlink /proc/$$/cwd'),
19-
cwd="/tmp", stdout=PIPE, stderr=PIPE)
19+
proc = run(
20+
(
21+
dumb_init,
22+
'sh', '-c', 'readlink /proc/$PPID/cwd && readlink /proc/$$/cwd',
23+
),
24+
cwd='/tmp', stdout=PIPE, stderr=PIPE,
25+
)
2026

2127
assert proc.returncode == 0
2228
assert proc.stdout == b'/\n/tmp\n'

tox.ini

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py37,gcov
2+
envlist = py38,gcov
33

44
[testenv]
55
deps = -r{toxinidir}/requirements-dev.txt
@@ -8,14 +8,14 @@ commands =
88

99
[testenv:gcov]
1010
skip_install = True
11-
basepython = /usr/bin/python3.7
11+
basepython = /usr/bin/python3.8
1212
commands =
1313
{toxinidir}/ci/gcov-build {envbindir}
1414
{[testenv]commands}
1515
{toxinidir}/ci/gcov-report
1616

1717
[testenv:pre-commit]
18-
basepython = /usr/bin/python3.7
18+
basepython = /usr/bin/python3.8
1919
commands = pre-commit {posargs:run --all-files}
2020

2121
[flake8]

0 commit comments

Comments
 (0)