2023-11-14 09:00:25 +01:00
|
|
|
pg_pass := "password"
|
|
|
|
pg_user := "postgres"
|
2023-12-09 12:31:09 +01:00
|
|
|
pg_container := "postgres-frostbyte" # This is the name of the postgres container
|
2023-11-14 09:00:25 +01:00
|
|
|
pg_port := "5432"
|
|
|
|
network := "fb_network"
|
2023-12-09 12:31:09 +01:00
|
|
|
db_name := "frostbyte" # This is the name of the database
|
2023-11-14 09:00:25 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2023-10-18 20:52:51 +02:00
|
|
|
# Builds a debug container and runs it
|
2023-10-19 02:31:54 +02:00
|
|
|
dev: start-debug
|
|
|
|
@echo "Cd into client and run 'npm run dev' to start the client in dev mode."
|
2023-10-17 19:43:26 +02:00
|
|
|
|
2023-10-18 20:52:51 +02:00
|
|
|
# Builds a debug container
|
2023-10-20 00:56:57 +02:00
|
|
|
[private]
|
2023-10-18 20:52:51 +02:00
|
|
|
build-container-server-debug:
|
2023-11-14 08:40:45 +01:00
|
|
|
podman build -t fb-server-debug -f container/ContainerfileDebug .
|
2023-10-18 20:52:51 +02:00
|
|
|
|
|
|
|
# Builds a debug container and runs it
|
2023-10-20 00:56:57 +02:00
|
|
|
[private]
|
2023-11-14 08:40:45 +01:00
|
|
|
start-debug: start-postgres-dev clean-podman init-sqlx build-container-server-debug
|
2023-11-14 09:00:25 +01:00
|
|
|
podman network create {{network}} --ignore
|
|
|
|
podman run -d --network {{network}} -e {{env_string}} -p 8080:8080 --name frostbyte-debug fb-server-debug
|
2023-12-09 12:31:09 +01:00
|
|
|
podman ps | grep frostbyte-debug
|
2023-10-19 02:31:54 +02:00
|
|
|
@echo "Debug server started."
|
2023-10-18 20:52:51 +02:00
|
|
|
|
|
|
|
# Builds a release container
|
2023-10-20 00:56:57 +02:00
|
|
|
[private]
|
2023-10-18 20:52:51 +02:00
|
|
|
build-container-release:
|
2023-11-14 08:40:45 +01:00
|
|
|
podman build -t fb-server -f container/Containerfile .
|
2023-10-17 19:43:26 +02:00
|
|
|
|
2023-10-18 20:52:51 +02:00
|
|
|
# Builds a release container and runs it
|
2023-11-22 15:40:29 +01:00
|
|
|
start-release: start-postgres-dev clean-podman init-sqlx build-container-release create-network
|
2023-11-14 09:00:25 +01:00
|
|
|
podman run -d --network {{network}} -e {{env_string}} -p 8080:8080 --name frostbyte fb-server
|
2023-10-20 00:56:57 +02:00
|
|
|
|
2023-11-14 08:40:45 +01:00
|
|
|
# Initializes the database, runs migrations and then prepares sqlx
|
2023-12-09 12:31:09 +01:00
|
|
|
[private]
|
2023-11-28 03:03:56 +01:00
|
|
|
init-sqlx: install-sqlx
|
2023-11-14 09:00:25 +01:00
|
|
|
echo {{env_local}} > server/.env
|
2023-11-14 08:40:45 +01:00
|
|
|
cd server && sqlx database create --connect-timeout 40 # Postgres takes a while to start up
|
2023-11-28 00:36:11 +01:00
|
|
|
cd server && sqlx migrate run
|
2023-12-09 12:31:09 +01:00
|
|
|
cd server && cargo sqlx prepare # If this fails, try running just clean
|
2023-10-21 00:02:58 +02:00
|
|
|
|
2023-12-09 12:31:09 +01:00
|
|
|
# Shorthand for installing sqlx
|
|
|
|
[private]
|
2023-11-28 03:03:56 +01:00
|
|
|
install-sqlx:
|
|
|
|
cargo install sqlx-cli
|
|
|
|
|
2023-11-14 08:40:45 +01:00
|
|
|
# Starts a postgres container for development
|
|
|
|
[private]
|
2023-11-22 15:40:29 +01:00
|
|
|
start-postgres-dev: create-network
|
2023-11-14 09:00:25 +01:00
|
|
|
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
|
2023-11-14 08:40:45 +01:00
|
|
|
|
2023-11-22 15:40:29 +01:00
|
|
|
[private]
|
|
|
|
create-network:
|
|
|
|
podman network create {{network}} --ignore
|
|
|
|
|
2023-11-14 08:40:45 +01:00
|
|
|
# Forcefully stops and removes the frostbyte container
|
2023-10-20 00:56:57 +02:00
|
|
|
[private]
|
2023-11-14 08:40:45 +01:00
|
|
|
clean-podman:
|
|
|
|
podman container rm -f frostbyte
|
|
|
|
podman container rm -f frostbyte-debug
|
2023-10-17 19:43:26 +02:00
|
|
|
|
2023-12-09 12:31:09 +01:00
|
|
|
# Removes the database container
|
|
|
|
[private]
|
|
|
|
clean-db:
|
|
|
|
podman container rm -f {{pg_container}}
|
|
|
|
|
|
|
|
# Removes the network
|
|
|
|
[private]
|
|
|
|
clean-network:
|
|
|
|
podman network rm -f {{network}}
|
|
|
|
|
2023-11-14 08:40:45 +01:00
|
|
|
# Forcefully removes the frostbyte images
|
2023-10-20 00:56:57 +02:00
|
|
|
[private]
|
2023-11-14 08:40:45 +01:00
|
|
|
clean-images:
|
|
|
|
podman image rm -f fb-server
|
|
|
|
podman image rm -f fb-server-debug
|
2023-12-09 12:31:09 +01:00
|
|
|
podman image rm -f postgres
|
2023-12-18 18:18:19 +01:00
|
|
|
podman image prune -af
|
2023-10-18 20:52:51 +02:00
|
|
|
|
|
|
|
# Cleans up everything related to the project
|
2023-12-09 12:31:09 +01:00
|
|
|
clean: clean-podman clean-db clean-images clean-network && state
|
2023-11-01 15:47:51 +01:00
|
|
|
rm -rf client-solid/dist
|
|
|
|
rm -rf client-solid/node_modules
|
2023-10-17 19:43:26 +02:00
|
|
|
rm -rf server/public
|
2023-10-18 20:52:51 +02:00
|
|
|
rm -rf server/target
|
2023-11-28 00:36:11 +01:00
|
|
|
@echo "Cleaned up! Make sure to clean up podman volumes and networks."
|
2023-12-09 12:31:09 +01:00
|
|
|
|
|
|
|
state:
|
|
|
|
podman ps -a
|
|
|
|
podman images ls -a
|
|
|
|
podman network ls
|
|
|
|
du -sch client* server
|