update dev dockerfiles

This commit is contained in:
sid palas
2023-02-21 20:35:58 -05:00
parent d2a8e3a599
commit e796267218
6 changed files with 59 additions and 36 deletions

View File

@ -1,10 +1,7 @@
# Pin specific version for stability
# Use separate stage for building image
# Use debian for easier build utilities
FROM golang:1.19-bullseye AS base-builder
# Add non root user
RUN useradd -u 1001 nonroot
FROM golang:1.19-bullseye AS build-base
WORKDIR /app
@ -16,8 +13,7 @@ RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go mod download
# Dev stage with additional dev dependencies installed
FROM base-builder AS dev
FROM build-base AS dev
# Install air for hot reload & delve for debugging
RUN go install github.com/cosmtrek/air@latest && \
@ -27,8 +23,10 @@ COPY . .
CMD ["air", "-c", ".air.toml"]
# Production builder stage to produce the static binaries
FROM base-builder AS production-builder
FROM build-base AS build-production
# Add non root user
RUN useradd -u 1001 nonroot
COPY . .
@ -47,7 +45,7 @@ RUN go build \
-o api-golang
# Use separate stage for deployable image
FROM scratch AS production
FROM scratch
# Set gin mode
ENV GIN_MODE=release
@ -55,13 +53,13 @@ ENV GIN_MODE=release
WORKDIR /
# Copy the passwd file
COPY --from=production-builder /etc/passwd /etc/passwd
COPY --from=build-production /etc/passwd /etc/passwd
# Copy the healthcheck binary from the build stage
COPY --from=production-builder /app/healthcheck/healthcheck healthcheck
COPY --from=build-production /app/healthcheck/healthcheck healthcheck
# Copy the app binary from the build stage
COPY --from=production-builder /app/api-golang api-golang
COPY --from=build-production /app/api-golang api-golang
# Use nonroot user
USER nonroot

View File

@ -1,9 +1,6 @@
# Pin specific version for stability
# Use alpine for reduced image size
FROM node:19.6-alpine
# Set NODE_ENV
ENV NODE_ENV production
FROM node:19.6-alpine AS base
# Specify working directory other than /
WORKDIR /usr/src/app
@ -12,6 +9,21 @@ WORKDIR /usr/src/app
# dependencies (better layer caching)
COPY package*.json ./
FROM base as dev
RUN --mount=type=cache,target=/usr/src/app/.npm \
npm set cache /usr/src/app/.npm && \
npm install
COPY . .
CMD ["npm", "run", "dev"]
FROM base as production
# Set NODE_ENV
ENV NODE_ENV production
# Install only production dependencies
# Use cache mount to speed up install of existing dependencies
RUN --mount=type=cache,target=/usr/src/app/.npm \

View File

@ -2,9 +2,6 @@
# Use alpine for reduced image size
FROM node:19.6-alpine AS base
# Set NODE_ENV
ENV NODE_ENV production
# Specify working directory other than /
WORKDIR /usr/src/app
@ -12,21 +9,20 @@ WORKDIR /usr/src/app
# dependencies (better layer caching)
COPY package*.json ./
# Development stage to include dev + production dependencies
FROM base AS dev
FROM base as dev
# Install all dependencies (including development ones)
# For the dev image
RUN --mount=type=cache,target=/usr/src/app/.npm \
npm set cache /usr/src/app/.npm && \
npm install
COPY . .
CMD [ "npm", "run", "dev" ]
CMD ["npm", "run", "dev"]
# Production stage optimzed for deployment
FROM base AS production
FROM base as production
# Set NODE_ENV
ENV NODE_ENV production
# Install only production dependencies
# Use cache mount to speed up install of existing dependencies