restructure repo, separate sample app from docker configs
This commit is contained in:
7
06-building-container-images/api-node/Dockerfile.0
Normal file
7
06-building-container-images/api-node/Dockerfile.0
Normal file
@ -0,0 +1,7 @@
|
||||
FROM node
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN npm install
|
||||
|
||||
CMD [ "node", "index.js" ]
|
||||
9
06-building-container-images/api-node/Dockerfile.1
Normal file
9
06-building-container-images/api-node/Dockerfile.1
Normal file
@ -0,0 +1,9 @@
|
||||
# Pin specific version
|
||||
# Use alpine for reduced image size
|
||||
FROM node:19.4-alpine
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN npm install
|
||||
|
||||
CMD [ "node", "index.js" ]
|
||||
12
06-building-container-images/api-node/Dockerfile.2
Normal file
12
06-building-container-images/api-node/Dockerfile.2
Normal file
@ -0,0 +1,12 @@
|
||||
# Pin specific version
|
||||
# Use alpine for reduced image size
|
||||
FROM node:19.4-alpine
|
||||
|
||||
# Specify working directory other than /
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN npm install
|
||||
|
||||
CMD [ "node", "index.js" ]
|
||||
18
06-building-container-images/api-node/Dockerfile.3
Normal file
18
06-building-container-images/api-node/Dockerfile.3
Normal file
@ -0,0 +1,18 @@
|
||||
# Pin specific version for stability
|
||||
# Use alpine for reduced image size
|
||||
FROM node:19.4-alpine
|
||||
|
||||
# Specify working directory other than /
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Copy only files required to install
|
||||
# dependencies (better layer caching)
|
||||
COPY package*.json ./
|
||||
|
||||
RUN npm install
|
||||
|
||||
# Copy remaining source code AFTER installing dependencies.
|
||||
# Again, copy only the necessary files
|
||||
COPY ./src/ .
|
||||
|
||||
CMD [ "node", "index.js" ]
|
||||
22
06-building-container-images/api-node/Dockerfile.4
Normal file
22
06-building-container-images/api-node/Dockerfile.4
Normal file
@ -0,0 +1,22 @@
|
||||
# Pin specific version for stability
|
||||
# Use alpine for reduced image size
|
||||
FROM node:19.4-alpine
|
||||
|
||||
# Specify working directory other than /
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Copy only files required to install
|
||||
# dependencies (better layer caching)
|
||||
COPY package*.json ./
|
||||
|
||||
RUN npm install
|
||||
|
||||
# Use non-root user
|
||||
# Use --chown on COPY commands to set file permissions
|
||||
USER node
|
||||
|
||||
# Copy remaining source code AFTER installing dependencies.
|
||||
# Again, copy only the necessary files
|
||||
COPY --chown=node:node ./src/ .
|
||||
|
||||
CMD [ "node", "index.js" ]
|
||||
26
06-building-container-images/api-node/Dockerfile.5
Normal file
26
06-building-container-images/api-node/Dockerfile.5
Normal file
@ -0,0 +1,26 @@
|
||||
# Pin specific version for stability
|
||||
# Use alpine for reduced image size
|
||||
FROM node:19.4-alpine
|
||||
|
||||
# Set NODE_ENV
|
||||
ENV NODE_ENV production
|
||||
|
||||
# Specify working directory other than /
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Copy only files required to install
|
||||
# dependencies (better layer caching)
|
||||
COPY package*.json ./
|
||||
|
||||
# Install only production dependencies
|
||||
RUN npm ci --only=production
|
||||
|
||||
# Use non-root user
|
||||
# Use --chown on COPY commands to set file permissions
|
||||
USER node
|
||||
|
||||
# Copy remaining source code AFTER installing dependencies.
|
||||
# Again, copy only the necessary files
|
||||
COPY --chown=node:node ./src/ .
|
||||
|
||||
CMD [ "node", "index.js" ]
|
||||
29
06-building-container-images/api-node/Dockerfile.6
Normal file
29
06-building-container-images/api-node/Dockerfile.6
Normal file
@ -0,0 +1,29 @@
|
||||
# Pin specific version for stability
|
||||
# Use alpine for reduced image size
|
||||
FROM node:19.4-alpine
|
||||
|
||||
# Set NODE_ENV
|
||||
ENV NODE_ENV production
|
||||
|
||||
# Specify working directory other than /
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Copy only files required to install
|
||||
# dependencies (better layer caching)
|
||||
COPY package*.json ./
|
||||
|
||||
# Install only production dependencies
|
||||
RUN npm ci --only=production
|
||||
|
||||
# Use non-root user
|
||||
# Use --chown on COPY commands to set file permissions
|
||||
USER node
|
||||
|
||||
# Copy remaining source code AFTER installing dependencies.
|
||||
# Again, copy only the necessary files
|
||||
COPY --chown=node:node ./src/ .
|
||||
|
||||
# Indicate expected port
|
||||
EXPOSE 3000
|
||||
|
||||
CMD [ "node", "index.js" ]
|
||||
36
06-building-container-images/api-node/Dockerfile.7
Normal file
36
06-building-container-images/api-node/Dockerfile.7
Normal file
@ -0,0 +1,36 @@
|
||||
# Pin specific version for stability
|
||||
# Use alpine for reduced image size
|
||||
FROM node:19.4-alpine
|
||||
|
||||
# Set NODE_ENV
|
||||
ENV NODE_ENV production
|
||||
|
||||
# Specify working directory other than /
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Copy only files required to install
|
||||
# dependencies (better layer caching)
|
||||
COPY package*.json ./
|
||||
|
||||
# Install only production dependencies
|
||||
# Use cache mount to speed up install of existing dependencies
|
||||
RUN --mount=type=cache,target=/usr/src/app/.npm \
|
||||
npm set cache /usr/src/app/.npm && \
|
||||
npm ci --only=production
|
||||
|
||||
# Use non-root user
|
||||
# Use --chown on COPY commands to set file permissions
|
||||
USER node
|
||||
|
||||
# Copy remaining source code AFTER installing dependencies.
|
||||
# Again, copy only the necessary files
|
||||
COPY --chown=node:node ./src/ .
|
||||
|
||||
# Indicate expected port
|
||||
EXPOSE 3000
|
||||
|
||||
CMD [ "node", "index.js" ]
|
||||
|
||||
# TODO: Use multi-stage with distroless image or chainguard image?
|
||||
# https://github.com/GoogleContainerTools/distroless/blob/main/examples/nodejs/Dockerfile
|
||||
# https://edu.chainguard.dev/chainguard/chainguard-images/reference/node/overview/
|
||||
12
06-building-container-images/api-node/Makefile
Normal file
12
06-building-container-images/api-node/Makefile
Normal file
@ -0,0 +1,12 @@
|
||||
API_NODE_PATH:=../../05-example-web-application/api-node/
|
||||
|
||||
N?=0
|
||||
.PHONY: build-N
|
||||
build-N:
|
||||
docker build --file ./Dockerfile.$(N) -t api-node:$(N) ${API_NODE_PATH}
|
||||
|
||||
.PHONY: build-all
|
||||
build-all:
|
||||
for number in 0 1 2 3 4 5 6 7 ; do \
|
||||
N=$$number $(MAKE) build-N; \
|
||||
done
|
||||
Reference in New Issue
Block a user