Skip to content

Commit

Permalink
Add the transpiled artifacts to build/ for a slimmer native Node Dock…
Browse files Browse the repository at this point in the history
…er container
  • Loading branch information
kwizzn authored and Overtorment committed Nov 22, 2021
1 parent aca47a2 commit 05eace7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*
!build/
!class/
!controllers/
!scripts/
!static/
!templates/
!utils/
!*.js
!.babelrc
!.eslint*
!admin.macaroon
!package*.json
!rpc.proto
!tls.cert
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

admin.macaroon
tls.cert
build/
logs/

# dependencies
Expand Down
13 changes: 6 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@ RUN apt-get update && apt-get -y install python3

WORKDIR /lndhub

# Copy 'package-lock.json' and 'package.json'
COPY package.json package-lock.json ./
# Copy project files and folders to the current working directory
COPY . .

# Install dependencies
RUN npm i

# Copy project files and folders to the current working directory
COPY . .
RUN npm run build

# Delete git data as it's not needed inside the container
RUN rm -rf .git

FROM node:16-bullseye-slim
FROM node:16-alpine

# Create a specific user so LNDHub doesn't run as root
COPY --from=perms /etc/group /etc/passwd /etc/shadow /etc/
Expand All @@ -34,10 +32,11 @@ COPY --from=perms /etc/group /etc/passwd /etc/shadow /etc/
COPY --from=builder /lndhub /lndhub

# Create logs folder and ensure permissions are set correctly
RUN mkdir /lndhub/logs && chown -R lndhub:lndhub /lndhub
RUN mkdir -p /lndhub/logs && chown -R lndhub:lndhub /lndhub
USER lndhub

ENV PORT=3000
EXPOSE 3000
WORKDIR /lndhub

CMD cp $LND_CERT_FILE /lndhub/ && cp $LND_ADMIN_MACAROON_FILE /lndhub/ && cd /lndhub && npm start
4 changes: 3 additions & 1 deletion controllers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ let express = require('express');
let router = express.Router();
let logger = require('../utils/logger');
const MIN_BTC_BLOCK = 670000;
console.log('using config', JSON.stringify(config));
if (process.env.NODE_ENV !== 'prod') {
console.log('using config', JSON.stringify(config));
}

var Redis = require('ioredis');
var redis = new Redis(config.redis);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "./node_modules/.bin/babel ./ --ignore node_modules/ --ignore *.spec.js --out-dir ./build",
"dev": "nodemon node_modules/.bin/babel-node index.js",
"start": "node_modules/.bin/babel-node index.js",
"lint": "./node_modules/.bin/eslint ./ controllers/ class/ --fix"
Expand Down

0 comments on commit 05eace7

Please sign in to comment.