Skip to content

Commit

Permalink
build: add Dockerfile and docker-compose.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
ahonn committed Mar 19, 2024
1 parent 88f33e4 commit 565c7a0
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.vercel
coverage
dist
node_modules
.env
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:20-slim

WORKDIR /app

COPY . .

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable pnpm

RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm run build

EXPOSE 3000
ENV ADDRESS=0.0.0.0 PORT=3000
CMD ["pnpm", "start"]
27 changes: 27 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3.8'

services:
app:
build:
context: .
ports:
- '3000:3000'
environment:
- REDIS_URL=redis://redis:6379
- JWT_SECRET=testnet_secret
- ADMIN_USERNAME=adolake
- ADMIN_PASSWORD=adolake1324
- BITCOIN_JSON_RPC_URL=https://btc-rpc-proxy-128f6a15.nip.io/
- BITCOIN_JSON_RPC_USERNAME=JoyID
- BITCOIN_JSON_RPC_PASSWORD=BTC_testnet_adolake1324
- BITCOIN_ELECTRS_API_URL=https://electrs-api-128f6a15.nip.io
depends_on:
- redis

redis:
image: redis:latest
ports:
- '6379:6379'
volumes:
- ./data:/root/redis
- ./redis.conf:/usr/local/etc/redis/redis.conf
2 changes: 2 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ if (env.SENTRY_DSN_URL && env.NODE_ENV !== 'development') {
const isTokenRoutesEnable = env.NODE_ENV === 'production' ? env.ADMIN_USERNAME && env.ADMIN_PASSWORD : true;

async function routes(fastify: FastifyInstance) {
fastify.log.info(`Process env: ${JSON.stringify(env, null, 2)}`);

container.register({ logger: asValue(fastify.log) });
fastify.decorate('container', container);

Expand Down
1 change: 1 addition & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import process from 'node:process';
const envSchema = z.object({
NODE_ENV: z.string().default('development'),
PORT: z.string().optional(),
ADDRESS: z.string().optional(),
NETWORK: z.string().default('testnet'),

SENTRY_DSN_URL: z.string().optional(),
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { env } from './env';
import { buildFastify } from './app';

const port = parseInt(env.PORT || '3000', 10);
const host = env.ADDRESS || '0.0.0.0';

const app = buildFastify();

app.listen({ port }, (err, address) => {
app.listen({ port, host }, (err, address) => {
if (err) {
console.error(err);
process.exit(1);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default fp(async (fastify) => {
return;
}

fastify.register(import('@fastify/redis'), { client: redis });
await fastify.register(import('@fastify/redis'), { client: redis });

fastify.addHook('onRequest', (request, reply, done) => {
if (request.url.startsWith(DOCS_ROUTE_PREFIX)) {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/bitcoin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const Output = z.object({
const Input = z.object({
txid: z.string(),
vout: z.number(),
prevout: Output,
prevout: Output.or(z.null()),
scriptsig: z.string(),
scriptsig_asm: z.string(),
witness: z.array(z.string()).optional(),
Expand Down

0 comments on commit 565c7a0

Please sign in to comment.