diff --git a/.docker.env b/.docker.env new file mode 100644 index 0000000..8c3558d --- /dev/null +++ b/.docker.env @@ -0,0 +1,27 @@ +# Environment variables declared in this file are automatically made available to Prisma. +# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema + +# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB. +# See the documentation for all the connection string options: https://pris.ly/d/connection-strings + +DATABASE_URL="mysql://root:hoplin1234!@db:3306/judge?schema=public" + +ADMIN_EMAIL="hoplin.dev@gmail.com" +ADMIN_PW = "admin" + +JWT_SECRET="SECRET" + +JUDGE_SERVER_ENDPOINT="" + +ENV="" +PORT="" + +# AWS +AWS_REGION="" +AWS_ACCESS_ID="" +AWS_ACCESS_SECRET="" +AWS_SQS_QUEUE="" +AWS_S3_BUCKET="" + +# Sentry +SENTRY_DSN="" diff --git a/Dockerfile b/Dockerfile index 48bdeeb..f6ddb93 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,9 +2,7 @@ FROM node:21-bullseye COPY . . -RUN yarn install\ -npx prisma migrate +RUN yarn install - -CMD [ "start" ] +CMD [ "docker:start" ] ENTRYPOINT [ "yarn" ] \ No newline at end of file diff --git a/README.md b/README.md index f7cafaf..de4ffce 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ - [📊Test Coverage](#test-coverage) - [🧰Technical Stack](#technical-stack) - [✅Run Application](#run-application) +- [🐳Run Application With Docker] - [📄Run E2E Test](#run-e2e-test) - [📄Run Unit Test](#run-unit-test) - [📝TODO](#todo) @@ -103,6 +104,26 @@ yarn dev ``` +## Run Application with docker + +1. Build docker image + + ``` + docker build -t online-judge . + ``` + +2. Run with docker enviornment + + ``` + yarn docker:up + ``` + +3. Remove docker environment + + ``` + yarn docker:down + ``` + ## Run E2E Test - Config: test/jest-e2e.json diff --git a/docker-compose.yaml b/docker-compose.yaml index 4536e6a..28efc2f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -5,15 +5,29 @@ services: ports: - '3306:3306' restart: 'unless-stopped' - # volumes: - # - system-db:/var/lib/mysql environment: - MYSQL_ROOT_PASSWORD=hoplin1234! - MYSQL_ROOT_HOST=% - MYSQL_DATABASE=judge + networks: + - system + api: + image: online-judge + ports: + - '3000:3000' + restart: 'unless-stopped' + env_file: + - ./.docker.env + depends_on: + - db + networks: + - system + redis: + image: redis + ports: + - '6379:6379' + networks: + - system networks: system: driver: bridge -# volumes: -# system-db: -# external: false diff --git a/package.json b/package.json index 79ea1cf..6abdc78 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,13 @@ "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"libs/**/*.ts\"", "start": "node dist/main", "dev": "nest start --watch", - "db:dev:up": "docker-compose up -d", - "db:dev:down": "docker-compose down", + "db:dev:up": "docker-compose up -d db", + "db:dev:down": "docker-compose down db", + "db:generate": "npx prisma generate", "db:push": "prisma db push", + "docker:up": "docker compose up -d", + "docker:down": "docker compose down", + "docker:start": "yarn db:push && yarn db:generate && yarn start", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest", "test:watch": "jest --watch",