# set podman-compliant container management CLI binary
PODMAN=podman
# set fun names for the containers
HUTTESE_POD=podracing
HUTTESE_SRHT=huttsr
HUTTESE_REDIS=huttredis
HUTTESE_POSTGRES=huttpg
# configure redis
REDIS_TARGET=docker.io/library/redis:alpine3.15
REDIS_LOCALNAME=my-redis
REDIS_DATADIR=/var/deploy/data/redis
# configure postgres
POSTGRES_TARGET=docker.io/library/postgres:alpine3.15
POSTGRES_LOCALNAME=my-postgres
POSTGRES_DATADIR=/var/deploy/data/postgres
POSTGRES_CONF=/var/deploy/conf/postgres/postgresql.conf
# configure git
GIT_DATADIR=/var/deploy/data/git
# set image tag data
SRHT_LOCALNAME=srht
SRHT_LOCALVERSION=1
CERTDIR=/var/deploy/certs
pod:
$(PODMAN) pod exists $(HUTTESE_POD) >/dev/null 2>&1 \
|| $(PODMAN) pod create --name $(HUTTESE_POD) \
--add-host=tatooine:127.0.0.1 \
--add-host=dominic-ricottone.com:127.0.0.1 \
--add-host=meta.dominic-ricottone.com:127.0.0.1 \
--add-host=git.dominic-ricottone.com:127.0.0.1 \
--add-host=todo.dominic-ricottone.com:127.0.0.1 \
--publish 0.0.0.0:80:80 --publish 0.0.0.0:443:443
cleanup:
$(PODMAN) rm --force $(HUTTESE_REDIS) >/dev/null 2>&1 || true
$(PODMAN) image rm --force $(REDIS_LOCALNAME):latest >/dev/null 2>&1 || true
$(PODMAN) rm --force $(HUTTESE_POSTGRES) >/dev/null 2>&1 || true
$(PODMAN) image rm --force $(POSTGRES_LOCALNAME):latest >/dev/null 2>&1 || true
setup: pod
$(PODMAN) inspect $(REDIS_LOCALNAME) >/dev/null 2>&1 \
|| $(PODMAN) pull $(REDIS_TARGET) \
&& $(PODMAN) tag $(REDIS_TARGET) $(REDIS_LOCALNAME)
$(PODMAN) run --detach --name $(HUTTESE_REDIS) --restart always \
--pod podracing \
$(REDIS_LOCALNAME)
#if I need persistence later:
# --mount type=bind,src=$(REDIS_DATADIR),dst=/data \
# $(REDIS_LOCALNAME) redis-server --save 60 1 --loglevel warning
# redis is now available at redis://localhost:6379
$(PODMAN) inspect $(POSTGRES_LOCALNAME) >/dev/null 2>&1 \
|| $(PODMAN) pull $(POSTGRES_TARGET) \
&& $(PODMAN) tag $(POSTGRES_TARGET) $(POSTGRES_LOCALNAME)
$(PODMAN) run --detach --name $(HUTTESE_POSTGRES) --restart always \
--env POSTGRES_HOST_AUTH_METHOD=trust \
--pod podracing \
--mount type=bind,src=$(POSTGRES_DATADIR),dst=/var/lib/postgresql/data,Z \
--mount type=bind,src=$(POSTGRES_CONF),dst=/etc/postgresql/postgresql.conf,Z \
$(POSTGRES_LOCALNAME) -c 'config_file=/etc/postgresql/postgresql.conf'
# postgres is now available at postgresql://postgres@localhost:5432
image:
# these are only necessary if on aarch64
cp -r /var/deploy/build/huttese-apk/pkg sr/pkg
cp -r /var/deploy/build/huttese-apk/keys sr/etc/apk/keys
$(PODMAN) inspect $(SRHT_LOCALNAME) >/dev/null 2>&1 \
|| $(PODMAN) build \
--tag $(SRHT_LOCALNAME):latest \
--tag $(SRHT_LOCALNAME):$(SRHT_LOCALVERSION) \
sr/
rm -rf sr/pkg sr/etc/apk/keys
dbinit: pod image
$(PODMAN) inspect -f '{{.State.Running}}' $(HUTTESE_POSTGRES) >/dev/null 2>&1
$(PODMAN) exec $(HUTTESE_POSTGRES) \
createdb -U postgres meta.sr.ht
$(PODMAN) exec $(HUTTESE_POSTGRES) \
createdb -U postgres git.sr.ht
$(PODMAN) exec $(HUTTESE_POSTGRES) \
createdb -U postgres todo.sr.ht
$(PODMAN) run --name $(HUTTESE_SRHT)_dbinit --rm \
--pod podracing \
$(SRHT_LOCALNAME) metasrht-initdb
$(PODMAN) run --name $(HUTTESE_SRHT)_dbinit --rm \
--pod podracing \
$(SRHT_LOCALNAME) gitsrht-initdb
$(PODMAN) run --name $(HUTTESE_SRHT)_dbinit --rm \
--pod podracing \
$(SRHT_LOCALNAME) todosrht-initdb
dbmigrate: pod image
$(PODMAN) inspect $(HUTTESE_NETWORK) >/dev/null 2>&1
$(PODMAN) inspect -f '{{.State.Running}}' $(HUTTESE_POSTGRES) >/dev/null 2>&1
$(PODMAN) run --name $(HUTTESE_SRHT)_dbmigrate --rm \
--pod podracing \
$(SRHT_LOCALNAME) srht-migrate meta.sr.ht -a upgrade head
$(PODMAN) run --name $(HUTTESE_SRHT)_dbmigrate --rm \
--pod podracing \
$(SRHT_LOCALNAME) metasrht-migrate -a upgrade head
$(PODMAN) run --name $(HUTTESE_SRHT)_dbmigrate --rm \
--pod podracing \
$(SRHT_LOCALNAME) srht-migrate git.sr.ht -a upgrade head
$(PODMAN) run --name $(HUTTESE_SRHT)_dbmigrate --rm \
--pod podracing \
$(SRHT_LOCALNAME) gitsrht-migrate -a upgrade head
$(PODMAN) run --name $(HUTTESE_SRHT)_dbmigrate --rm \
--pod podracing \
$(SRHT_LOCALNAME) srht-migrate todo.sr.ht -a upgrade head
$(PODMAN) run --name $(HUTTESE_SRHT)_dbmigrate --rm \
--pod podracing \
$(SRHT_LOCALNAME) todosrht-migrate -a upgrade head
start: pod image
$(PODMAN) inspect -f '{{.State.Running}}' $(HUTTESE_POSTGRES) >/dev/null 2>&1
$(PODMAN) inspect -f '{{.State.Running}}' $(HUTTESE_REDIS) >/dev/null 2>&1
$(PODMAN) run --detach --name $(HUTTESE_SRHT) --restart always \
--pod podracing \
--mount type=bind,src=$(GIT_DATADIR),dst=/var/lib/git,Z \
--mount type=bind,src=$(CERTDIR),dst=/var/lets-encrypt,Z \
$(SRHT_LOCALNAME)
USER_EMAIL?=
USER_NAME?=
adduser:
$(PODMAN) inspect -f '{{.State.Running}}' $(HUTTESE_POSTGRES) >/dev/null 2>&1
$(PODMAN) inspect -f '{{.State.Running}}' $(HUTTESE_REDIS) >/dev/null 2>&1
@echo "USAGE: USER_EMAIL=me@example.com USER_NAME=me make adduser"
$(PODMAN) exec -it $(HUTTESE_SRHT) metasrht-manageuser -e $(USER_EMAIL) -t admin $(USER_NAME)
shell:
$(PODMAN) inspect -f '{{.State.Running}}' $(HUTTESE_POSTGRES) >/dev/null 2>&1
$(PODMAN) inspect -f '{{.State.Running}}' $(HUTTESE_REDIS) >/dev/null 2>&1
$(PODMAN) exec -it $(HUTTESE_SRHT) sh
stop:
$(PODMAN) stop $(HUTTESE_SRHT)
restart:
$(PODMAN) inspect -f '{{.State.Running}}' $(HUTTESE_POSTGRES) >/dev/null 2>&1
$(PODMAN) inspect -f '{{.State.Running}}' $(HUTTESE_REDIS) >/dev/null 2>&1
$(PODMAN) restart $(HUTTESE_SRHT)
clean:
$(PODMAN) rm --force $(HUTTESE_SRHT) >/dev/null 2>&1 || true
$(PODMAN) image rm --force $(SRHT_LOCALNAME):latest >/dev/null 2>&1 || true