Skip to content

Commit

Permalink
fix: simplify docker setup (#41)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexandru Matei <alexandrumatei3693@gmail.com>
  • Loading branch information
amateima and alexandrumatei36 authored Sep 19, 2024
1 parent 82654f3 commit 08d2962
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 59 deletions.
13 changes: 8 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
node_modules
Dockerfile
docker-compose.yml
volumes
**/dist
**/node_modules
.dockerignore
.vscode
.env
.git*
.husky
.pnpm-store
.turbo
**/dist
dist
.env
.vscode
32 changes: 5 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Set the build image
FROM node:20 AS development
FROM node:20

# Set the work directory
WORKDIR /usr/src/app
Expand All @@ -21,32 +21,10 @@ COPY packages/template/package.json ./packages/template/package.json
COPY packages/typescript-config/package.json ./packages/typescript-config/package.json

# Build the dependencies into a node_modules folder
RUN pnpm install --frozen-lockfile --ignore-scripts
RUN pnpm install --frozen-lockfile

# Copy the rest of the files & build the app
COPY ./apps ./apps
COPY ./packages ./packages
RUN pnpm build

# Set the production image
FROM node:20-alpine AS production

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /usr/src/app
COPY . .

# Copy pnpm from the development stage
COPY --from=development /usr/local/bin/pnpm /usr/local/bin/pnpm

# Copy over the built files from the development stage
COPY --from=development /usr/src/app/apps ./apps
COPY --from=development /usr/src/app/packages ./packages
COPY --from=development /usr/src/app/node_modules ./node_modules

# Change the working directory to the apps/node directory
WORKDIR /usr/src/app/apps/node

COPY ./docker ./docker

CMD ["sh", "./docker/prod.command.sh"]
# Build the monorepo
RUN pnpm build
1 change: 1 addition & 0 deletions apps/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"scripts": {
"start": "ts-node ./src/app",
"start:prod": "node dist/app",
"build": "tsc -b",
"format": "prettier --write src",
"lint": "eslint --fix",
Expand Down
14 changes: 4 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@ services:
indexer-scraper:
build:
context: .
target: development
container_name: indexer_service
volumes:
- .:/usr/src/app
# - .:/usr/src/app
- indexer-node-modules:/usr/src/app/node_modules
command: /bin/sh -c "/bin/sh ./docker/migrations.command.sh && /bin/sh ./docker/dev.command.sh"
working_dir: "/usr/src/app"
command: [sh, -c, "pnpm db:indexer-database:migrate:run && pnpm start:indexer"]
env_file:
- .env
environment:
APP: indexer
INDEXER_REDIS_HOST: redis
DATABASE_HOST: postgres
depends_on:
Expand All @@ -46,19 +43,16 @@ services:
indexer-api:
build:
context: .
target: development
container_name: indexer_api
working_dir: "/usr/src/app"
volumes:
- .:/usr/src/app
# - .:/usr/src/app
- indexer-api-node-modules:/usr/src/app/node_modules
ports:
- ${PORT}:${PORT}
command: ["/bin/sh", "./docker/dev.command.sh"]
command: pnpm start:indexer-api
env_file:
- .env
environment:
APP: indexer-api
INDEXER_REDIS_HOST: redis
DATABASE_HOST: postgres
depends_on:
Expand Down
3 changes: 0 additions & 3 deletions docker/dev.command.sh

This file was deleted.

9 changes: 0 additions & 9 deletions docker/migrations.command.sh

This file was deleted.

4 changes: 0 additions & 4 deletions docker/prod.command.sh

This file was deleted.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
"check": "turbo check",
"test": "turbo test",
"start:indexer": "APP=indexer pnpm --filter @repo/node-app start",
"start:indexer:prod": "APP=indexer pnpm --filter @repo/node-app start:prod",
"start:indexer-api": "APP=indexer-api pnpm --filter @repo/node-app start",
"start:indexer-api:prod": "APP=indexer-api pnpm --filter @repo/node-app start:prod",
"start:template": "APP=template pnpm --filter @repo/node-app start",
"start:persistence-example": "APP=persistence-example pnpm --filter @repo/node-app start",
"prepare": "husky",
"db:persistence-example:migrate:generate": "cd packages/persistence-example; pnpm db:migration:generate $MIGRATION_PATH",
"db:persistence-example:migrate:run": "cd packages/persistence-example; pnpm db:migration:run",
"db:indexer-database:migrate:generate": "cd packages/indexer-database; pnpm db:migration:generate $MIGRATION_PATH",
"db:indexer-database:migrate:run": "cd packages/indexer-database; pnpm db:migration:run",
"db:indexer-database:migrate:run": "pnpm --filter @repo/indexer-database db:migration:run",
"dev-env:up": "docker compose up -d --build",
"dev-env:down": "docker compose down"
},
Expand Down

0 comments on commit 08d2962

Please sign in to comment.