diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ebec90d --- /dev/null +++ b/.dockerignore @@ -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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0a59533..b861c87 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,6 @@ lerna-debug.log* #e2e /e2e/.logs + +#dev +/config/dev.config.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dc357a1 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/config/config.yaml b/config/config.yaml deleted file mode 100644 index 01850cd..0000000 --- a/config/config.yaml +++ /dev/null @@ -1,22 +0,0 @@ -db: - path: ~/.silent-pay-indexer/db/database.sqlite - synchronize: false -app: - port: - verbose: - debug: - network: - requestRetry: - delay: # delay in Milliseconds - count: -providerType: -esplora: - url: - batchSize: -bitcoinCore: - protocol: - rpcHost: - rpcPass: - rpcUser: - rpcPort: - diff --git a/config/dev.config.yaml b/config/dev.config.yaml deleted file mode 100644 index b304d4a..0000000 --- a/config/dev.config.yaml +++ /dev/null @@ -1,21 +0,0 @@ -db: - path: ./.silent-pay-indexer/db/database.sqlite - synchronize: true -app: - port: 3000 - verbose: false - debug: true - network: regtest - requestRetry: - delay: 3000 - count: 3 -providerType: BITCOIN_CORE_RPC -esplora: - url: https://blockstream.info - batchSize: 5 -bitcoinCore: - protocol: http - rpcHost: 127.0.0.1 - rpcPass: password - rpcUser: admin - rpcPort: 18443 diff --git a/config/example.config.yaml b/config/example.config.yaml new file mode 100644 index 0000000..e09e393 --- /dev/null +++ b/config/example.config.yaml @@ -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 diff --git a/src/configuration.ts b/src/configuration.ts index 80119a8..89aa3b0 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -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);