Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the transpiled artifacts to build/ for a slimmer native Node Dock… #306

Merged
merged 1 commit into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduces the Docker image by ~100MB.


# 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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This broke the Docker build if the directory already existed.

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') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No password logs in production.

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