Compare commits
2 Commits
72f8ea3ed4
...
e4242e3ca7
| Author | SHA1 | Date |
|---|---|---|
|
|
e4242e3ca7 | 7 days ago |
|
|
a168a6f312 | 7 days ago |
6 changed files with 212 additions and 0 deletions
@ -0,0 +1,63 @@ |
|||
.PHONY: all install uninstall pre-requisites clean dryrun |
|||
|
|||
PROJECT_NAME := $(shell basename "$${PWD}") |
|||
QUADLET_FILES = $(wildcard *.container *.volume *.network *.pod *.build) |
|||
SYSTEMD_FILES = $(wildcard *.service *.target *.timer) |
|||
SYSTEMD_UNIT_NAMES := $(wildcard *.service *.target *.timer) |
|||
SYSTEMD_MAIN_UNIT_NAMES := $(wildcard *.target) |
|||
QUADLET_UNIT_NAMES := $(patsubst %.container, %.service, $(wildcard *.container)) \
|
|||
$(patsubst %.volume, %-volume.service, $(wildcard *.volume)) \
|
|||
$(patsubst %.network, %-network.service, $(wildcard *.network)) \
|
|||
$(patsubst %.pod, %-pod.service, $(wildcard *.pod)) \
|
|||
$(patsubst %.build, %-build.service, $(wildcard *.build)) |
|||
CONFIG_FILES = $(wildcard config/*) |
|||
TARGET_QUADLET_FILES = $(addprefix /etc/containers/systemd/, $(QUADLET_FILES)) |
|||
TARGET_SYSTEMD_FILES = $(addprefix /etc/systemd/system/, $(SYSTEMD_FILES)) |
|||
TARGET_CONFIG_FILES = $(patsubst config/%, /etc/quadlets/$(PROJECT_NAME)/%, $(CONFIG_FILES)) |
|||
|
|||
pre-requisites: |
|||
@test "$$(id -u)" -eq 0 || (echo "This Makefile must be run as root" >&2; exit 1) |
|||
|
|||
all: install |
|||
|
|||
dryrun: |
|||
QUADLET_UNIT_DIRS="$$PWD" /usr/lib/systemd/system-generators/podman-system-generator -dryrun > /dev/null |
|||
|
|||
/etc/containers/systemd/%.container: %.container |
|||
install -D -m 0644 -o root -g root $< $@ |
|||
|
|||
/etc/containers/systemd/%.volume: %.volume |
|||
install -D -m 0644 -o root -g root $< $@ |
|||
|
|||
/etc/containers/systemd/%.network: %.network |
|||
install -D -m 0644 -o root -g root $< $@ |
|||
|
|||
/etc/containers/systemd/%.pod: %.pod |
|||
install -D -m 0644 -o root -g root $< $@ |
|||
|
|||
/etc/containers/systemd/%.build: %.build |
|||
install -D -m 0644 -o root -g root $< $@ |
|||
|
|||
/etc/systemd/system/%.service: %.service |
|||
install -D -m 0644 -o root -g root $< $@ |
|||
|
|||
/etc/systemd/system/%.target: %.target |
|||
install -D -m 0644 -o root -g root $< $@ |
|||
|
|||
/etc/quadlets/$(PROJECT_NAME)/%: config/% |
|||
install -D -m 0644 -o root -g root $< $@ |
|||
|
|||
install: pre-requisites dryrun $(TARGET_QUADLET_FILES) $(TARGET_SYSTEMD_FILES) $(TARGET_CONFIG_FILES) |
|||
systemctl daemon-reload |
|||
systemd-analyze --generators=true verify $(QUADLET_UNIT_NAMES) $(SYSTEMD_UNIT_NAMES) |
|||
systemctl enable $(SYSTEMD_UNIT_NAMES) |
|||
systemctl start $(SYSTEMD_MAIN_UNIT_NAMES) |
|||
|
|||
uninstall: pre-requisites |
|||
systemctl --no-block disable $(SYSTEMD_UNIT_NAMES) |
|||
systemctl --no-block stop $(SYSTEMD_UNIT_NAMES) $(QUADLET_UNIT_NAMES) |
|||
rm -f $(TARGET_QUADLET_FILES) $(TARGET_SYSTEMD_FILES) $(TARGET_CONFIG_FILES) |
|||
systemctl daemon-reload |
|||
|
|||
clean: |
|||
rm -rf /var/lib/quadlets/$(PROJECT_NAME)/ /etc/quadlets/$(PROJECT_NAME)/ |
|||
@ -0,0 +1,4 @@ |
|||
GIT_REPO=https://github.com/nmasse-itix/podman-quadlet-cookbook.git |
|||
GIT_BRANCH=main |
|||
NGINX_PORT=80 |
|||
NGINX_HOST=localhost |
|||
@ -0,0 +1,45 @@ |
|||
[Unit] |
|||
Description=Initialize Nginx root directory from a Git repository |
|||
Documentation=https://hub.docker.com/r/alpine/git |
|||
After=network-online.target |
|||
Before=nginx-server.service |
|||
|
|||
# Only start if the service has been configured |
|||
ConditionPathExists=/etc/quadlets/nginx/config.env |
|||
# And if the git repo has NOT been cloned yet |
|||
ConditionPathExists=!/var/lib/quadlets/nginx/.git |
|||
|
|||
# Start/stop this unit when the target is started/stopped |
|||
PartOf=nginx.target |
|||
|
|||
[Container] |
|||
ContainerName=nginx-init-job |
|||
Image=docker.io/alpine/git:latest |
|||
|
|||
# Network configuration |
|||
Network=host |
|||
|
|||
# Those environment variables will be injected by podman into the container |
|||
EnvironmentFile=/etc/quadlets/nginx/config.env |
|||
|
|||
# Clone the website repository |
|||
Exec=clone -b ${GIT_BRANCH} ${GIT_REPO} /var/git |
|||
|
|||
# Volume mounts |
|||
Volume=/var/lib/quadlets/nginx:/var/git:z |
|||
|
|||
[Service] |
|||
Restart=no |
|||
TimeoutStartSec=30 |
|||
|
|||
# These environment variables are sourced to be used by systemd in the Exec* commands |
|||
EnvironmentFile=/etc/quadlets/nginx/config.env |
|||
|
|||
# Skaffold filesystem + fix permissions |
|||
ExecStartPre=install -m 0755 -o root -g root -d /var/lib/quadlets/nginx |
|||
|
|||
# This container is a job - run once to completion |
|||
Type=oneshot |
|||
|
|||
[Install] |
|||
WantedBy=nginx.target |
|||
@ -0,0 +1,45 @@ |
|||
[Unit] |
|||
Description=Nginx HTTP Server |
|||
Documentation=https://hub.docker.com/_/nginx |
|||
After=network.target nginx-init.service nginx-update.service |
|||
Requires=nginx-init.service nginx-update.service |
|||
Before=nginx.target |
|||
|
|||
# Only start if Nginx has been configured |
|||
ConditionPathExists=/etc/quadlets/nginx/config.env |
|||
ConditionPathExists=/var/lib/quadlets/nginx/.git |
|||
|
|||
# Start/stop this unit when the target is started/stopped |
|||
PartOf=nginx.target |
|||
|
|||
[Container] |
|||
ContainerName=nginx-server |
|||
Image=docker.io/library/nginx:mainline-alpine |
|||
|
|||
# Network configuration |
|||
Network=host |
|||
|
|||
# Those environment variables will be injected by podman into the container |
|||
EnvironmentFile=/etc/quadlets/nginx/config.env |
|||
|
|||
# Volume mounts |
|||
Volume=/var/lib/quadlets/nginx/nginx/website:/usr/share/nginx/html:z |
|||
|
|||
# Health check |
|||
HealthCmd=curl -sSf -o /dev/null http://localhost/ |
|||
HealthInterval=30s |
|||
HealthTimeout=10s |
|||
HealthStartPeriod=10s |
|||
HealthRetries=3 |
|||
|
|||
[Service] |
|||
Restart=always |
|||
RestartSec=10 |
|||
TimeoutStartSec=120 |
|||
TimeoutStopSec=30 |
|||
|
|||
# These environment variables are sourced to be used by systemd in the Exec* commands |
|||
EnvironmentFile=/etc/quadlets/nginx/config.env |
|||
|
|||
[Install] |
|||
WantedBy=nginx.target |
|||
@ -0,0 +1,43 @@ |
|||
[Unit] |
|||
Description=Update Nginx root directory from a Git repository |
|||
Documentation=https://hub.docker.com/r/alpine/git |
|||
After=network-online.target |
|||
Before=nginx-server.service |
|||
|
|||
# Only start if the service has been configured |
|||
ConditionPathExists=/etc/quadlets/nginx/config.env |
|||
# And if the git repo has already been cloned |
|||
ConditionPathExists=/var/lib/quadlets/nginx/.git |
|||
|
|||
# Start/stop this unit when the target is started/stopped |
|||
PartOf=nginx.target |
|||
|
|||
[Container] |
|||
ContainerName=nginx-update-job |
|||
Image=docker.io/alpine/git:latest |
|||
|
|||
# Network configuration |
|||
Network=host |
|||
|
|||
# Those environment variables will be injected by podman into the container |
|||
EnvironmentFile=/etc/quadlets/nginx/config.env |
|||
|
|||
# Clone the website repository |
|||
Exec=pull |
|||
WorkingDir=/var/git |
|||
|
|||
# Volume mounts |
|||
Volume=/var/lib/quadlets/nginx:/var/git:z |
|||
|
|||
[Service] |
|||
Restart=no |
|||
TimeoutStartSec=30 |
|||
|
|||
# These environment variables are sourced to be used by systemd in the Exec* commands |
|||
EnvironmentFile=/etc/quadlets/nginx/config.env |
|||
|
|||
# This container is a job - run once to completion |
|||
Type=oneshot |
|||
|
|||
[Install] |
|||
WantedBy=nginx.target |
|||
@ -0,0 +1,12 @@ |
|||
[Unit] |
|||
Description=Nginx Service Target |
|||
Documentation=man:systemd.target(5) |
|||
Wants=nginx-server.service nginx-init.service nginx-update.service |
|||
After=nginx-server.service nginx-init.service nginx-update.service |
|||
# Allow isolation - can stop/start this target independently |
|||
AllowIsolate=yes |
|||
# Only start if Nginx has been configured |
|||
ConditionPathExists=/etc/quadlets/nginx/config.env |
|||
|
|||
[Install] |
|||
WantedBy=multi-user.target |
|||
Loading…
Reference in new issue