Skip to content

Commit

Permalink
Add dev container
Browse files Browse the repository at this point in the history
  • Loading branch information
Delemangi committed Dec 16, 2023
1 parent 100406c commit 05f13d7
Show file tree
Hide file tree
Showing 14 changed files with 1,166 additions and 44 deletions.
22 changes: 22 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"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"
}
20 changes: 17 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
# Node modules
node_modules

# Git
.git
.gitignore

# Docker
.dockerignore
Dockerfile*
docker-compose*

# Output
dist

# Logs
bot.log

# User defined folders
# Configuration
config
files
sessions

# Environment variables
.env
# Environment
.env*

# GitHub
.github
*.md
LICENSE
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ files
config

# Database
db
db/
migration/
pgadmin
pgadmin/

# Compiled output
dist
Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"Prisma.prisma",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"github.vscode-codeql",
"me-dutour-mathieu.vscode-github-actions",
"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
19 changes: 12 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG PLATFORM="linux/amd64"

# Build stage
FROM --platform=${PLATFORM} node:20-alpine AS build
FROM node:20 AS development
WORKDIR /app

COPY package*.json ./
Expand All @@ -15,18 +15,23 @@ RUN npm run build

COPY start.sh ./

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

COPY nodemon.json ./

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

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

RUN apk update && apk add postgresql-client && apk cache clean

COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/prisma ./prisma
COPY --from=build /app/package.json ./
COPY --from=build /app/start.sh ./

CMD [ "sh", "/app/start.sh" ]
RUN npm i --production

RUN apk update && apk add postgresql-client && apk cache clean

CMD [ "npm", "run", "start" ]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ It's recommended, but not required to run this inside a Docker container.

For development purposes, be sure to run `npm run prepare` to install the Git pre-commit hooks.

Also, this project contains a dev container configuration for hot reloading. If you encounter issues in the dev container with Prisma, then run `npm run generate` to regenerate the Prisma client.

### Installation (Docker)

1. Clone the repository: `git clone [email protected]:Delemangi/finki-discord-bot.git`
Expand Down
43 changes: 43 additions & 0 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: "3.8"

services:
database:
container_name: finki-database-dev
image: postgres:16
restart: unless-stopped
ports:
- "${POSTGRES_PORT}:${POSTGRES_PORT}"
env_file:
- .env
volumes:
- ./db:/var/lib/postgresql/data

bot:
container_name: finki-bot-dev
build:
context: .
dockerfile: ./Dockerfile
target: development
image: finki-discord-bot-dev:latest
restart: unless-stopped
env_file:
- .env
depends_on:
- database
volumes:
- .:/app
command: ["npm", "run", "dev"]

pgadmin:
container_name: finki-pgadmin-dev
image: dpage/pgadmin4:8
restart: unless-stopped
ports:
- 8080:80
environment:
- [email protected]
- PGADMIN_DEFAULT_PASSWORD=test
depends_on:
- database
volumes:
- ./pgadmin:/var/lib/pgadmin
13 changes: 0 additions & 13 deletions docker-compose.migration.yaml

This file was deleted.

9 changes: 4 additions & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: "3.8"

services:
db:
container_name: finki-db
database:
container_name: finki-database
image: postgres:16
restart: unless-stopped
env_file:
Expand All @@ -12,13 +12,12 @@ services:

bot:
container_name: finki-bot
image: finki-discord-bot:latest
build: .
image: delemangi/finki-discord-bot:latest
restart: unless-stopped
env_file:
- .env
depends_on:
- db
- database
volumes:
- ./config:/app/config
- ./sessions:/app/sessions
Expand Down
11 changes: 11 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"exec": "node --loader ts-node/esm ./src/main.ts",
"ext": "*",
"legacyWatch": true,
"watch": [
"src"
],
"watchOptions": {
"interval": 1000
}
}
Loading

0 comments on commit 05f13d7

Please sign in to comment.