Skip to content

Commit

Permalink
refactor(build): generalize container images
Browse files Browse the repository at this point in the history
  • Loading branch information
rudenkornk committed Apr 30, 2024
1 parent ecb7550 commit 7c4deb4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .ansible-lint
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extra_vars:
hosts_var: localhost
ubuntu_tag: 22.04
container: dotfiles_ubuntu_22.04
image: ubuntu:22.04
user: root

enable_list:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defaults:
jobs:
check_container:
env:
UBUNTU_TAG: ${{ matrix.ubuntu_tag }}
IMAGE: ${{ matrix.image }}
USER: random_user
runs-on: ubuntu-22.04
steps:
Expand All @@ -25,7 +25,7 @@ jobs:
! (grep -oP "changed=\d+" __build__/log | grep -oPq "changed=[1-9]")
strategy:
matrix:
ubuntu_tag: ["22.04", "23.04", "23.10", "24.04"]
image: ["ubuntu:22.04", "ubuntu:23.04", "ubuntu:23.10", "ubuntu:24.04"]

check_locahost:
runs-on: ubuntu-22.04
Expand Down
10 changes: 5 additions & 5 deletions inventory.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ all:
localhost:
ansible_connection: local
trusted: true
dotfiles_22.04:
dotfiles_ubuntu_22.04:
ansible_connection: podman
ansible_python_interpreter: auto_silent
trusted: true
dotfiles_22.10:
dotfiles_ubuntu_22.10:
ansible_connection: podman
ansible_python_interpreter: auto_silent
trusted: true
dotfiles_23.04:
dotfiles_ubuntu_23.04:
ansible_connection: podman
ansible_python_interpreter: auto_silent
trusted: true
dotfiles_23.10:
dotfiles_ubuntu_23.10:
ansible_connection: podman
ansible_python_interpreter: auto_silent
trusted: true
dotfiles_24.04:
dotfiles_ubuntu_24.04:
ansible_connection: podman
ansible_python_interpreter: auto_silent
trusted: true
15 changes: 8 additions & 7 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ config: $(BUILD_DIR)/bootstrap_control_node
sudo bash -c ''; \
fi
if [[ "$(HOSTS)" =~ ^dotfiles_ ]]; then \
$(VENV) && ansible-playbook --extra-vars "ubuntu_tag=$(UBUNTU_TAG)" \
$(VENV) && ansible-playbook --extra-vars "container=$(HOSTS) image=$(IMAGE)" \
--inventory inventory.yaml playbook_dotfiles_container.yaml; \
fi
$(VENV) && ansible-playbook --extra-vars "hosts_var=$(HOSTS)" \
Expand Down Expand Up @@ -52,7 +52,8 @@ hooks: .git/hooks/pre-commit


############################## Checks ##############################
UBUNTU_TAG ?= 22.04
IMAGE ?= ubuntu:22.04
CONTAINER := dotfiles_$(subst :,_,$(IMAGE))

.PHONY: check
check: \
Expand Down Expand Up @@ -86,18 +87,18 @@ lint: $(BUILD_DIR)/bootstrap_control_node

.PHONY: check_host
check_host: $(BUILD_DIR)/bootstrap_control_node
make HOSTS=dotfiles_$(UBUNTU_TAG) config
make HOSTS=$(CONTAINER) config

.PHONY: check_bootstrap_control_node
check_bootstrap_control_node: $(BUILD_DIR)/$(UBUNTU_TAG)/bootstrap_control_node
check_bootstrap_control_node: $(BUILD_DIR)/$(CONTAINER)/bootstrap_control_node

$(BUILD_DIR)/$(UBUNTU_TAG)/bootstrap_control_node: $(BUILD_DIR)/bootstrap_control_node
$(BUILD_DIR)/$(CONTAINER)/bootstrap_control_node: $(BUILD_DIR)/bootstrap_control_node
podman run --rm --interactive --tty \
--mount=type=bind,source=$$(pwd),target=$$(pwd) \
--workdir $$(pwd) ubuntu:$(UBUNTU_TAG) bash -c \
--workdir $$(pwd) $(IMAGE) bash -c \
' \
apt-get update && apt-get install make --yes --no-install-recommends && \
make BUILD_DIR=$(BUILD_DIR)/$(UBUNTU_TAG) $(BUILD_DIR)/$(UBUNTU_TAG)/bootstrap_control_node \
make BUILD_DIR=$(BUILD_DIR)/$(CONTAINER) $(BUILD_DIR)/$(CONTAINER)/bootstrap_control_node \
'


Expand Down
6 changes: 3 additions & 3 deletions playbook_dotfiles_container.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
- name: Create test linux container
hosts: localhost
tasks:
- name: Spin up dotfiles_{{ ubuntu_tag }}
- name: Spin up {{ container }}
containers.podman.podman_container:
name: dotfiles_{{ ubuntu_tag }}
image: ubuntu:{{ ubuntu_tag }}
name: "{{ container }}"
image: "{{ image }}"
interactive: true
privileged: true
tty: true
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ make graph
## Test

```bash
make check UBUNTU_TAG=22.04
make check IMAGE=ubuntu:22.04
```

0 comments on commit 7c4deb4

Please sign in to comment.