diff --git a/Makefile b/Makefile index 5556ba2d..11201d7c 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,45 @@ +# ===== + +all: install build db server +rebuild: build server + +# ===== + install: @echo "Setting up the project..." yarn +build: + @echo "Building the docker images..." + docker compose -f docker-compose.yml build + db: @echo "Setting up the database and running migrations..." - yarn dockerup-db - - @read -p "Enter the DATABASE_URL for seeding: " DATABASE_URL; \ - DATABASE_URL=$$DATABASE_URL yarn workspace @creature-chess/data prisma-migrate deploy + docker compose -f docker-compose.db.yml up -d postgres + docker compose run -e DATABASE_URL nodejs-builder yarn workspace @creature-chess/data prisma migrate deploy server: @echo "Running the game..." - yarn dockerup + docker compose -f docker-compose.yml up -d + +down: + @echo "Stopping the game..." + docker compose -f docker-compose.yml down + @echo "Stopping the database..." + docker compose -f docker-compose.db.yml down + +# ===== + +# This step is used to create a new migration. +# It creates a new nodejs-builder container, runs the migration command inside, +# then copies the migration files to the local machine. +add-migration: + @echo "Creating new migration" + read -p "Enter the migration name: " MIGRATION_NAME; \ + docker compose -f docker-compose.db.yml up -d postgres; \ + docker compose run -e DATABASE_URL nodejs-builder yarn workspace @creature-chess/data prisma migrate dev --name $$MIGRATION_NAME; \ + CONTAINER_ID=$$(docker ps -aqf "ancestor=nodejs-builder" --latest); \ + docker cp $$CONTAINER_ID:/code/modules/@creature-chess/data/prisma/migrations ./modules/@creature-chess/data/prisma/; \ + docker stop $$CONTAINER_ID; \ + docker rm $$CONTAINER_ID; \ + yarn workspace @creature-chess/data prisma generate diff --git a/README.md b/README.md index 6f83fcdb..818dee0c 100644 --- a/README.md +++ b/README.md @@ -54,13 +54,13 @@ See "Environment variables" above for info on how to store them. ### Setup -You can use the following `make` commands to set up the project: +To build and run the project, you can use `make`: -- `make install` - install dependencies -- `make db` - seed the database - - take the `DATABASE_URL` from `.env` and input it when asked. - - you may need to configure the connection string to use `localhost` instead of `postgres` as the host, depending on your setup. -- `make server` - build and run the docker containers +```shell +make +``` + +If you change the server, you can run `make rebuild` to rebuild and restart the server. ### Dev toolkit diff --git a/apps/nodejs-builder.Dockerfile b/apps/nodejs-builder.Dockerfile index b879ba69..f4de467a 100644 --- a/apps/nodejs-builder.Dockerfile +++ b/apps/nodejs-builder.Dockerfile @@ -46,7 +46,6 @@ ADD modules/@shoki/networking/package.json ./modules/@shoki/networking/ ADD modules/@tools/battle-tester/package.json ./modules/@tools/battle-tester/ # Run the install now that we have the package.json and yarn.lock files - RUN yarn install --frozen-lockfile --network-timeout 1000000 # Finally, copy the rest of the source code into the image @@ -54,7 +53,20 @@ RUN yarn install --frozen-lockfile --network-timeout 1000000 # install every time one of these steps has a different result ADD tsconfig.json ./ -ADD modules/ ./modules/ +# Copy and build the `@shoki` packages (excluding board-react) +ADD modules/@shoki/ ./modules/@shoki/ +RUN yarn workspaces foreach --include "@shoki/*" --exclude "@shoki/board-react" run build + +# Copy and build the @creature-chess/models +ADD modules/@creature-chess/models/ ./modules/@creature-chess/models/ +RUN yarn workspace @creature-chess/models run build + +# Copy and build the @creature-chess/data +ADD modules/@creature-chess/data/ ./modules/@creature-chess/data/ RUN yarn workspace @creature-chess/data prisma-generate -RUN yarn workspaces foreach --exclude "@creature-chess-app/*" run build +RUN yarn workspace @creature-chess/data run build + +# Copy and build the remaining `@creature-chess` packages +ADD modules/@creature-chess/ ./modules/@creature-chess/ +RUN yarn workspaces foreach --include "@creature-chess/*" --exclude "@creature-chess/models" --exclude "@creature-chess/data" run build diff --git a/apps/web-menu/src/index.ejs b/apps/web-menu/src/index.ejs index 9e735916..964376f3 100644 --- a/apps/web-menu/src/index.ejs +++ b/apps/web-menu/src/index.ejs @@ -9,8 +9,6 @@ />