Skip to content

Commit

Permalink
Overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
t13a committed Sep 6, 2020
1 parent b460ff8 commit 3129659
Show file tree
Hide file tree
Showing 25 changed files with 88 additions and 206 deletions.
3 changes: 0 additions & 3 deletions .dockerignore

This file was deleted.

5 changes: 5 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ISO_NAME=archlinux-cloud
ISO_LABEL=ARCH_DEVELOP
ISO_VERSION=develop

OUT_DIR=/mnt/out
26 changes: 0 additions & 26 deletions .env.template

This file was deleted.

3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
.env
/out
dist
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
- docker

script:
- make all test
- make

before_deploy:
- export TRAVIS_TAG=$TRAVIS_BRANCH
Expand All @@ -14,7 +14,7 @@ deploy:
api_key:
secure: bAY1lV6dfCKWAwreXCi68s0v6c9LThAgGbksbScTuTJO0f1hrhT6pGNOkG4IMKkaLHdjt3P11NKlutPHYZWpXa+buYv7d6KeWweUI8J441sML5qSXM4yZ2los6pdiRcH0ioKII0Yr1/dZM6a07I9MuWffiqv7dQgZv3YQ5vOc6wb98j5BVoHOyzJF479AK21sOgy4klKglQGQsH/RT6SVJDNx2D41z73sBVmSVJiqebPRHYlUa6dVwBISwcaArmJTkFFlyl7SWplqxJrSsI2dLrBS4Jg22GY0io2lOZI+0Txs61ovJs4zw9kz25qf+mpZMIhb0dqDYdhXoWA6iNv0PUqhMqYi7S2HWh37NX9soNtdkDejAwqRY2jKJVy/jtBPJvnvI/hIXVfKdK0mpJpRnJf0wU5uejPCnrChS/Id0bG8/HEteZWyclD7GFIAxBuPClQRJW9UBJ3p32wkhUd9WrVV993yFtWQ/djsGua0lQeQ8iPJUuUOJODCf1kye3rZqb2dBqXkrnd17ihe+G9WS1hJWkE1nnVySD9ySiVEdZd4iTlJjSPspCgUgYBluaSwa6HiqoGG996+wx159Ord0XAGTC+MoFVU154rkqxc8ASiQ6w0Mi6WN7V0qhQ6+rWVGrdAkduxnH3UDEGFDo/k2Dahvm+PlR/knMMvbovfh8=
file_glob: true
file: out/iso/*.iso
file: dist/*.iso
skip_cleanup: true
on:
all_branches: true
Expand Down
76 changes: 16 additions & 60 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,72 +1,28 @@
PRINT = @echo -e "\e[1;34m"$(1)"\e[0m"
export ISO_NAME := archlinux-cloud
export ISO_LABEL := ARCH_$(shell date +%Y%m)
export ISO_VERSION := $(shell date +%Y.%m.%d)

BUILD_DIR := build
TEST_DIR := test
OUT_DIR := out

export CONTAINER_BUILD_DIR := /mnt/build
export CONTAINER_TEST_DIR := /mnt/test
export CONTAINER_OUT_DIR := /mnt/out

CONTAINER_RUN = docker run \
-e BUILD_DIR=$(CONTAINER_BUILD_DIR) \
-e TEST_DIR=$(CONTAINER_TEST_DIR) \
-e OUT_DIR=$(CONTAINER_OUT_DIR) \
-e PUID=$(shell id -u) \
-e PGID=$(shell id -g) \
-e PUSER=$(1) \
--env-file=$(abspath $(DOTENV)) \
-i \
--privileged \
--rm \
-t \
--tmpfs=/run/shm \
--tmpfs=/tmp:exec \
-v "$(abspath $(2)):$(3)" \
-v "$(abspath $(OUT_DIR)):$(CONTAINER_OUT_DIR)" \
-w "$(3)" \
$(call CONTAINER_IMAGE,$(1))

INIT_FILES :=
CLEAN_FILES := $(OUT_DIR)

include *.mk
DIST_ISO := dist/$(ISO_NAME)-$(ISO_VERSION)-x86_64.iso

.DEFAULT_GOAL := all
.PHONY: all
all: init build

.PHON: init
init: $(INIT_FILES)
all: build test dist

.PHONY: build
build: build/all

.PHONY: build/%
build/%: build-container $(OUT_DIR)
$(call PRINT,Starting build container...)
$(call CONTAINER_RUN,build,$(BUILD_DIR),$(CONTAINER_BUILD_DIR)) make $(MAKEFLAGS) $*
$(call PRINT,Stopped build container)
build:
docker-compose run --rm build sh -c 'sudo chmod 777 $${OUT_DIR} && make'

.PHONY: test
test: test/all

.PHONY: test/%
test/%: test-container $(OUT_DIR)
$(call PRINT,Starting test container...)
$(call CONTAINER_RUN,test,$(TEST_DIR),$(CONTAINER_TEST_DIR)) make $(MAKEFLAGS) $*
$(call PRINT,Stopped test container)
test:
docker-compose run --rm test make

$(OUT_DIR):
$(call PRINT,'Creating directory "$@"...')
mkdir -p $(@)
.PHONY: dist
dist:
mkdir -p $(dir $(DIST_ISO))
docker-compose run --rm build sh -c 'cat $${OUT_DIR}/$(notdir $(DIST_ISO))' > $(DIST_ISO).tmp
mv -f $(DIST_ISO).tmp $(DIST_ISO)

.PHONY: clean
clean:
$(call PRINT,Cleaning...)
docker run \
--rm \
-v "$(abspath .):/mnt" \
-w /mnt \
archlinux \
rm -rf $(CLEAN_FILES)
rm -rf $(dir $(DIST_ISO))
docker-compose down --rmi local -v
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ The build process and E2E tests (using [QEMU](https://www.qemu.org/)) are run en

- Bash
- Docker
- Docker Compose
- GNU Make
- KVM enabled Linux (optional but strongly recommended)

### Build and test the ISO image

The following command generates the ISO image at `out/archlinux-cloud-YYYY.mm.dd-x86_64.iso` then run all E2E tests.
The following command generates the ISO image at `dist/archlinux-cloud-YYYY.mm.dd-x86_64.iso` then run all E2E tests.

```sh
$ make all test
$ make
```

To delete all generated files, run the following command.
Expand Down
1 change: 1 addition & 0 deletions build/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
6 changes: 3 additions & 3 deletions Dockerfile.build → build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN pacman -Syu --noconfirm \
git \
&& pacman -Scc --noconfirm

COPY entrypoint.sh /

ENTRYPOINT ["/entrypoint.sh"]
RUN useradd -m -s /bin/bash -U build \
&& echo "build ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/build

USER build
11 changes: 0 additions & 11 deletions build/Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
PRINT = @echo -e "\e[1;34m"[build] $(1)"\e[0m"

CLEAN_FILES :=

include *.mk

.DEFAULT_GOAL := all
.PHONY: all
all: iso

.PHONY: clean
clean:
sudo rm -rf $(CLEAN_FILES)

.PHONY: exec
exec:
bash

11 changes: 3 additions & 8 deletions build/iso.mk
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
export OUT_ISO_WORK_DIR := $(OUT_DIR)/iso.work
export OUT_ISO := $(OUT_ISO_DIR)/$(ISO_NAME)-$(ISO_VERSION)-x86_64.iso

CLEAN_FILES += \
$(OUT_ISO_WORK_DIR) \
$(OUT_ISO)
OUT_ISO := $(OUT_DIR)/$(ISO_NAME)-$(ISO_VERSION)-x86_64.iso
OUT_ISO_WORK_DIR := $(OUT_DIR)/iso

.PHONY: iso
iso: $(OUT_ISO)

$(OUT_ISO): profile repo
$(call PRINT,Building ISO image...)
sudo mkarchiso \
-o $(OUT_ISO_DIR) \
-o $(OUT_DIR) \
-v \
-w $(OUT_ISO_WORK_DIR) \
$(OUT_PROFILE_DIR)
$(call PRINT,Succeessfully built ISO image)

22 changes: 11 additions & 11 deletions build/profile.mk
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
PROFILE_CHECKSUM_CMD := cd $(PROFILE_SRC_DIR) && find . -type f | sort | xargs sha256sum
PROFILE_MODS := $(shell find $(PROFILE_MOD_DIR) -type f -executable | sort)
RELENG_DIR := /usr/share/archiso/configs/releng

export OUT_PROFILE_DIR := $(OUT_DIR)/profile
PROFILE_CHECKSUM := $(BUILD_DIR)/profile/checksum
PROFILE_CHECKSUM_CMD := cd $(RELENG_DIR) && find . -type f | sort | xargs sha256sum

OUT_PROFILE_MOD_DONE = $(OUT_PROFILE_DIR)/.mod-$(shell basename $(1)).done
PROFILE_MODS := $(shell find $(BUILD_DIR)/profile/mods -type f -executable | sort)

CLEAN_FILES += $(OUT_PROFILE_DIR)
OUT_PROFILE_DIR := $(OUT_DIR)/profile
OUT_PROFILE_MOD_DONE = $(OUT_PROFILE_DIR)/.mod-$(shell basename $(1)).done

.PHONY: profile
profile: $(OUT_PROFILE_DIR)/.done
Expand All @@ -26,16 +27,15 @@ $(eval $(foreach _,$(PROFILE_MODS),$(call PROFILE_MOD_DONE_RULE,$_)))
$(OUT_PROFILE_DIR)/.src.done: profile/verify $(PROFILE_MODS)
$(call PRINT,Copying source profile...)
rm -rf $(@D)
cp -r $(PROFILE_SRC_DIR) $(@D)
cp -r $(RELENG_DIR) $(@D)
mkdir -p $(@D)
touch $@

.PHONY: profile/verify
profile/verify: $(PROFILE_CHECKSUM)
$(PROFILE_CHECKSUM_CMD) | diff $< - || $(PROFILE_CHECKSUM_CMD) > $<.new
$(call PRINT,Verifying source profile...)
$(PROFILE_CHECKSUM_CMD) | diff $< - || sudo sh -c '$(PROFILE_CHECKSUM_CMD) > $<.new'

$(PROFILE_CHECKSUM):
mkdir -p $(@D)
$(PROFILE_CHECKSUM_CMD) > $@.tmp
mv -f $@.tmp $@

$(call PRINT,Creating checksum of source profile...)
sudo sh -c '$(PROFILE_CHECKSUM_CMD) > $@'
7 changes: 0 additions & 7 deletions build/profile/mods/enable-serial-console
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

set -euxo pipefail

# cat << EOF >> airootfs/root/customize_airootfs.sh
#
# sed -i 's/^\(GRUB_CMDLINE_LINUX_DEFAULT\)="\([^"]*\)"/GRUB_TERMINAL=serial\nGRUB_SERIAL_COMMAND="serial --speed=38400 --unit=0 --word=8 --parity=no --stop=1"\n\1="\2 console=tty0 console=ttyS0,38400n8"/g' /etc/default/grub
#
# grub-mkconfig -o /boot/grub/grub.cfg
# EOF

sed -i 's/options \(.*\)/options \1 console=ttyS0,38400/g' efiboot/loader/entries/archiso-x86_64-cd.conf
sed -i 's/options \(.*\)/options \1 console=ttyS0,38400/g' efiboot/loader/entries/archiso-x86_64-usb.conf

Expand Down
6 changes: 2 additions & 4 deletions build/repo.mk
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
REPO_PKGS := $(shell cat $(REPO_PKGS_FILE))
export REPO_NAME := custom
REPO_PKGS := $(shell cat $(BUILD_DIR)/repo/packages)

export OUT_REPO_DIR := $(OUT_DIR)/repo

CLEAN_FILES += $(OUT_REPO_DIR)

.PHONY: repo
repo: $(OUT_REPO_DIR)/.done

Expand Down Expand Up @@ -32,4 +31,3 @@ $$(OUT_REPO_DIR)/$(1)/.done:

endef
$(eval $(foreach _,$(REPO_PKGS),$(call REPO_OUT_PKG_DONE_RULE,$(_))))

10 changes: 0 additions & 10 deletions container.mk

This file was deleted.

30 changes: 30 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: '3'
services:
build:
build: ./build
environment:
BUILD_DIR: /mnt/build
ISO_LABEL: ${ISO_LABEL}
ISO_NAME: ${ISO_NAME}
ISO_VERSION: ${ISO_VERSION}
env_file: .env
privileged: true
volumes:
- ./build:/mnt/build:rw
- out:/mnt/out:rw
working_dir: /mnt/build
test:
build: ./test
environment:
ISO_LABEL: ${ISO_LABEL}
ISO_NAME: ${ISO_NAME}
ISO_VERSION: ${ISO_VERSION}
TEST_DIR: /mnt/test
env_file: .env
privileged: true
volumes:
- ./test:/mnt/test:ro
- out:/mnt/out:rw
working_dir: /mnt/test
volumes:
out:
15 changes: 0 additions & 15 deletions dotenv.mk

This file was deleted.

7 changes: 0 additions & 7 deletions dotenv.sh

This file was deleted.

10 changes: 0 additions & 10 deletions entrypoint.sh

This file was deleted.

1 change: 1 addition & 0 deletions test/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
6 changes: 3 additions & 3 deletions Dockerfile.test → test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN pacman -Syu --noconfirm \
sudo \
&& pacman -Scc --noconfirm

COPY entrypoint.sh /

ENTRYPOINT ["/entrypoint.sh"]
RUN useradd -m -s /bin/bash -U test \
&& echo "test ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/test

USER test
Loading

0 comments on commit 3129659

Please sign in to comment.