aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-07-30 00:27:46 +0900
committernsfisis <nsfisis@gmail.com>2024-07-30 00:27:46 +0900
commit432593ddc20e4248c6fe134d13f9c25bad7e39f7 (patch)
treeb60ac9ce2102367f345110d451abe19e1b6219bf
parent7e2704c90ffba3612bd87ed342d4f310b0de78c0 (diff)
parent0908e5d2041ded22969da7d66ead59d5037d40dd (diff)
downloadiosdc-japan-2024-albatross-432593ddc20e4248c6fe134d13f9c25bad7e39f7.tar.gz
iosdc-japan-2024-albatross-432593ddc20e4248c6fe134d13f9c25bad7e39f7.tar.zst
iosdc-japan-2024-albatross-432593ddc20e4248c6fe134d13f9c25bad7e39f7.zip
Merge branch 'feat/local-dev'
-rw-r--r--Makefile52
-rw-r--r--Makefile.prod39
-rw-r--r--backend/fixtures/dev.sql37
-rw-r--r--backend/schema.sql14
-rw-r--r--compose.local.yaml54
-rw-r--r--compose.prod.yaml (renamed from compose.yaml)29
-rw-r--r--docs/DEV.md18
7 files changed, 186 insertions, 57 deletions
diff --git a/Makefile b/Makefile
index 07f682f..b15a2bb 100644
--- a/Makefile
+++ b/Makefile
@@ -1,42 +1,52 @@
+DOCKER_COMPOSE := docker compose -f compose.local.yaml
+
.PHONY: build
build:
- docker compose build
+ ${DOCKER_COMPOSE} build
+ cd frontend; npm install
.PHONY: up
up:
- docker compose up -d
+ ${DOCKER_COMPOSE} up -d
+ cd frontend; npm run dev
.PHONY: down
down:
- docker compose down
-
-.PHONY: api-server-only-build
-api-server-only-build:
- docker compose build api-server-only
-
-.PHONY: api-server-only-up
-api-server-only-up:
- docker compose up -d api-server-only
+ ${DOCKER_COMPOSE} down
-.PHONY: api-server-only-down
-api-server-only-down:
- docker compose down api-server-only db
+.PHONY: logs
+logs:
+ ${DOCKER_COMPOSE} logs
.PHONY: psql
psql:
- docker compose exec db psql --user=postgres albatross
+ ${DOCKER_COMPOSE} up --wait db
+ ${DOCKER_COMPOSE} exec db psql --user=postgres albatross
+
+.PHONY: psql-query
+psql-query:
+ ${DOCKER_COMPOSE} up --wait db
+ ${DOCKER_COMPOSE} exec --no-TTY db psql --user=postgres albatross
.PHONY: sqldef-dryrun
sqldef-dryrun: down
- docker compose build db
- docker compose up -d db
- docker compose run --no-TTY tools psqldef --dry-run < ./backend/schema.sql
+ ${DOCKER_COMPOSE} build db
+ ${DOCKER_COMPOSE} up --wait db
+ ${DOCKER_COMPOSE} run --no-TTY tools psqldef --dry-run < ./backend/schema.sql
.PHONY: sqldef
sqldef: down
- docker compose build db
- docker compose up -d db
- docker compose run --no-TTY tools psqldef < ./backend/schema.sql
+ ${DOCKER_COMPOSE} build db
+ ${DOCKER_COMPOSE} up --wait db
+ ${DOCKER_COMPOSE} run --no-TTY tools psqldef < ./backend/schema.sql
+
+.PHONY: init
+init: build initdb
+
+.PHONY: initdb
+initdb:
+ make psql-query < ./backend/schema.sql
+ make psql-query < ./backend/fixtures/dev.sql
.PHONY: oapi-codegen
oapi-codegen:
diff --git a/Makefile.prod b/Makefile.prod
new file mode 100644
index 0000000..05901f0
--- /dev/null
+++ b/Makefile.prod
@@ -0,0 +1,39 @@
+DOCKER_COMPOSE := docker compose -f compose.prod.yaml
+
+.PHONY: build
+build:
+ ${DOCKER_COMPOSE} build
+
+.PHONY: up
+up:
+ ${DOCKER_COMPOSE} up -d
+
+.PHONY: down
+down:
+ ${DOCKER_COMPOSE} down
+
+.PHONY: logs
+logs:
+ ${DOCKER_COMPOSE} logs
+
+.PHONY: psql
+psql:
+ ${DOCKER_COMPOSE} up --wait db
+ ${DOCKER_COMPOSE} exec db psql --user=postgres albatross
+
+.PHONY: psql-query
+psql-query:
+ ${DOCKER_COMPOSE} up --wait db
+ ${DOCKER_COMPOSE} exec --no-TTY db psql --user=postgres albatross
+
+.PHONY: sqldef-dryrun
+sqldef-dryrun: down
+ ${DOCKER_COMPOSE} build db
+ ${DOCKER_COMPOSE} up --wait db
+ ${DOCKER_COMPOSE} run --no-TTY tools psqldef --dry-run < ./backend/schema.sql
+
+.PHONY: sqldef
+sqldef: down
+ ${DOCKER_COMPOSE} build db
+ ${DOCKER_COMPOSE} up --wait db
+ ${DOCKER_COMPOSE} run --no-TTY tools psqldef < ./backend/schema.sql
diff --git a/backend/fixtures/dev.sql b/backend/fixtures/dev.sql
new file mode 100644
index 0000000..3549d86
--- /dev/null
+++ b/backend/fixtures/dev.sql
@@ -0,0 +1,37 @@
+INSERT INTO users
+(username, display_name, icon_path, is_admin)
+VALUES
+ ('a', 'TEST A', NULL, FALSE),
+ ('b', 'TEST B', NULL, FALSE),
+ ('c', 'TEST C', NULL, TRUE);
+
+INSERT INTO user_auths
+(user_id, auth_type)
+VALUES
+ (1, 'bypass'),
+ (2, 'bypass'),
+ (3, 'bypass');
+
+INSERT INTO problems
+(title, description)
+VALUES
+ ('TEST problem 1', 'This is TEST problem 1'),
+ ('TEST problem 2', 'This is TEST problem 2'),
+ ('TEST problem 3', 'This is TEST problem 3');
+
+INSERT INTO games
+(state, display_name, duration_seconds, problem_id)
+VALUES
+ ('waiting_entries', 'TEST game 1', 180, 1),
+ ('closed', 'TEST game 2', 180, 2),
+ ('finished', 'TEST game 3', 180, 3);
+
+INSERT INTO game_players
+(game_id, user_id)
+VALUES
+ (1, 1),
+ (1, 2),
+ (2, 1),
+ (2, 2),
+ (3, 1),
+ (3, 2);
diff --git a/backend/schema.sql b/backend/schema.sql
index 7f98d91..3a4422f 100644
--- a/backend/schema.sql
+++ b/backend/schema.sql
@@ -9,12 +9,18 @@ CREATE TABLE users (
CREATE TABLE user_auths (
user_auth_id SERIAL PRIMARY KEY,
- user_id INT NOT NULL,
+ user_id INT NOT NULL UNIQUE,
auth_type VARCHAR(16) NOT NULL,
password_hash VARCHAR(256),
CONSTRAINT fk_user_id FOREIGN KEY(user_id) REFERENCES users(user_id)
);
+CREATE TABLE problems (
+ problem_id SERIAL PRIMARY KEY,
+ title VARCHAR(255) NOT NULL,
+ description TEXT NOT NULL
+);
+
CREATE TABLE games (
game_id SERIAL PRIMARY KEY,
state VARCHAR(32) NOT NULL,
@@ -34,12 +40,6 @@ CREATE TABLE game_players (
CONSTRAINT fk_user_id FOREIGN KEY(user_id) REFERENCES users(user_id)
);
-CREATE TABLE problems (
- problem_id SERIAL PRIMARY KEY,
- title VARCHAR(255) NOT NULL,
- description TEXT NOT NULL
-);
-
CREATE TABLE testcases (
testcase_id SERIAL PRIMARY KEY,
problem_id INT NOT NULL,
diff --git a/compose.local.yaml b/compose.local.yaml
new file mode 100644
index 0000000..6e5604f
--- /dev/null
+++ b/compose.local.yaml
@@ -0,0 +1,54 @@
+services:
+ api-server:
+ build:
+ context: ./backend
+ ports:
+ - '127.0.0.1:8002:80'
+ depends_on:
+ db:
+ condition: service_healthy
+ environment:
+ ALBATROSS_DB_HOST: db
+ ALBATROSS_DB_PORT: 5432
+ ALBATROSS_DB_USER: postgres
+ ALBATROSS_DB_PASSWORD: eepei5reesoo0ov2ceelahd4Emi0au8ahJa6oochohheiquahweihoovahsee1oo
+ ALBATROSS_DB_NAME: albatross
+ restart: always
+
+ db:
+ image: postgres:16.3
+ environment:
+ POSTGRES_USER: postgres
+ POSTGRES_PASSWORD: eepei5reesoo0ov2ceelahd4Emi0au8ahJa6oochohheiquahweihoovahsee1oo
+ POSTGRES_DB: albatross
+ expose:
+ - 5432
+ healthcheck:
+ test: ["CMD-SHELL", "pg_isready -U postgres"]
+ interval: 10s
+ timeout: 5s
+ retries: 5
+ volumes:
+ - db-data:/var/lib/postgresql/data
+ restart: always
+
+ worker:
+ build:
+ context: ./worker
+ expose:
+ - 80
+ restart: always
+
+ tools:
+ build:
+ context: ./backend
+ dockerfile: ./Dockerfile.tools
+ environment:
+ POSTGRES_USER: postgres
+ POSTGRES_PASSWORD: eepei5reesoo0ov2ceelahd4Emi0au8ahJa6oochohheiquahweihoovahsee1oo
+ POSTGRES_DB: albatross
+ profiles:
+ - tools
+
+volumes:
+ db-data:
diff --git a/compose.yaml b/compose.prod.yaml
index a98b918..a7c64ab 100644
--- a/compose.yaml
+++ b/compose.prod.yaml
@@ -26,24 +26,6 @@ services:
ALBATROSS_DB_NAME: albatross
restart: always
- api-server-only:
- build:
- context: ./backend
- ports:
- - '127.0.0.1:8002:80'
- depends_on:
- db:
- condition: service_healthy
- environment:
- ALBATROSS_DB_HOST: db
- ALBATROSS_DB_PORT: 5432
- ALBATROSS_DB_USER: postgres
- ALBATROSS_DB_PASSWORD: eepei5reesoo0ov2ceelahd4Emi0au8ahJa6oochohheiquahweihoovahsee1oo
- ALBATROSS_DB_NAME: albatross
- restart: always
- profiles:
- - api-server-only
-
app-server:
build:
context: ./frontend
@@ -77,16 +59,5 @@ services:
- 80
restart: always
- tools:
- build:
- context: ./backend
- dockerfile: ./Dockerfile.tools
- environment:
- POSTGRES_USER: postgres
- POSTGRES_PASSWORD: eepei5reesoo0ov2ceelahd4Emi0au8ahJa6oochohheiquahweihoovahsee1oo
- POSTGRES_DB: albatross
- profiles:
- - tools
-
volumes:
db-data:
diff --git a/docs/DEV.md b/docs/DEV.md
new file mode 100644
index 0000000..7e8bcd6
--- /dev/null
+++ b/docs/DEV.md
@@ -0,0 +1,18 @@
+# Dependencies
+
+* Docker
+* Docker Compose
+* Node.js 20.0.0 or later
+* Npm
+* Go 1.22.3 or later
+
+# Run
+
+1. Clone the repository.
+1. `cd path/to/the/repo`
+1. `make init`
+1. `make up`
+1. Access to http://localhost:5173.
+ * User `a`, `b` and `c` can log in with any password.
+ * User `a` and `b` are players.
+ * User `c` is an administrator.