Merge remote-tracking branch 'enko/feature/reduced-container-size'

This commit is contained in:
Travis Ralston 2020-12-28 20:20:57 -07:00
commit 196fafa2e5
3 changed files with 44 additions and 27 deletions

View file

@ -1,47 +1,44 @@
FROM node:10.16.0-alpine
FROM node:12.16.1-alpine AS builder
LABEL maintainer="Andreas Peters <support@aventer.biz>"
#Upstream URL: https://git.aventer.biz/AVENTER/docker-matrix-dimension
RUN apk add dos2unix --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/community/ --allow-untrusted
WORKDIR /home/node/matrix-dimension
RUN apk update && \
apk add --no-cache bash gcc python make g++ sqlite && \
mkdir /home/node/.npm-global && \
mkdir -p /home/node/app
RUN mkdir -p /home/node/matrix-dimension
COPY ./docker-entrypoint.sh /
COPY . /home/node/matrix-dimension
RUN chown -R node:node /home/node/app && \
chown -R node:node /home/node/.npm-global && \
chown -R node:node /home/node/matrix-dimension
RUN chown -R node /home/node/matrix-dimension
USER node
ENV PATH=/home/node/.npm-global/bin:$PATH
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
RUN npm clean-install && \
node /home/node/matrix-dimension/scripts/convert-newlines.js /home/node/matrix-dimension/docker-entrypoint.sh && \
NODE_ENV=production npm run-script build
RUN cd /home/node/matrix-dimension && \
npm install -D wd rimraf webpack webpack-command sqlite3 pg pg-hstore && \
NODE_ENV=production npm run-script build:web && npm run-script build:app
FROM node:12.16.1-alpine
USER root
WORKDIR /home/node/matrix-dimension
RUN apk del gcc make g++ && \
rm /home/node/matrix-dimension/Dockerfile && \
rm /home/node/matrix-dimension/docker-entrypoint.sh && \
dos2unix /docker-entrypoint.sh
COPY --from=builder /home/node/matrix-dimension/docker-entrypoint.sh /
COPY --from=builder /home/node/matrix-dimension/build /home/node/matrix-dimension/build
COPY --from=builder /home/node/matrix-dimension/package* /home/node/matrix-dimension/
COPY --from=builder /home/node/matrix-dimension/config /home/node/matrix-dimension/config
RUN chown -R node /home/node/matrix-dimension
USER node
RUN npm clean-install --production
VOLUME ["/data"]
# Ensure the database doesn't get lost to the container
ENV DIMENSION_DB_PATH=/data/dimension.db
EXPOSE 8184
#CMD ["/bin/sh"]
# CMD ["/bin/sh"]
ENTRYPOINT ["/docker-entrypoint.sh"]

View file

@ -1,7 +1,4 @@
#!/bin/bash
set -e
cd /home/node/matrix-dimension/
#!/bin/sh
if [ -f "/data/config.yaml" ]; then
cp /data/config.yaml /home/node/matrix-dimension/config/production.yaml

View file

@ -0,0 +1,23 @@
const fs = require('fs');
const util = require('util');
(async function () {
if (process.argv.length !== 3) {
console.error('Wrong number of arguments');
process.exit(-1);
}
const filePath = process.argv.pop();
const fileExists = await util.promisify(fs.exists)(filePath);
if (fileExists) {
const file = await fs.promises.readFile(filePath, { encoding: 'utf-8' });
await fs.promises.writeFile(
filePath,
file
.replace(/\r\n/g, '\n')
.replace(/\r/, '\n'),
);
}
})();