Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Docker Stack #75

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c2ed3ac
Remove old docker implementation
burnoutprojects Dec 30, 2023
d38b214
Add dockerignore file
burnoutprojects Dec 30, 2023
5209bf3
Replace ts-node with tsx package
burnoutprojects Dec 30, 2023
0c9df01
Create multi-stage image file and entrypoint file
burnoutprojects Dec 30, 2023
90b0bd2
Update entrypoint.sh
burnoutprojects Dec 30, 2023
631c88e
.gitignore: Ignore .dev-data folder
burnoutprojects Dec 30, 2023
f7741d7
tsconfig.json: Include src folder, exclude node_modules folder
burnoutprojects Dec 30, 2023
073753a
Remove nodemon.json config file
burnoutprojects Dec 30, 2023
3ab819e
Remove nodemon package
burnoutprojects Dec 30, 2023
36dd554
package.json: Update docker scripts
burnoutprojects Dec 30, 2023
d29cdfa
.dockerignore: Cleanup entries
burnoutprojects Dec 30, 2023
72d98a2
Update npm scripts and entrypoint scripts file
burnoutprojects Dec 30, 2023
f10b2ff
Dockerfile: Update multi-stage image
burnoutprojects Dec 30, 2023
fd98882
Add new docker compose files for development and production use
burnoutprojects Dec 30, 2023
a82603d
Move @swc/helpers and dotenv to dependencies
burnoutprojects Jan 1, 2024
240ca6a
entrypoint.sh: Update script to run with sh from bash
burnoutprojects Jan 1, 2024
516d160
Dockerfile: Update the images structure
burnoutprojects Jan 1, 2024
a2f71d1
prod.compose.yaml: Comment out the database port for extra security
burnoutprojects Jan 1, 2024
fc8e4dd
Update .gitignore and .dockerignore
burnoutprojects Jan 1, 2024
c3366a2
Dockerfile: Remove useless label
burnoutprojects Jan 1, 2024
beade97
package.json: Update dev script to use ts-node
burnoutprojects Jan 1, 2024
0a472b0
tsconfig.json: Re-add ts-node config
burnoutprojects Jan 1, 2024
0243bdd
entrypoint.js: Update docker entrypoint script
burnoutprojects Jan 1, 2024
8b315b9
dev.compose.yaml: Update dev compose file
burnoutprojects Jan 1, 2024
4a17148
dev.compose.yaml: Update dev compose file
burnoutprojects Jan 1, 2024
297e81d
package.json: Update scripts
burnoutprojects Jan 1, 2024
e7104ac
Dockerfile: Change production image
burnoutprojects Jan 3, 2024
b9e3c8a
Add --silent flag to all yarn install
burnoutprojects Jan 3, 2024
24e7afa
Add init service inside container
burnoutprojects Jan 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
node_modules
.vscode
.env*
dist
.github

