# set docker-compliant container management CLI binary
CONMAN=docker
# set fun names for the containers
HUTTESE_NETWORK=holonet
HUTTESE_SRHT=huttsr
HUTTESE_REDIS=huttredis
HUTTESE_POSTGRES=huttpg
# configure redis
REDIS_TARGET=redis:alpine3.15
REDIS_LOCALNAME=my-redis
REDIS_DATADIR=/var/deploy/data/redis
# configure postgres
POSTGRES_TARGET=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
keys:
ssh-keygen -A -f etc/ssh/
databases:
$(CONMAN) inspect $(HUTTESE_NETWORK) >/dev/null 2>&1
$(CONMAN) inspect -f '{{.State.Running}}' $(HUTTESE_POSTGRES) >/dev/null 2>&1
$(CONMAN) inspect -f '{{.State.Running}}' $(HUTTESE_REDIS) >/dev/null 2>&1
cleanup:
$(CONMAN) network disconnect --force $(HUTTESE_NETWORK) $(HUTTESE_REDIS) >/dev/null 2>&1 || true
$(CONMAN) rm --force $(HUTTESE_REDIS) >/dev/null 2>&1 || true
$(CONMAN) image rm --force $(REDIS_LOCALNAME):latest >/dev/null 2>&1 || true
$(CONMAN) network disconnect --force $(HUTTESE_NETWORK) $(HUTTESE_POSTGRES) >/dev/null 2>&1 || true
$(CONMAN) rm --force $(HUTTESE_POSTGRES) >/dev/null 2>&1 || true
$(CONMAN) image rm --force $(POSTGRES_LOCALNAME):latest >/dev/null 2>&1 || true
setup:
$(CONMAN) inspect $(HUTTESE_NETWORK) >/dev/null 2>&1 \
|| $(CONMAN) network create $(HUTTESE_NETWORK)
$(CONMAN) inspect $(REDIS_LOCALNAME) >/dev/null 2>&1 \
|| $(CONMAN) pull $(REDIS_TARGET) \
&& $(CONMAN) tag $(REDIS_TARGET) $(REDIS_LOCALNAME)
$(CONMAN) run --detach --name $(HUTTESE_REDIS) --restart always \
$(REDIS_LOCALNAME)
$(CONMAN) network connect --alias $(HUTTESE_REDIS) \
$(HUTTESE_NETWORK) $(HUTTESE_REDIS)
$(CONMAN) inspect $(POSTGRES_LOCALNAME) >/dev/null 2>&1 \
|| $(CONMAN) pull $(POSTGRES_TARGET) \
&& $(CONMAN) tag $(POSTGRES_TARGET) $(POSTGRES_LOCALNAME)
$(CONMAN) run --detach --name $(HUTTESE_POSTGRES) --restart always \
--env POSTGRES_HOST_AUTH_METHOD=trust \
--mount type=bind,src=$(POSTGRES_DATADIR),dst=/var/lib/postgresql/data \
--mount type=bind,src=$(POSTGRES_CONF),dst=/etc/postgresql/postgresql.conf \
$(POSTGRES_LOCALNAME) -c 'config_file=/etc/postgresql/postgresql.conf'
$(CONMAN) network connect --alias $(HUTTESE_POSTGRES) \
$(HUTTESE_NETWORK) $(HUTTESE_POSTGRES)
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
$(CONMAN) inspect $(SRHT_LOCALNAME) >/dev/null 2>&1 \
|| $(CONMAN) build \
--tag $(SRHT_LOCALNAME):latest \
--tag $(SRHT_LOCALNAME):$(SRHT_LOCALVERSION) \
sr/
# again, only necessary if on aarch64
rm -rf sr/pkg sr/etc/apk/keys
dbinit: databases image
$(CONMAN) exec $(HUTTESE_POSTGRES) \
createdb -U postgres meta.sr.ht
$(CONMAN) exec $(HUTTESE_POSTGRES) \
createdb -U postgres git.sr.ht
$(CONMAN) exec $(HUTTESE_POSTGRES) \
createdb -U postgres todo.sr.ht
$(CONMAN) run --name $(HUTTESE_SRHT)_dbinit --rm \
--network $(HUTTESE_NETWORK) \
$(SRHT_LOCALNAME) metasrht-initdb
$(CONMAN) run --name $(HUTTESE_SRHT)_dbinit --rm \
--network $(HUTTESE_NETWORK) \
$(SRHT_LOCALNAME) gitsrht-initdb
$(CONMAN) run --name $(HUTTESE_SRHT)_dbinit --rm \
--network $(HUTTESE_NETWORK) \
$(SRHT_LOCALNAME) todosrht-initdb
dbmigrate: databases image
$(CONMAN) run --name $(HUTTESE_SRHT)_dbmigrate --rm \
--network $(HUTTESE_NETWORK) \
$(SRHT_LOCALNAME) srht-migrate meta.sr.ht -a upgrade head
$(CONMAN) run --name $(HUTTESE_SRHT)_dbmigrate --rm \
--network $(HUTTESE_NETWORK) \
$(SRHT_LOCALNAME) metasrht-migrate -a upgrade head
$(CONMAN) run --name $(HUTTESE_SRHT)_dbmigrate --rm \
--network $(HUTTESE_NETWORK) \
$(SRHT_LOCALNAME) srht-migrate git.sr.ht -a upgrade head
$(CONMAN) run --name $(HUTTESE_SRHT)_dbmigrate --rm \
--network $(HUTTESE_NETWORK) \
$(SRHT_LOCALNAME) gitsrht-migrate -a upgrade head
$(CONMAN) run --name $(HUTTESE_SRHT)_dbmigrate --rm \
--network $(HUTTESE_NETWORK) \
$(SRHT_LOCALNAME) srht-migrate todo.sr.ht -a upgrade head
$(CONMAN) run --name $(HUTTESE_SRHT)_dbmigrate --rm \
--network $(HUTTESE_NETWORK) \
$(SRHT_LOCALNAME) todosrht-migrate -a upgrade head
start: databases image
$(CONMAN) run --detach --name $(HUTTESE_SRHT) --restart always \
--hostname tatooine \
--hostname dominic-ricottone.com \
--hostname meta.dominic-ricottone.com \
--hostname git.dominic-ricottone.com \
--hostname todo.dominic-ricottone.com \
--publish 0.0.0.0:80:80 --publish 0.0.0.0:443:443 --publish 0.0.0.0:8822:22 \
--mount type=bind,src=$(GIT_DATADIR),dst=/var/lib/git \
--mount type=bind,src=$(CERTDIR),dst=/var/lets-encrypt \
$(SRHT_LOCALNAME)
$(CONMAN) network connect --alias $(HUTTESE_SRHT) \
$(HUTTESE_NETWORK) $(HUTTESE_SRHT)
USER_EMAIL?=
USER_NAME?=
adduser: databases
$(CONMAN) exec -it $(HUTTESE_SRHT) metasrht-manageuser -e $(USER_EMAIL) -t active_free $(USER_NAME) \
|| echo "USAGE: USER_EMAIL=me@example.com USER_NAME=me make adduser"
addadmin: databases
$(CONMAN) exec -it $(HUTTESE_SRHT) metasrht-manageuser -e $(USER_EMAIL) -t admin $(USER_NAME) \
|| echo "USAGE: USER_EMAIL=me@example.com USER_NAME=me make adduser"
shell:
$(CONMAN) exec -it $(HUTTESE_SRHT) sh
psql: databases
$(CONMAN) exec -it huttpg psql --username=postgres
stop:
$(CONMAN) stop $(HUTTESE_SRHT)
restart: databases
$(CONMAN) restart $(HUTTESE_SRHT)
clean:
$(CONMAN) rm --force $(HUTTESE_SRHT) >/dev/null 2>&1 || true
$(CONMAN) image rm --force $(SRHT_LOCALNAME):latest >/dev/null 2>&1 || true
.PHONY: databases cleanup setup image dbinit dbmigrate start adduser addadmin shell psql stop restart clean