This repository has been archived on 2025-12-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
fullstack-open/part3/phonebook/node_modules/@flydotio/dockerfile/templates/Dockerfile.ejs
Andrew Trieu fa5d8255d6 Add part3
2023-05-23 08:05:53 +03:00

95 lines
2.2 KiB
Docker

# syntax = docker/dockerfile:1
# Adjust NODE_VERSION as desired
ARG NODE_VERSION=<%= nodeVersion %>
FROM node:${NODE_VERSION}-slim as base
LABEL fly_launch_runtime="<%= runtime %>"
# <%= runtime %> app lives here
WORKDIR /app
# Set production environment
ENV NODE_ENV=production
<% if (yarn && yarnVersion != yarnClassic) { -%>
ARG YARN_VERSION=<%= yarnVersion %>
<% if(yarnVersion.startsWith('3.')) {-%>
# Install Yarn 3
RUN corepack enable && \
yarn set version ${YARN_VERSION}
<% } else { -%>
RUN npm install -g yarn@$YARN_VERSION --force
<% } -%>
<% } else if (pnpm) { -%>
ARG PNPM_VERSION=<%= pnpmVersion %>
RUN npm install -g pnpm@$PNPM_VERSION
<% } %>
# Throw-away build stage to reduce size of final image
FROM base as build
# Install packages needed to build node modules
RUN apt-get update -qq && \
apt-get install -y <%= python %> pkg-config build-essential <%
if (prisma) { %>openssl <% } %>
# Install node modules
COPY --link <%= packageFiles.join(' ') %> ./
RUN <%= packagerInstall %>
<% if (prisma) { -%>
# Generate Prisma Client
COPY --link prisma .
RUN npx prisma generate
<% } -%>
# Copy application code
COPY --link . .
<% if (build) { -%>
# Build application
RUN <%= packager %> run build
<% } -%>
<% if (devDependencies && !nestjs) { -%>
# Remove development dependencies
RUN <%= packagerPrune %>
<% } -%>
# Final stage for app image
FROM base
# Copy built application
COPY --from=build /app /app
<% if (false && !options.root) /* needs more testing */ { -%>
# Run as a non-root user for security
RUN addgroup --system --gid 1001 nodejs && \
useradd <%= user %> --gid nodejs --home /app --shell /bin/bash
USER <%= user %>:nodejs
<% } -%>
<% if (entrypoint) { -%>
<% if (entrypointFixups.length) { -%>
# Adjust entrypoint to be executable on Linux
RUN <%- entrypointFixups.join(' && \\\n ') %>
<% } -%>
<% if (prisma) { -%>
# Entrypoint prepares the database.
<% } else { -%>
# Entrypoint sets up the container.
<% } -%>
ENTRYPOINT [ "/app/docker-entrypoint" ]
<% } -%>
# Start the server by default, this can be overwritten at runtime
EXPOSE <%= port %>
<% if (nuxtjs) { -%>
ENV HOST=0
<% } -%>
CMD <%- JSON.stringify(startCommand, null, 1).replaceAll(/\n\s*/g, " ") %>