*.compose.yaml
docker/*
!docker/entrypoint.sh

.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ node_modules
.vscode
.env
dist
.data

.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
!.yarn/versions
32 changes: 32 additions & 0 deletions dev.compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: "3.9"

services:
postgres:
container_name: "snailycad-bot-postgres"
image: postgres
command: -p ${DB_PORT:-5554}
env_file:
- .env
ports:
- "${DB_PORT:-5554}:${DB_PORT:-5554}"
volumes:
- snailybot-dev-db-data:/var/lib/postgresql/data

api:
container_name: "snaily-cad-bot"
image: snaily-cad-bot:dev
build:
context: .
dockerfile: docker/Dockerfile
target: development
volumes:
- .:/srv
env_file:
- .env
environment:
- NODE_ENV=development
depends_on:
- postgres

volumes:
snailybot-dev-db-data:
burnoutprojects marked this conversation as resolved.
Show resolved Hide resolved
35 changes: 0 additions & 35 deletions docker-compose.yml

This file was deleted.

37 changes: 37 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Builder Image
FROM node:18 as builder

LABEL stage=builder

WORKDIR /srv

COPY . .

RUN yarn install && yarn run build

# Development Image
FROM node:18 as development

COPY docker/entrypoint.sh .

RUN chmod +x entrypoint.sh

WORKDIR /srv

ENTRYPOINT ["/entrypoint.sh"]

# Production Image
FROM node:18-alpine as production

COPY docker/entrypoint.sh .

RUN chmod +x entrypoint.sh

WORKDIR /app

COPY --from=builder /srv/package.json /srv/yarn.lock /srv/.yarn /srv/prisma .
COPY --from=builder /srv/dist ./dist

RUN yarn install --production

ENTRYPOINT ["/entrypoint.sh"]
11 changes: 11 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

echo "███████╗███╗ ██╗ █████╗ ██╗██╗ ██╗ ██╗ ██████╗ █████╗ ██████╗ ██████╗ ██████╗ ████████╗"
echo "██╔════╝████╗ ██║██╔══██╗██║██║ ╚██╗ ██╔╝██╔════╝██╔══██╗██╔══██╗ ██╔══██╗██╔═══██╗╚══██╔══╝"
echo "███████╗██╔██╗ ██║███████║██║██║ ╚████╔╝ ██║ ███████║██║ ██║ ██████╔╝██║ ██║ ██║"
echo "╚════██║██║╚██╗██║██╔══██║██║██║ ╚██╔╝ ██║ ██╔══██║██║ ██║ ██╔══██╗██║ ██║ ██║"
echo "███████║██║ ╚████║██║ ██║██║███████╗██║ ╚██████╗██║ ██║██████╔╝ ██████╔╝╚██████╔╝ ██║"
echo "╚══════╝╚═╝ ╚═══╝╚═╝ ╚═╝╚═╝╚══════╝╚═╝ ╚═════╝╚═╝ ╚═╝╚═════╝ ╚═════╝ ╚═════╝ ╚═╝"

[ $NODE_ENV == "development" ] && echo "App running in development mode" && yarn install && yarn run dev
[ $NODE_ENV == "production" ] && echo "App running in production mode" && yarn run start
5 changes: 0 additions & 5 deletions nodemon.json

This file was deleted.

19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@
"type": "module",
"license": "MIT",
"scripts": {
"dev": "npx prisma db push && nodemon",
"build": "npx prisma generate && npx swc ./src -d dist",
"start": "npx prisma migrate deploy && node dist/index.js",
"dev": "prisma migrate dev && tsx watch src/index.ts",
burnoutprojects marked this conversation as resolved.
Show resolved Hide resolved
"build": "prisma generate && swc src -d dist",
"start": "prisma migrate deploy && node ./dist/index.js",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json}\" --ignore-path .gitignore",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"test-tsc": "tsc --noEmit",
"postinstall": "npx prisma generate"
"postinstall": "prisma generate",
"docker-dev:start": "docker compose -f dev.compose.yaml build --no-cache && docker compose -f dev.compose.yaml up -d",
"docker-dev:stop": "docker compose -f dev.compose.yaml down",
"docker-prod:start": "docker compose -f prod.compose.yaml build --no-cache && docker compose -f prod.compose.yaml up -d",
"docker-prod:stop": "docker compose -f prod.compose.yaml down"
},
"dependencies": {
"@discordjs/builders": "^1.6.5",
"@prisma/client": "^5.5.2",
"@sentry/node": "^7.76.0",
"@swc/helpers": "^0.5.3",
"discord.js": "^14.13.0",
"dotenv": "^16.3.1",
"globby": "^13.2.2",
"pretty-ms": "^8.0.0",
"undici": "^5.27.0"
Expand All @@ -25,16 +31,13 @@
"@casperiv/eslint-config": "^8.0.0",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.95",
"@swc/helpers": "^0.5.3",
"@types/glob": "^8.1.0",
"@types/node": "^20.8.9",
"dotenv": "^16.3.1",
"eslint": "^8.52.0",
"nodemon": "^3.0.1",
"prettier": "^3.0.3",
"prisma": "^5.5.2",
"regenerator-runtime": "^0.14.0",
"ts-node": "^10.9.1",
"tsx": "^4.7.0",
"typescript": "^5.2.2"
},
"packageManager": "yarn@4.0.1"
Expand Down
30 changes: 30 additions & 0 deletions prod.compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "3.9"

services:
postgres:
container_name: "snailycad-bot-postgres"
image: postgres
command: -p ${DB_PORT:-55545}
env_file:
- .env
# ports:
# - "${DB_PORT:-55545}:${DB_PORT:-55545}"
burnoutprojects marked this conversation as resolved.
Show resolved Hide resolved
volumes:
- snailybot-db-data:/var/lib/postgresql/data

api:
container_name: "snaily-cad-bot"
image: snaily-cad-bot:prod
build:
context: .
dockerfile: ./docker/Dockerfile
target: production
env_file:
- .env
environment:
- NODE_ENV=production
depends_on:
- postgres

volumes:
snailybot-db-data:
burnoutprojects marked this conversation as resolved.
Show resolved Hide resolved
35 changes: 0 additions & 35 deletions prod.docker-compose.yml

This file was deleted.

21 changes: 11 additions & 10 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"exclude": [".dev-data", ".data"],
"include": [
"src/**/*"
],
"exclude": [
".dev-data",
".data",
"node_modules"
],
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */

/* Basic Options */
"target": "esnext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */,
"module": "esnext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
Expand All @@ -12,8 +18,9 @@
"importHelpers": true,
"outDir": "dist",
"sourceMap": true,
"lib": ["esnext"],

"lib": [
"esnext"
],
/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
"strictNullChecks": true /* Enable strict null checks. */,
Expand All @@ -22,24 +29,18 @@
"strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */,
"noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */,
"alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */,

/* Additional Checks */
"noUnusedLocals": true /* Report errors on unused locals. */,
"noUnusedParameters": true /* Report errors on unused parameters. */,
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
"noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
"noUncheckedIndexedAccess": true /* Include 'undefined' in index signature results */,
"noPropertyAccessFromIndexSignature": true /* Require undeclared properties from index signatures to use element accesses. */,

/* Module Resolution Options */
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,

/* Advanced Options */
"skipLibCheck": true /* Skip type checking of declaration files. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
},
"ts-node": {
"swc": true
burnoutprojects marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading