Skip to content

Commit

Permalink
testing: Refactor Dockerfile (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
nuta authored Dec 23, 2021
1 parent 8c7e3c8 commit a0446f3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
jobs:
build_and_test:
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
Expand Down
23 changes: 15 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ endif

# $(IMAGE): Use a Docker image for initramfs.
ifeq ($(IMAGE),)
INITRAMFS_PATH := build/kerla.initramfs
INITRAMFS_PATH := build/testing.initramfs
export INIT_SCRIPT := /bin/sh
else
IMAGE_FILENAME := $(subst /,.s,$(IMAGE))
INITRAMFS_PATH := build/$(IMAGE_FILENAME).initramfs
export INIT_SCRIPT := $(shell tools/inspect-init-in-docker-image.py $(IMAGE))
endif

DUMMY_INITRAMFS_PATH := build/dummy-for-lint.initramfs

# Set the platform name for docker image cross compiling.
ifeq ($(ARCH),x64)
docker_platform = linux/amd64
Expand Down Expand Up @@ -137,9 +139,8 @@ testw:

.PHONY: check
check:
mkdir -p $(dir $(INITRAMFS_PATH))
touch $(INITRAMFS_PATH)
$(CARGO) check $(CARGOFLAGS)
$(MAKE) $(DUMMY_INITRAMFS_PATH)
INITRAMFS_PATH=$(DUMMY_INITRAMFS_PATH) $(CARGO) check $(CARGOFLAGS)

.PHONY: checkw
checkw:
Expand All @@ -166,15 +167,18 @@ src-docs:

.PHONY: lint
lint:
RUSTFLAGS="-C panic=abort -Z panic_abort_tests" $(CARGO) clippy
$(MAKE) $(DUMMY_INITRAMFS_PATH)
INITRAMFS_PATH=$(DUMMY_INITRAMFS_PATH) RUSTFLAGS="-C panic=abort -Z panic_abort_tests" $(CARGO) clippy

.PHONY: strict-lint
strict-lint:
RUSTFLAGS="-C panic=abort -Z panic_abort_tests" $(CARGO) clippy -- -D warnings
$(MAKE) $(DUMMY_INITRAMFS_PATH)
INITRAMFS_PATH=$(DUMMY_INITRAMFS_PATH) RUSTFLAGS="-C panic=abort -Z panic_abort_tests" $(CARGO) clippy -- -D warnings

.PHONY: lint-and-fix
lint-and-fix:
RUSTFLAGS="-C panic=abort -Z panic_abort_tests" $(CARGO) clippy --fix -Z unstable-options
$(MAKE) $(DUMMY_INITRAMFS_PATH)
INITRAMFS_PATH=$(DUMMY_INITRAMFS_PATH) RUSTFLAGS="-C panic=abort -Z panic_abort_tests" $(CARGO) clippy --fix -Z unstable-options

.PHONY: print-stack-sizes
print-stack-sizes: build
Expand All @@ -188,7 +192,7 @@ clean:
#
# Build Rules
#
build/kerla.initramfs: $(wildcard testing/*) $(wildcard testing/*/*) Makefile
build/testing.initramfs: $(wildcard testing/*) $(wildcard testing/*/*) Makefile
$(PROGRESS) "BUILD" testing
cd testing && docker buildx build --platform $(docker_platform) -t kerla-testing .
$(PROGRESS) "EXPORT" testing
Expand All @@ -200,6 +204,9 @@ build/$(IMAGE_FILENAME).initramfs: tools/docker2initramfs.py Makefile
mkdir -p build
$(PYTHON3) tools/docker2initramfs.py $@ $(IMAGE)

$(DUMMY_INITRAMFS_PATH):
touch $@

%.svg: %.drawio
$(PROGRESS) "DRAWIO" $@
$(DRAWIO) -x -f svg -o $@ $<
8 changes: 7 additions & 1 deletion testing/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@ FROM busybox as empty_dir
RUN mkdir /empty_dir

FROM scratch

# Directories to be populated by "busybox --install -s".
COPY --from=empty_dir /empty_dir /bin
COPY --from=empty_dir /empty_dir /sbin
COPY --from=empty_dir /empty_dir /usr/bin
COPY --from=empty_dir /empty_dir /usr/sbin

COPY --from=busybox /build/busybox_unstripped /bin/busybox
COPY --from=dropbear /build/dropbear /build/dropbearkey /bin
COPY --from=curl /build/src/curl /bin

RUN ["/bin/busybox", "--install", "-s"]
RUN mkdir -p /bin /sbin /usr/bin /usr/sbin /etc /dev /tmp /var/www/html
RUN mkdir -p /etc /dev /tmp /var/www/html
ADD etc/banner /etc
ADD etc/group /etc
ADD etc/passwd /etc
Expand Down

0 comments on commit a0446f3

Please sign in to comment.