Skip to content

Commit

Permalink
Fix asset caching (#153)
Browse files Browse the repository at this point in the history
* Switch to custom server

* remove app load context

* Simplify Dockerfile
  • Loading branch information
brookslybrand authored Dec 17, 2024
1 parent f6b1cf6 commit 7f42c96
Show file tree
Hide file tree
Showing 6 changed files with 242 additions and 96 deletions.
61 changes: 22 additions & 39 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,47 +1,30 @@
# base node image
FROM node:20-alpine as base

# set for base and all layer that inherit from it
ENV NODE_ENV production

# Install all node_modules, including dev dependencies
FROM base as deps

WORKDIR /myapp

ADD package.json package-lock.json .npmrc ./
RUN npm install --production=false

# Setup production node_modules
FROM base as production-deps

WORKDIR /myapp

COPY --from=deps /myapp/node_modules /myapp/node_modules
ADD package.json package-lock.json .npmrc ./
RUN npm prune --production

# Build the app
FROM base as build

WORKDIR /myapp

COPY --from=deps /myapp/node_modules /myapp/node_modules

ADD . .
FROM node:20-alpine AS development-dependencies-env
COPY . /app
WORKDIR /app
RUN npm ci

FROM node:20-alpine AS production-dependencies-env
COPY ./package.json package-lock.json .npmrc /app/
WORKDIR /app
RUN npm ci --omit=dev

FROM node:20-alpine AS build-env
COPY . /app/
COPY --from=development-dependencies-env /app/node_modules /app/node_modules
WORKDIR /app
RUN npm run build

# Finally, build the production image with minimal footprint
FROM base
FROM node:20-alpine
COPY ./package.json package-lock.json server.js /app/


ENV PORT="8080"
ENV NODE_ENV="production"

WORKDIR /myapp
COPY --from=production-dependencies-env /app/node_modules /app/node_modules
COPY --from=build-env /app/build /app/build
COPY --from=build-env /app/start.sh /app/start.sh

COPY --from=production-deps /myapp/node_modules /myapp/node_modules
COPY --from=build /myapp/build /myapp/build
COPY --from=build /myapp/package.json /myapp/package.json
COPY --from=build /myapp/start.sh /myapp/start.sh

CMD ["npm", "start"]
WORKDIR /app
CMD ["npm", "run", "start"]
Loading

0 comments on commit 7f42c96

Please sign in to comment.