Skip to content

Commit

Permalink
Improve dev container setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Delemangi committed Dec 20, 2023
1 parent fe7c01b commit ab6a5e7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 33 deletions.
12 changes: 0 additions & 12 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
{
"customizations": {
"vscode": {
"sonarlint.pathToNodeExecutable": "node",
"terminal.integrated.shell.linux": "/bin/bash"
}
},
"dockerComposeFile": "../docker-compose.dev.yaml",
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {},
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/java:1": {}
},
"forwardPorts": [
8080
],
"name": "finki-discord-bot",
"postCreateCommand": "npm i",
"service": "bot",
"shutdownAction": "stopCompose",
"workspaceFolder": "/app"
Expand Down
17 changes: 17 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules
# Git
.git
.gitignore
.gitattributes

# Docker
.dockerignore
Expand All @@ -28,3 +29,19 @@ sessions
.github
*.md
LICENSE

# Dev container
.devcontainer

# ESLint
.eslintcache
.eslintrc*

# Database
db

# pgAdmin
pgadmin

# SonarCloud
sonar-project.properties
1 change: 0 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"meganrogge.template-string-converter",
"mikestead.dotenv",
"ms-azuretools.vscode-docker",
"ms-azuretools.vscode-docker",
"ms-vscode-remote.remote-containers",
"sonarsource.sonarlint-vscode",
"yoavbls.pretty-ts-errors"
Expand Down
30 changes: 12 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
ARG PLATFORM="linux/amd64"

# Build stage
FROM node:20 AS development
# Development stage
FROM node:20-alpine AS development
WORKDIR /app

COPY package*.json ./
RUN apk add --no-cache postgresql-client git gnupg openjdk17 nodejs

COPY package.json package-lock.json ./
RUN npm i

COPY prisma ./prisma
RUN npx prisma generate

COPY src tsconfig.json ./
COPY . ./
RUN npm run build

COPY start.sh ./

RUN apt-get update && apt-get install postgresql-client gnupg2 -y && apt-get clean

COPY nodemon.json ./

CMD [ "npm", "run", "dev" ]

# Production stage
FROM --platform=${PLATFORM} node:20-alpine AS production
WORKDIR /app

COPY --from=development /app/dist ./dist
COPY --from=development /app/prisma ./prisma
COPY --from=development /app/package.json ./
COPY --from=development /app/package-lock.json ./
COPY --from=development /app/start.sh ./
RUN apk add --no-cache postgresql-client

RUN npm i
COPY --from=development /app/package.json /app/start.sh ./
COPY --from=development /app/node_modules ./node_modules
RUN npm prune --production

RUN apk update && apk add postgresql-client && apk cache clean
COPY --from=development /app/prisma ./prisma
COPY --from=development /app/dist ./dist

CMD [ "npm", "run", "start" ]
CMD [ "sh", "./start.sh" ]
1 change: 1 addition & 0 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ services:
- database
volumes:
- .:/app
- /app/node_modules
command: ["npm", "run", "dev"]

pgadmin:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"apply": "prisma migrate deploy",
"migrate": "prisma migrate dev --name a",
"prepare": "husky install",
"start": "sh ./start.sh"
"start": "node dist/main.js"
},
"type": "module",
"version": "4.0.0"
Expand Down
2 changes: 1 addition & 1 deletion start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ until PGPASSWORD="$POSTGRES_PASSWORD" pg_isready --host="$POSTGRES_HOST" --port=
done

echo "Starting the bot..."
npm run apply && node dist/main.js
npm run apply && npm run start

0 comments on commit ab6a5e7

Please sign in to comment.