Skip to content

Commit

Permalink
Overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
t13a committed May 26, 2020
1 parent 8d7b48a commit a93a70e
Show file tree
Hide file tree
Showing 78 changed files with 453 additions and 1,102 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!entrypoint.sh

29 changes: 29 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
OUT_ISO_DIR=${CONTAINER_OUT_DIR}

# build/iso
ISO_NAME=archlinux-cloud
ISO_VERSION=$(date +%Y.%m.%d)
ISO_LABEL=ARCH_$(date +%Y%m%d)
ISO_PUBLISHER='Tatsuya Kitagawa <https://github.com/t13a/archlinux-cloud>'
ISO_APPLICATION='Arch Linux Cloud Installation Image'
ISO_INSTALL_DIR=

# build/profile
PROFILE_SRC_DIR=/usr/share/archiso/configs/releng
PROFILE_CHECKSUM=${CONTAINER_BUILD_DIR}/profile/checksum
PROFILE_MOD_DIR=${CONTAINER_BUILD_DIR}/profile/mods

# build/repo
REPO_NAME=custom
REPO_PKGS_FILE=${CONTAINER_BUILD_DIR}/repo/packages

# test/cidata
CIDATA_TEMPLATE_DIR=${CONTAINER_TEST_DIR}/cidata

# test/e2e
E2E_CASE_DIR=${CONTAINER_TEST_DIR}/e2e
QEMU_SMP=1
QEMU_MEM=1024
BOOT_TIMEOUT_SECS=1200
CASE_TIMEOUT_SECS=120

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

script:
- make ISO_VERSION=$(date +%Y.%m.%d) build test
- make

