Skip to content

Commit 05eace7

Browse files
kwizznOvertorment
authored andcommitted
Add the transpiled artifacts to build/ for a slimmer native Node Docker container
1 parent aca47a2 commit 05eace7

5 files changed

Lines changed: 26 additions & 8 deletions

File tree

.dockerignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*
2+
!build/
3+
!class/
4+
!controllers/
5+
!scripts/
6+
!static/
7+
!templates/
8+
!utils/
9+
!*.js
10+
!.babelrc
11+
!.eslint*
12+
!admin.macaroon
13+
!package*.json
14+
!rpc.proto
15+
!tls.cert

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
admin.macaroon
44
tls.cert
5+
build/
56
logs/
67

78
# dependencies

Dockerfile

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,17 @@ RUN apt-get update && apt-get -y install python3
1313

1414
WORKDIR /lndhub
1515

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

1919
# Install dependencies
2020
RUN npm i
21-
22-
# Copy project files and folders to the current working directory
23-
COPY . .
21+
RUN npm run build
2422

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

28-
FROM node:16-bullseye-slim
26+
FROM node:16-alpine
2927

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

3634
# Create logs folder and ensure permissions are set correctly
37-
RUN mkdir /lndhub/logs && chown -R lndhub:lndhub /lndhub
35+
RUN mkdir -p /lndhub/logs && chown -R lndhub:lndhub /lndhub
3836
USER lndhub
3937

4038
ENV PORT=3000
4139
EXPOSE 3000
40+
WORKDIR /lndhub
4241

4342
CMD cp $LND_CERT_FILE /lndhub/ && cp $LND_ADMIN_MACAROON_FILE /lndhub/ && cd /lndhub && npm start

controllers/api.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ let express = require('express');
55
let router = express.Router();
66
let logger = require('../utils/logger');
77
const MIN_BTC_BLOCK = 670000;
8-
console.log('using config', JSON.stringify(config));
8+
if (process.env.NODE_ENV !== 'prod') {
9+
console.log('using config', JSON.stringify(config));
10+
}
911

1012
var Redis = require('ioredis');
1113
var redis = new Redis(config.redis);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
8+
"build": "./node_modules/.bin/babel ./ --ignore node_modules/ --ignore *.spec.js --out-dir ./build",
89
"dev": "nodemon node_modules/.bin/babel-node index.js",
910
"start": "node_modules/.bin/babel-node index.js",
1011
"lint": "./node_modules/.bin/eslint ./ controllers/ class/ --fix"

0 commit comments

Comments
 (0)