Compare commits

...

8 Commits

10 changed files with 125 additions and 37 deletions
+40 -18
View File
@@ -6,7 +6,7 @@ CPU_ARCH := $(shell lscpu | grep ^Architecture: | sed "s/^Architecture:[[:space:
IMAGE_PREFIX := $(if $(filter armv7%,$(CPU_ARCH)),armv7/) IMAGE_PREFIX := $(if $(filter armv7%,$(CPU_ARCH)),armv7/)
REGISTRY_DOMAIN := git.joeac.net REGISTRY_DOMAIN := git.joeac.net
REGISTRY_USER := joeac REGISTRY_USER := joeac
MODULES := http gemini smtp MODULES := http gemini smtp vaultwarden
############# #############
@@ -38,6 +38,24 @@ $(module)/.env: .env
cp .env $(module)/.env cp .env $(module)/.env
endef endef
define install_module_rule =
.PHONY: install_$(module)
install_$(module): ~/.config/rc/init.d/joeac.net ~/.config/rc/init.d/joeac.net.$(module)
~/.config/rc/init.d/joeac.net.$(module): ~/.config/rc/init.d/joeac.net ~/.config/rc/runlevels/default
ln -s $(shell realpath ~/.config/rc/init.d/joeac.net) ~/.config/rc/init.d/joeac.net.$(module)
rc-update -U add joeac.net.$(module) default
rc-service -U joeac.net.$(module) start
endef
define uninstall_module_rule =
.PHONY: uninstall_$(module)
uninstall_$(module):
rc-service -U joeac.net.$(module) stop
rc-update -U del joeac.net.$(module) default
rm ~/.config/rc/init.d/joeac.net.$(module)
endef
######### #########
# RULES # # RULES #
@@ -55,10 +73,13 @@ login_registry:
podman login $(REGISTRY_DOMAIN) podman login $(REGISTRY_DOMAIN)
.PHONY: install .PHONY: install
install: install_nginx install_service install_crontab next_steps install: install_nginx $(foreach module,$(MODULES),install_$(module)) install_crontab
.PHONY: uninstall .PHONY: uninstall
uninstall: uninstall_nginx uninstall_service uninstall_crontab uninstall: uninstall_nginx uninstall_joeac.net_service $(foreach module,$(MODULES),uninstall_$(module)) uninstall_crontab
.PHONY: uninstall_joeac.net_service
rm ~/.config/rc/joeac.net
nginx_src := $(shell find -L nginx -type f) nginx_src := $(shell find -L nginx -type f)
nginx_target := $(addprefix /etc/,$(nginx_src)) nginx_target := $(addprefix /etc/,$(nginx_src))
@@ -92,21 +113,26 @@ else
sudo rc-service nginx restart sudo rc-service nginx restart
endif endif
.PHONY: install_service $(foreach module,$(MODULES),$(eval $(install_module_rule)))
install_service: ~/.config/rc/init.d/joeac.net $(foreach module,$(MODULES),$(eval $(uninstall_module_rule)))
~/.config/rc/init.d/joeac.net: openrc/joeac.net ~/.config/rc/init.d/joeac.net: openrc/init.d/joeac.net ~/.config/rc/init.d ~/.config/rc/runlevels/default /etc/init.d/user.$(shell whoami) /etc/conf.d/user.$(shell whoami)
rm -f ~/.config/rc/init.d/joeac.net; \ rm -f ~/.config/rc/init.d/joeac.net; \
mkdir -p ~/.config/rc/init.d; \ mkdir -p ~/.config/rc/init.d; \
cp openrc/joeac.net ~/.config/rc/init.d/joeac.net \ cp openrc/init.d/joeac.net ~/.config/rc/init.d/joeac.net
&& rc-update -U add joeac.net default \
&& rc-service -U joeac.net start; \
.PHONY: uninstall_service ~/.config/rc/init.d:
uninstall_service: mkdir -p ~/.config/rc/init.d
rc-service -U joeac.net stop \
&& rc-update -U del joeac.net default \ ~/.config/rc/runlevels/default:
&& rm -f ~/.config/rc/init.d/joeac.net; \ mkdir -p ~/.config/rc/runlevels/default
/etc/init.d/user.$(shell whoami):
sudo ln -s /etc/init.d/user /etc/init.d/user.$(shell whoami)
/etc/conf.d/user.$(shell whoami): openrc/conf.d/user.$(shell whoami)
sudo cp openrc/conf.d/user.$(shell whoami) /etc/conf.d/user.$(shell whoami)
sudo rc-update add user.$(shell whoami) default
.PHONY: install_crontab .PHONY: install_crontab
install_crontab: /etc/periodic/daily/joeac.net install_crontab: /etc/periodic/daily/joeac.net
@@ -120,10 +146,6 @@ uninstall_crontab:
> crontab.tmp > crontab.tmp
sudo mv crontab.tmp /etc/periodic/daily/joeac.net sudo mv crontab.tmp /etc/periodic/daily/joeac.net
.PHONY: next_steps
next_steps:
@echo "Make sure that your user's default runlevel is triggered by OpenRC. If this isn't already happening, edit openrc/user-default-runlevel with your username, copy it to /etc/init.d, and add it to the system's default runlevel with \`rc-service add <SERVICE> default\`."
.PHONY: clean .PHONY: clean
clean: clean:
$(foreach module,$(MODULES),$(MAKE) --directory=$(module) clean;) $(foreach module,$(MODULES),$(MAKE) --directory=$(module) clean;)
+14
View File
@@ -1,6 +1,7 @@
services: services:
gemini: gemini:
image: git.joeac.net/joeac/joeac.net-gemini image: git.joeac.net/joeac/joeac.net-gemini
container_name: joeac.net-gemini
build: build:
context: . context: .
dockerfile: gemini.Dockerfile dockerfile: gemini.Dockerfile
@@ -9,6 +10,7 @@ services:
http: http:
image: git.joeac.net/joeac/joeac.net-http image: git.joeac.net/joeac/joeac.net-http
container_name: joeac.net-http
build: build:
context: . context: .
dockerfile: http.Dockerfile dockerfile: http.Dockerfile
@@ -19,6 +21,7 @@ services:
smtp: smtp:
image: git.joeac.net/joeac/joeac.net-smtp image: git.joeac.net/joeac/joeac.net-smtp
container_name: joeac.net-smtp
build: build:
context: . context: .
dockerfile: smtp.Dockerfile dockerfile: smtp.Dockerfile
@@ -34,6 +37,17 @@ services:
secrets: secrets:
- remote_smtp_password - remote_smtp_password
vaultwarden:
image: docker.io/vaultwarden/server:latest
container_name: joeac.net-vaultwarden
restart: unless-stopped
environment:
DOMAIN: "https://pwd.joeac.net"
volumes:
- ./vaultwarden/vw-data/:/data/
ports:
- "9000:80"
secrets: secrets:
remote_smtp_password: remote_smtp_password:
external: true external: true
-1
View File
@@ -1 +0,0 @@
/home/broughton/.config/nginx/http.d
+27
View File
@@ -0,0 +1,27 @@
server {
server_name joeac.net;
location / {
proxy_pass http://127.0.0.1:8080;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/joeac.net-0001/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/joeac.net-0001/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = joeac.net) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
listen [::]:80 default_server;
server_name joeac.net;
return 404; # managed by Certbot
}
+23
View File
@@ -0,0 +1,23 @@
server {
server_name pwd.joeac.net;
location / {
proxy_pass http://localhost:9000;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/pwd.joeac.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/pwd.joeac.net/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = pwd.joeac.net) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name pwd.joeac.net;
listen 80;
return 404; # managed by Certbot
}
+3
View File
@@ -0,0 +1,3 @@
*
!.gitignore
!user.example
+3
View File
@@ -0,0 +1,3 @@
# copy this file to user.<USER> for the user you want to be running joeac.net via OpenRC
# add in here any user setup, bearing in mind that OpenRC doesn't use your usual login flow
# this may include setting up $HOME and/or $XDG_RUNTIME_DIR
+14 -12
View File
@@ -3,10 +3,11 @@
# https://gist.github.com/itzwam/2069e935385193207f7e5bea7156e21d # https://gist.github.com/itzwam/2069e935385193207f7e5bea7156e21d
# https://github.com/0x17de/dockerservice-openrc # https://github.com/0x17de/dockerservice-openrc
: ${MODULENAME:=${RC_SVCNAME##*.}}
: ${SRCDIR:=/usr/local/lib/joeac.net} : ${SRCDIR:=/usr/local/lib/joeac.net}
DOCKER_COMPOSE_UP_ARGS=${DOCKER_COMPOSE_UP_ARGS-"--no-build --no-recreate --no-deps"} DOCKER_COMPOSE_UP_ARGS=${DOCKER_COMPOSE_UP_ARGS-"--no-build --no-recreate --no-deps"}
[ -z "${SVCNAME}" ] && exit 1 [ -z "${MODULENAME}" ] && exit 1
: ${COMPOSEFILE:="${SRCDIR}/compose.yml"} : ${COMPOSEFILE:="${SRCDIR}/compose.yml"}
: ${MAKEFILE:="${SRCDIR}/Makefile"} : ${MAKEFILE:="${SRCDIR}/Makefile"}
COMPOSECMD="/usr/bin/podman-compose" COMPOSECMD="/usr/bin/podman-compose"
@@ -31,14 +32,14 @@ configtest() {
start() { start() {
configtest || return 1 configtest || return 1
ebegin "Starting ${SVCNAME}" ebegin "Starting ${MODULENAME}"
"${COMPOSECMD}" -f "${COMPOSEFILE}" up -d ${DOCKER_COMPOSE_UP_ARGS} "${COMPOSECMD}" -f "${COMPOSEFILE}" up -d ${DOCKER_COMPOSE_UP_ARGS} ${MODULENAME}
eend $? eend $?
} }
stop() { stop() {
ebegin "Stopping ${SVCNAME}" ebegin "Stopping ${MODULENAME}"
"${COMPOSECMD}" -f "${COMPOSEFILE}" down --timeout=5 "${COMPOSECMD}" -f "${COMPOSEFILE}" down --timeout=5 ${MODULENAME}
eend $? eend $?
} }
@@ -46,18 +47,19 @@ status() {
pods=0 pods=0
started=0 started=0
while read pod; do while read pod; do
pod_service="$(podman inspect $pod | jq .[0].Config.Labels.[\"com.docker.compose.service\"])"
if ! [ "$pod_service" = "\"${MODULENAME}\"" ]; then
continue
fi
pods=$(($pods+1)) pods=$(($pods+1))
if podman top $pod &>/dev/null; then if podman top $pod &>/dev/null; then
einfo "status: [$pod] started" einfo "status: [$pod] started"
started=$(($started+1)) exit 0
else else
einfo "status: [$pod] stopped" einfo "status: [$pod] stopped"
exit 3
fi fi
done < <("${COMPOSECMD}" -f "${COMPOSEFILE}" ps --quiet) done < <("${COMPOSECMD}" -f "${COMPOSEFILE}" ps --quiet)
if [ $started -eq $pods ]; then einfo "status: no container found for ${MODULENAME}"
einfo "status: started" exit 3
else
einfo "status: stopped"
return 3
fi
} }
-6
View File
@@ -1,6 +0,0 @@
#!/sbin/openrc
description="start <USER> default runlevel"
command="openrc"
command_args="-U default"
command_user="<USER>"
Submodule
+1
Submodule vaultwarden added at 19c0baa183