deploy:
provider: releases
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/*
file: out/*.iso
skip_cleanup: true
on:
tags: true
Expand Down
13 changes: 13 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM archlinux

RUN pacman -Syu --noconfirm \
&& pacman -S --needed --noconfirm \
base-devel \
archiso \
git \
&& pacman -Scc --noconfirm

COPY entrypoint.sh /

ENTRYPOINT ["/entrypoint.sh"]

11 changes: 1 addition & 10 deletions runner/Dockerfile → Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,7 @@ RUN pacman -Syu --noconfirm \
sudo \
&& pacman -Scc --noconfirm

COPY /rootfs /

VOLUME ["/out", "/work"]

ENV PGID=1000
ENV PUID=1000
ENV PUSER=runner

WORKDIR /test
COPY entrypoint.sh /

ENTRYPOINT ["/entrypoint.sh"]

CMD ["make"]
105 changes: 56 additions & 49 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,71 +1,78 @@
OUT_DIR := out
SRC_DIR := src
PRINT = @echo -e "\e[1;34m"$(1)"\e[0m"

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

ISO_NAME := archlinux-cloud
ISO_VERSION := $(shell date +%Y.%m.%d)
export CONTAINER_BUILD_DIR := /build
export CONTAINER_TEST_DIR := /test
export CONTAINER_OUT_DIR := /out
export CONTAINER_DOTENV := /.env
export CONTAINER_DOTENV_SCRIPT := /dotenv.sh

DOCKER_TAG = archiso-cloud-$(1)
DOCKER_RUN = docker run \
-e ISO_NAME=$(ISO_NAME) \
-e ISO_VERSION=$(ISO_VERSION) \
-e ISO_LABEL=$(ISO_LABEL) \
-e PUBLISHER=$(PUBLISHER) \
-e APPLICATION=$(APPLICATION) \
-e INSTALL_DIR=$(INSTALL_DIR) \
-e WAIT_TIMEOUT_SECS=$(WAIT_TIMEOUT_SECS) \
-e TEST_TIMEOUT_SECS=$(TEST_TIMEOUT_SECS) \
CONTAINER_RUN = docker run \
-e BUILD_DIR=$(CONTAINER_BUILD_DIR) \
-e TEST_DIR=$(CONTAINER_TEST_DIR) \
-e OUT_DIR=$(CONTAINER_OUT_DIR) \
-e DOTENV=$(CONTAINER_DOTENV) \
-e DOTENV_SCRIPT=$(CONTAINER_DOTENV_SCRIPT) \
-e PUID=$(shell id -u) \
-e PGID=$(shell id -g) \
-e PUSER=$(1) \
-i \
--privileged \
--rm \
-t \
--tmpfs=/run/shm \
--tmpfs=/tmp:exec \
-v $(abspath $(2)):$(3) \
-v $(abspath $(WORK_DIR)):/work \
-v $(abspath $(OUT_DIR)):/out \
$(DOCKER_RUN_EXTRA_OPTS) \
$(call DOCKER_TAG,$(1))
-v "$(abspath $(DOTENV)):$(CONTAINER_DOTENV)" \
-v "$(abspath $(DOTENV_SCRIPT)):$(CONTAINER_DOTENV_SCRIPT)" \
-v "$(abspath $(2)):$(3)" \
-v "$(abspath $(OUT_DIR)):$(CONTAINER_OUT_DIR)" \
-w "$(3)" \
$(call CONTAINER_IMAGE,$(1)) \
$(CONTAINER_DOTENV_SCRIPT)

BUILD = $(call DOCKER_RUN,builder,$(SRC_DIR),/src)
RUN = $(call DOCKER_RUN,runner,$(TEST_DIR),/test)
INIT_FILES :=
CLEAN_FILES := $(OUT_DIR)

PRINT = @echo -e "\e[1;34m"$(1)"\e[0m"
include *.mk

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

.PHONY: build
build: build-all
.PHON: init
init: $(INIT_FILES)

.PHONY: test
test: run-all
.PHONY: build
build: build/all

.PHONY: build-%
build-exec: DOCKER_RUN_EXTRA_OPTS = -it
build-%: builder $(OUT_DIR) $(WORK_DIR)
$(call PRINT,Starting builder...)
$(BUILD) make $(@:build-%=%)
$(call PRINT,Stopped builder)
.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)

.PHONY: run-%
run-exec: DOCKER_RUN_EXTRA_OPTS = -it
run-%: runner $(OUT_DIR) $(WORK_DIR)
$(call PRINT,Starting runner...)
$(RUN) make $(@:run-%=%)
$(call PRINT,Stopped runner)
.PHONY: test
test: test/all

.PHONY: builder runner
builder runner:
$(call PRINT,Building Docker image $(call DOCKER_TAG,$@)...)
docker build -t $(call DOCKER_TAG,$@) $@
.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)

$(OUT_DIR) $(WORK_DIR):
$(call PRINT,Creating host directory $(@)...)
mkdir -p $@
$(OUT_DIR):
$(call PRINT,'Creating directory "$@"...')
mkdir -p $(@)

.PHONY: clean
clean:
rm -rf $(OUT_DIR) $(WORK_DIR)
docker rmi -f $(call DOCKER_TAG,builder) $(call DOCKER_TAG,runner)
$(call PRINT,Cleaning...)
docker run \
--rm \
-v "$(abspath .):/work" \
-w /work \
archlinux \
rm -rf $(CLEAN_FILES)
70 changes: 31 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

[![Build Status](https://travis-ci.org/t13a/archlinux-cloud.svg?branch=master)](https://travis-ci.org/t13a/archlinux-cloud)

An [Arch Linux](https://www.archlinux.org) cloud installation image builder.
An [Arch Linux](https://www.archlinux.org) cloud installation image.

- Based on the official Arch Linux ISO profile (`releng`)
- [cloud-init](https://cloud-init.io) installed
- [Predictable network interface names](https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/) disabled
- Serial console enabled
- [Predictable network interface names](https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/) disabled
- Auto login disabled
- Root password locked

Expand All @@ -17,21 +17,21 @@ The build process and E2E tests (using [QEMU](https://www.qemu.org/)) are run en

- Docker
- GNU Make
- KVM enabled Linux (for development, optional but strongly recommended)
- KVM enabled Linux (optional but strongly recommended)

## Getting started

### Build the ISO image
### Build and test the ISO image

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

```
$ make build
```sh
$ make init build test # or just simply `make`
```

To delete all generated files and containers, run the following command.
To delete all generated files, run the following command.

```
```sh
$ make clean
```

Expand All @@ -41,7 +41,7 @@ Please refer to the [official documentation](https://cloudinit.readthedocs.io/)

In Arch Linux, cloud-init 19.1 tries network configuration with [netctl](https://wiki.archlinux.org/index.php/Netctl). However, this does not work well because it has a [bug](https://bugs.launchpad.net/cloud-init/+bug/1714495). As a workaround, the following example shows how to use [systemd-networkd](https://wiki.archlinux.org/index.php/Systemd-networkd) and [systemd-resolved](https://wiki.archlinux.org/index.php/Systemd-resolved) with [`bootcmd` module](https://cloudinit.readthedocs.io/en/latest/topics/modules.html#bootcmd) instead of using normal network configuration.

```
```yaml
#cloud-config
...
bootcmd:
Expand All @@ -60,43 +60,35 @@ bootcmd:

## Development

### E2E test

It is good practice not to include the creation date in the `ISO_VERSION` variable to avoid unintended file name inconsistencies.

```
$ make ISO_VERSION=dev build test
```

### Debugging

#### Build the ISO image step-by-step
### Build the ISO image step-by-step

```
$ make ISO_VERSION=dev build-exec
[builder@ffffffffffff src]$ make archlive # build profile
[builder@ffffffffffff src]$ make repo # build custom repository
[builder@ffffffffffff src]$ make iso # build ISO image
```sh
$ make init
$ make build/exec
[build@xxxxxxxxxxxx build]$ make profile
[build@xxxxxxxxxxxx build]$ make repo
[build@xxxxxxxxxxxx build]$ make iso
[build@xxxxxxxxxxxx build]$ exit
```

#### Run QEMU with the ISO image
### Run QEMU with the ISO image

```
$ make ISO_VERSION=dev run-exec
[runner@ffffffffffff test]$ make cidata # generate cloud-init data source ISO image
[runner@ffffffffffff test]$ qemu-daemon # start QEMU in background
[runner@ffffffffffff test]$ qemu-serial # connect to serial
[runner@ffffffffffff test]$ qemu-monitor # connect to monitor
[runner@ffffffffffff test]$ qemu-ssh # connect to SSH
[runner@ffffffffffff test]$ qemu-kill # stop QEMU
```sh
$ make test/exec
[test@xxxxxxxxxxxx test]$ make ssh-key
[test@xxxxxxxxxxxx test]$ make cidata
[test@xxxxxxxxxxxx test]$ qemu-daemon
[test@xxxxxxxxxxxx test]$ qemu-serial
[test@xxxxxxxxxxxx test]$ qemu-kill
```

or

```
$ make ISO_VERSION=dev run-exec
[runner@ffffffffffff test]$ make cidata
[runner@ffffffffffff test]$ qemu-daemon -f # start QEMU in foreground
```sh
$ make test/exec
[test@xxxxxxxxxxxx test]$ make ssh-key
[test@xxxxxxxxxxxx test]$ make cidata
[test@xxxxxxxxxxxx test]$ qemu-daemon -f # start in foreground
```

## References
Expand Down
18 changes: 18 additions & 0 deletions build/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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

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

CLEAN_FILES += \
$(OUT_ISO_WORK_DIR) \
$(OUT_ISO)

.PHONY: iso
iso: $(OUT_ISO)

$(OUT_ISO): profile repo
$(call PRINT,Building ISO image...)
sudo $(OUT_PROFILE_DIR)/build.sh \
-N $(ISO_NAME) \
-V $(ISO_VERSION) \
$(if $(ISO_LABEL),-L "$(ISO_LABEL)") \
$(if $(ISO_PUBLISHER),-P "$(ISO_PUBLISHER)") \
$(if $(ISO_APPLICATION),-A "$(ISO_APPLICATION)") \
$(if $(ISO_INSTALL_DIR),-D "$(ISO_INSTALL_DIR)") \
-w $(OUT_ISO_WORK_DIR) \
-o $(OUT_ISO_DIR) \
-v
$(call PRINT,Succeessfully built ISO image)

Loading

0 comments on commit a93a70e

Please sign in to comment.