Skip to content

Commit

Permalink
added docker file and necessary utils for production environment
Browse files Browse the repository at this point in the history
  • Loading branch information
aruokhai committed Nov 11, 2024
1 parent 52c72d9 commit bb88f7b
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 44 deletions.
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

RUN apk add --no-cache gettext

#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 --only=production

# Set environment variables for SQLite path and app port
ENV SQLITE_PATH="/app/.silent-pay-indexer/db/database.sqlite"
ENV APP_PORT="80"

EXPOSE $APP_PORT

# Set up entrypoint to handle database migration and config generation
ENTRYPOINT ["sh", "-c", "npm run migration:run && envsubst < dist/config/config.template.yaml > dist/config/config.yaml && node dist/main.js"]
42 changes: 42 additions & 0 deletions config/config.template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
db:
path: ${SQLITE_PATH}
synchronize: false
app:
port: ${PORT}
verbose: ${VERBOSE}
debug: ${DEBUG}
network: ${NETWORK}
requestRetry:
delay: ${DELAY} # delay in Milliseconds
count: ${COUNT}
providerType: ${PROVIDER_TYPE}
esplora:
url: ${HOST}
batchSize: ${BATCH_SIZE}
bitcoinCore:
protocol: ${PROTOCOL} # http | https
rpcHost: ${RPC_HOST}
rpcPass: ${RPC_PASS}
rpcUser: ${RPC_USER}
rpcPort: ${RPC_PORT}


### Example ####
# db:
# path: ':memory:'
# synchronize: true
# app:
# port: 3000
# verbose: false
# debug: true
# network: regtest
# requestRetry:
# delay: 500
# count: 1
# providerType: BITCOIN_CORE_RPC
# bitcoinCore:
# protocol: http
# rpcHost: localhost
# rpcPass: password
# rpcUser: polaruser
# rpcPort: 18443
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.

2 changes: 1 addition & 1 deletion migrations/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function getEnvVariable(key: string): string {

async function configureDataSource(): Promise<DataSource> {
return new DataSource({
database: getEnvVariable('DB_PATH'),
database: getEnvVariable('SQLITE_PATH'),
type: 'sqlite',
synchronize: false,
logging: false,
Expand Down

0 comments on commit bb88f7b

Please sign in to comment.