Skip to content

Commit

Permalink
Chore: Add dockerize for local strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Hoplin committed Jan 23, 2024
1 parent db92285 commit 22276a3
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 11 deletions.
27 changes: 27 additions & 0 deletions .docker.env
Original file line number Diff line number Diff line change
@@ -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=""
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
24 changes: 19 additions & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 22276a3

Please sign in to comment.