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

Add Dockerfile For Deployment #54

Merged
merged 1 commit into from
Nov 27, 2024
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
44 changes: 44 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# compiled output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
/.silent-pay-indexer

#e2e
/e2e/.logs

#dev
/config/dev.config.yaml
/config/e2e.config.yaml
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ lerna-debug.log*

#e2e
/e2e/.logs

#dev
/config/dev.config.yaml
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Stage 1: Build the NestJS application
FROM node:22-alpine AS builder

WORKDIR /app

# Copy package.json and package-lock.json for efficient layer caching
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application code
COPY . .

# Build the application
RUN npm run build

# Stage 2: Production image
FROM node:22-alpine AS production

WORKDIR /app

#Copy the compiled application from the build stage
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/migrations ./migrations

#Copy package.json and install only production dependencies
COPY package*.json ./
RUN npm install --omit=dev

# Set environment variables for SQLite path and app port
ENV DB_PATH="/app/data/database.sqlite"
ENV APP_PORT="80"

VOLUME /app/data

EXPOSE $APP_PORT

# Set up entrypoint to handle database migration and config generation
ENTRYPOINT ["sh", "-c", "npm run migration:run && mv dist/config/example.config.yaml dist/config/config.yaml && node dist/main.js"]
22 changes: 0 additions & 22 deletions config/config.yaml

This file was deleted.

21 changes: 0 additions & 21 deletions config/dev.config.yaml

This file was deleted.

18 changes: 18 additions & 0 deletions config/example.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
db:
path: '~/.silent-pay-indexer/db/database.sqlite'
synchronize: false
app:
port: 3000
verbose: false
debug: true
network: regtest
requestRetry:
delay: 500 # delay in Milliseconds
count: 3
providerType: BITCOIN_CORE_RPC
bitcoinCore:
protocol: http # http | https
rpcHost: localhost
rpcPass: password
rpcUser: polaruser
rpcPort: 18443
2 changes: 1 addition & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function mergeEnvVariablesRecursive(
for (const key of Object.keys(config)) {
const currentEnvVarName = envVarName
? `${envVarName}_${camelToSnakeCase(key)}`
: key.toUpperCase();
: camelToSnakeCase(key);
const currentEnvVarValue = process.env[currentEnvVarName];
if (config[key] && typeof config[key] === 'object') {
mergeEnvVariablesRecursive(config[key], currentEnvVarName);
Expand Down