Justfile templating

This commit is contained in:
Imbus 2023-11-14 09:00:25 +01:00
parent 29c1fc8f82
commit 8d19a935d8

View file

@ -1,3 +1,15 @@
pg_pass := "password"
pg_user := "postgres"
pg_container := "postgres"
pg_port := "5432"
network := "fb_network"
db_name := "frostbyte"
conn_string := "postgres://" + pg_user + ":" + pg_pass + "@" + pg_container + ":" + pg_port / db_name
conn_local := "postgres://" + pg_user + ":" + pg_pass + "@" + "localhost" + ":" + pg_port / db_name
env_string := "DATABASE_URL=" + conn_string
env_local := "DATABASE_URL=" + conn_local
# Builds a debug container and runs it
dev: start-debug
@echo "Cd into client and run 'npm run dev' to start the client in dev mode."
@ -10,8 +22,8 @@ build-container-server-debug:
# Builds a debug container and runs it
[private]
start-debug: start-postgres-dev clean-podman init-sqlx build-container-server-debug
podman network create fb_network --ignore
podman run -d --network fb_network -e DATABASE_URL=postgres://postgres:password@postgres:5432/frostbyte -p 8080:8080 --name frostbyte-debug fb-server-debug
podman network create {{network}} --ignore
podman run -d --network {{network}} -e {{env_string}} -p 8080:8080 --name frostbyte-debug fb-server-debug
@echo "Debug server started."
# Builds a release container
@ -21,12 +33,12 @@ build-container-release:
# Builds a release container and runs it
start-release: start-postgres-dev clean-podman init-sqlx build-container-release
podman network create fb_network --ignore
podman run -d --network fb_network -e DATABASE_URL=postgres://postgres:password@postgres:5432/frostbyte -p 8080:8080 --name frostbyte fb-server
podman network create {{network}} --ignore
podman run -d --network {{network}} -e {{env_string}} -p 8080:8080 --name frostbyte fb-server
# Initializes the database, runs migrations and then prepares sqlx
init-sqlx:
echo "DATABASE_URL=postgres://postgres:password@localhost:5432/frostbyte" > server/.env
echo {{env_local}} > server/.env
cd server && sqlx database create --connect-timeout 40 # Postgres takes a while to start up
cd server && sqlx migrate run --source migrations_pg
cd server && cargo sqlx prepare
@ -34,8 +46,8 @@ init-sqlx:
# Starts a postgres container for development
[private]
start-postgres-dev:
podman rm -f postgres
podman run --network fb_network --name postgres -e POSTGRES_PASSWORD=password -d -p 5432:5432 docker.io/postgres:16.1-alpine
podman rm -f {{pg_container}}
podman run --network {{network}} --name {{pg_container}} -e POSTGRES_PASSWORD={{pg_pass}} -d -p {{pg_port}}:5432 docker.io/postgres:16.1-alpine
# Forcefully stops and removes the frostbyte container
[private]