Use additional_contexts to copy platform server package into the Docker build context. Rewrites the file: dependency path and removes the lockfile so npm install can resolve the local package correctly. Applied to both production and dev Dockerfiles.
32 lines
819 B
Docker
32 lines
819 B
Docker
# Node.js backend
|
|
FROM node:18-alpine
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy platform server package from additional build context
|
|
COPY --from=platform-server . /app/platform-server/
|
|
RUN rm -rf /app/platform-server/node_modules
|
|
|
|
# Copy package files
|
|
COPY package*.json ./
|
|
|
|
# Rewrite file: dependency to use the local copy inside the container
|
|
RUN sed -i 's|file:../../cc-platform-core/server|file:./platform-server|' package.json \
|
|
&& rm -f package-lock.json
|
|
|
|
# Install dependencies
|
|
RUN npm install --omit=dev
|
|
|
|
# Copy all server code
|
|
COPY . .
|
|
|
|
# Expose ports
|
|
EXPOSE 3001 3002
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD node -e "require('http').get('http://localhost:3001/api/turtles', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
|
|
|
|
# Start server
|
|
CMD ["node", "server.js"]
|