Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules
dist
.git
.gitignore
Dockerfile
docker-compose*
tests
coverage
*.log
.env*
33 changes: 33 additions & 0 deletions .env.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Environment
NODE_ENV=development
APP_ENVIRONMENT=docker
MAINTENANCE=false

# API
API_BASE_URL=http://localhost
API_PORT=3333

# APP
APP_URL=http://localhost:3000

# Secrets
COOKIE_DOMAIN=localhost
COOKIE_SECRET=super-secret-here
JWT_SECRET=super-secret-here

# E-mails
ENABLE_EMAILS=false
EMAIL_PROVIDER=ses
RESEND_KEY=resend-key
AWS_SES_REGION=aws-region
AWS_SES_ACCESS_KEY_ID=aws-access-key-id
AWS_SES_SECRET_ACCESS_KEY=aws-secret-access-key
AWS_SES_FROM_EMAIL=test@mail.com

# Database
DB_HOST=database
DB_PORT=3306
DB_DATABASE=abnmo_dev
DB_USERNAME=abnmo_user
DB_PASSWORD=abnmo_password
DB_ROOT_PASSWORD=abnmo_root_password
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Environment
NODE_ENV="test"
APP_ENVIRONMENT="local"
MAINTENANCE=false
MAINTENANCE="false"

# API
API_BASE_URL="http://localhost"
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# compiled output
/dist
/dist-lambda
/dist-docker
/node_modules
/build
lambda.zip
Expand Down Expand Up @@ -51,6 +52,7 @@ lerna-debug.log*
# temp directory
.temp
.tmp
.bkp

# Runtime data
pids
Expand Down
6 changes: 5 additions & 1 deletion infra/database/data.source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ const dataSource = new DataSource({
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
migrations: [
process.env.APP_ENVIRONMENT === 'docker'
? 'dist/infra/database/migrations/*.js'
: 'infra/database/migrations/*.ts',
],
entities: DATABASE_ENTITIES,
migrations: ['infra/database/migrations/**/*.ts'],
synchronize: false,
});

Expand Down
31 changes: 31 additions & 0 deletions infra/docker/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM node:22-slim AS builder

WORKDIR /app

COPY package*.json ./

RUN npm ci

COPY . .

RUN npm run build:docker
RUN npm prune --omit=dev

####

FROM node:22-slim AS runner

WORKDIR /app

RUN apt-get update && apt-get install -y netcat-openbsd && rm -rf /var/lib/apt/lists/*

COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist-docker ./dist
COPY --from=builder /app/package*.json ./

COPY infra/docker/dev/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

EXPOSE 3333

ENTRYPOINT ["/entrypoint.sh"]
46 changes: 46 additions & 0 deletions infra/docker/dev/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: svm_dev

services:
database:
image: mysql:8.4
container_name: 'svm_dev_mysql'
env_file:
- ../../../.env.docker
environment:
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_USER: ${DB_USERNAME}
MYSQL_PASSWORD: ${DB_PASSWORD}
ports:
- '${DB_PORT}:3306'
volumes:
- svm_dev_mysql_data:/var/lib/mysql
healthcheck:
test: ['CMD', 'mysqladmin', 'ping', '-h', 'localhost']
timeout: 5s
retries: 10
networks:
- svm_dev_network

api:
build:
context: ../../..
dockerfile: infra/docker/dev/Dockerfile
image: svm-dev-api
container_name: 'svm_dev_api'
ports:
- '${API_PORT}:3333'
env_file:
- ../../../.env.docker
depends_on:
database:
condition: service_healthy
networks:
- svm_dev_network

networks:
svm_dev_network:
driver: bridge

volumes:
svm_dev_mysql_data:
18 changes: 18 additions & 0 deletions infra/docker/dev/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
set -e

echo "Waiting for database..."

until nc -z "$DB_HOST" "$DB_PORT"; do
sleep 1
done

echo "Database is up"

echo "Running migrations..."
node node_modules/typeorm/cli.js \
-d dist/infra/database/data.source.js \
migration:run

echo "Starting API..."
exec node dist/src/app/main.js
16 changes: 8 additions & 8 deletions infra/scripts/build-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ const outDir = 'dist-lambda';
const zipFile = 'lambda.zip';

async function buildLambda() {
console.log('🚀 Starting Lambda build...');
console.log('Starting Lambda build...');

await fs.ensureDir(outDir);

try {
execSync('rm -rf dist dist-lambda lambda.zip', { stdio: 'inherit' });
execSync('npm run build', { stdio: 'inherit' });
execSync('npx nest build', { stdio: 'inherit' });
} catch (error) {
console.error('Failed TypeScript build:', error);
console.error('Failed TypeScript build:', error);
process.exit(1);
}

await build({
entryPoints: ['dist-lambda/app/lambda.js'],
entryPoints: ['dist/app/lambda.js'],
bundle: true,
platform: 'node',
target: 'node22',
Expand All @@ -39,15 +39,15 @@ async function buildLambda() {
try {
execSync(`cd ${outDir} && zip -r ../${zipFile} .`, { stdio: 'inherit' });
const { size } = await fs.stat(zipFile);
console.log(`Lambda bundle created: ${zipFile}`);
console.log(`📦 Size: ${(size / 1024 / 1024).toFixed(2)} MB`);
console.log(`Lambda bundle created: ${zipFile}`);
console.log(`Size: ${(size / 1024 / 1024).toFixed(2)} MB`);
} catch (error) {
console.error('Failed to zip:', error);
console.error('Failed to zip:', error);
process.exit(1);
}
}

buildLambda().catch((err) => {
console.error('Build failed:', err);
console.error('Build failed:', err);
process.exit(1);
});
Loading