feat: Update docker server dockerfile.

This commit is contained in:
SamTolmay 2021-06-01 14:04:10 +02:00
parent 8fb7c753c4
commit 0f52b35048
3 changed files with 35 additions and 10 deletions

View File

@ -1,19 +1,40 @@
FROM node:14-buster AS build
WORKDIR /lowdefy
COPY . .
# Install all dependencies needed for production build
# Can't try and cache this for src changes (just copy package.json)
# since we yarn install later
RUN yarn install
RUN yarn build
# Build lowdefy starter app
RUN yarn build:lowdefy-starter
# clean all depencies
RUN rm -rf node_modules
RUN yarn cache clean
# install production dependencies only
RUN yarn install --production
FROM node:14-alpine
ENV NODE_ENV=production
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
RUN mkdir -p /home/node/app && chown -R node:node /home/node/app
WORKDIR /home/node/app
COPY package.json ./
USER node
RUN npm install --only=production
COPY --from=build --chown=node:node /lowdefy/node_modules ./node_modules
COPY --chown=node:node ./dist ./dist
COPY --from=build --chown=node:node /lowdefy/dist ./dist
EXPOSE 3000
COPY --chown=node:node ./.lowdefy/build ./build
CMD ["node", "./dist/server.js"]
CMD ["node", "/home/node/app/dist/server.js"]

View File

@ -33,6 +33,7 @@
"babel": "babel src --out-dir dist",
"build": "yarn webpack && yarn babel",
"build:docker": "docker build --tag lowdefy/lowdefy .",
"build:lowdefy-starter": "lowdefy init && lowdefy build",
"clean": "rm -rf dist && rm -rf dev",
"prepare": "yarn build",
"start": "nodemon dist/server.js",
@ -58,6 +59,7 @@
"css-loader": "5.2.6",
"html-webpack-plugin": "5.3.1",
"jest": "26.6.3",
"lowdefy": "3.16.5",
"nodemon": "2.0.7",
"react": "17.0.2",
"react-dom": "17.0.2",

View File

@ -20,8 +20,11 @@ import { ApolloServer } from 'apollo-server-express';
import { typeDefs, resolvers, createContext } from '@lowdefy/graphql';
import { createGetSecretsFromEnv, readFile } from '@lowdefy/node-utils';
const configurationBasePath = process.env.LOWDEFY_SERVER_CONFIGURATION_PATH || './build';
const port = parseInt(process.env.LOWDEFY_SERVER_PORT) || 443;
const config = {
CONFIGURATION_BASE_PATH: path.resolve(process.cwd(), './build'),
CONFIGURATION_BASE_PATH: path.resolve(configurationBasePath),
getSecrets: createGetSecretsFromEnv(),
logger: console,
};
@ -61,5 +64,4 @@ app.use(express.static('dist/shell'));
// This should always be the last route
app.use(serveIndex);
// TODO: option to modify port here? port 443 by default?
app.listen({ port: 3000 }, () => console.log(`Server started at port 3000`));
app.listen({ port }, () => console.log(`Server started at port ${port}`));