-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added docker file and necessary utils for production environment
- Loading branch information
Showing
8 changed files
with
125 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,6 @@ lerna-debug.log* | |
|
||
#e2e | ||
/e2e/.logs | ||
|
||
#dev | ||
/config/dev.config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
db: | ||
path: ${SQLITE_PATH} | ||
synchronize: false | ||
app: | ||
port: ${PORT} | ||
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} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Stage 1: Build the NestJS application | ||
FROM node:18-alpine AS builder | ||
|
||
# Set the working directory in the container | ||
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:18-alpine AS production | ||
|
||
#Set the working directory in the container | ||
WORKDIR /app | ||
|
||
# Generate config.yml by replacing placeholders in config.yml.template | ||
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 --from=builder /app/migrate.js ./migrate.js | ||
|
||
#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="3000" | ||
|
||
EXPOSE $APP_PORT | ||
|
||
# Set up entrypoint to handle database migration and config generation | ||
ENTRYPOINT ["sh", "-c", "node migrate.js && envsubst < dist/config/config.template.yaml > dist/config/config.yaml && node dist/main.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const sqlite3 = require('sqlite3').verbose(); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// Set the database directory and file path | ||
const dbPath = process.env.SQLITE_PATH; | ||
const dbDir = path.dirname(dbPath); | ||
|
||
// Ensure the database directory exists, creating it if necessary | ||
if (!fs.existsSync(dbDir)) { | ||
fs.mkdirSync(dbDir, { recursive: true }); | ||
} | ||
|
||
const db = new sqlite3.Database(dbPath); | ||
|
||
// Function to run migrations | ||
async function runMigrations() { | ||
const migrationsDir = path.join(__dirname, 'migrations'); | ||
|
||
// Read migration files in sorted order | ||
const files = fs.readdirSync(migrationsDir).sort(); | ||
|
||
for (const file of files) { | ||
const filePath = path.join(migrationsDir, file); | ||
const sql = fs.readFileSync(filePath, 'utf-8'); | ||
console.log(`Running migration: ${file}`); | ||
|
||
// Execute each SQL file | ||
await new Promise((resolve, reject) => { | ||
db.exec(sql, (err) => { | ||
if (err) reject(err); | ||
else resolve(); | ||
}); | ||
}); | ||
} | ||
console.log('All migrations applied.'); | ||
} | ||
|
||
// Run migrations, then close the database connection | ||
runMigrations() | ||
.then(() => db.close()) | ||
.catch((err) => { | ||
console.error('Migration failed:', err); | ||
db.close(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TABLE IF NOT EXISTS "transaction" ( | ||
id TEXT PRIMARY KEY, | ||
blockHeight INTEGER NOT NULL, | ||
blockHash TEXT NOT NULL, | ||
scanTweak TEXT NOT NULL, | ||
outputs TEXT NOT NULL, | ||
isSpent BOOLEAN NOT NULL | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CREATE TABLE IF NOT EXISTS "operation_state" ( | ||
id TEXT PRIMARY KEY, | ||
state TEXT | ||
); |