Refactor Dockerfiles to remove unnecessary comments and echo statements; streamline build stages for clarity and efficiency.
This commit is contained in:
parent
0ca2cfc2bc
commit
ebbcff2e41
2 changed files with 3 additions and 43 deletions
|
|
@ -1,24 +1,11 @@
|
|||
# Start from the latest golang base image
|
||||
FROM golang:1.24-bullseye AS builder
|
||||
|
||||
# Set the Current Working Directory inside the container
|
||||
WORKDIR /app
|
||||
|
||||
# Copy go mod and sum files
|
||||
COPY go.mod go.sum ./
|
||||
|
||||
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
|
||||
RUN go mod download
|
||||
|
||||
# Copy the source from the current directory to the Working Directory inside the container
|
||||
COPY . .
|
||||
|
||||
# Build the Go app
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -o main .
|
||||
|
||||
# Start a new stage from alpine:latest
|
||||
FROM alpine:latest AS runner
|
||||
|
||||
ARG POSTGRES_USER
|
||||
ARG POSTGRES_PASSWORD
|
||||
ARG POSTGRES_DB
|
||||
|
|
@ -29,7 +16,7 @@ ARG CONCURRENT_IMAGES
|
|||
ARG STORAGE_URL
|
||||
ARG STORAGE_TOKEN
|
||||
|
||||
RUN apk add --no-cache ffmpeg ca-certificates libc6-compat
|
||||
RUN apk add --no-cache ffmpeg ca-certificates libc6-compat curl
|
||||
ENV GOMEMLIMIT=2750MiB
|
||||
ENV GOGC=100
|
||||
ENV PGHOST=$PGHOST
|
||||
|
|
@ -43,8 +30,6 @@ ENV STORAGE_URL=$STORAGE_URL
|
|||
ENV STORAGE_TOKEN=$STORAGE_TOKEN
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the Pre-built binary file from the previous stage
|
||||
COPY --from=builder /app/main /app/.
|
||||
COPY --from=builder /app/public /app/public
|
||||
COPY ./test.jpg /app/test.jpg
|
||||
|
|
@ -53,16 +38,8 @@ COPY ./categorie.xml /app/categorie.xml
|
|||
COPY ./caratteristiche.xml /app/caratteristiche.xml
|
||||
RUN chmod +x /app/scripts/*.sh
|
||||
|
||||
#COPY --from=builder /app/.env /app/.env
|
||||
# create folders
|
||||
RUN mkdir images
|
||||
RUN mkdir videos
|
||||
RUN mkdir failed_requests
|
||||
|
||||
RUN apk add curl
|
||||
|
||||
# Expose port 1323 to the outside world
|
||||
EXPOSE 1323
|
||||
|
||||
# Command to run the executable
|
||||
CMD ["./main"]
|
||||
CMD ["./main"]
|
||||
|
|
@ -1,20 +1,12 @@
|
|||
FROM node:22-alpine AS base
|
||||
|
||||
# Dependencies stage
|
||||
# This stage is used to install dependencies and prepare the environment
|
||||
FROM base AS deps
|
||||
RUN apk add --no-cache libc6-compat openssl
|
||||
WORKDIR /app
|
||||
COPY package.json ./
|
||||
ENV NODE_ENV=production
|
||||
|
||||
RUN echo "base variables: $NODE_ENV is set to $NODE_ENV"
|
||||
RUN npm i --omit=dev
|
||||
|
||||
RUN echo "Dependencies installed successfully"
|
||||
|
||||
# Builder stage
|
||||
# This stage is used to build the application
|
||||
FROM base AS builder
|
||||
WORKDIR /app
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
|
|
@ -24,7 +16,7 @@ ENV NODE_ENV=production
|
|||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
ENV SKIP_REDIS="true"
|
||||
|
||||
# Only essential build-time variables
|
||||
|
||||
ARG BASE_URL
|
||||
ENV BASE_URL=$BASE_URL
|
||||
ARG NEXT_PUBLIC_BASE_URL
|
||||
|
|
@ -63,15 +55,8 @@ ENV STRIPE_WEBHOOK_SECRET="mock"
|
|||
# ENV REVALIDATION_SECRET="mock"
|
||||
# ENV STORAGE_URL="mock"
|
||||
# ENV STORAGE_TOKEN="mock"
|
||||
|
||||
RUN SKIP_ENV_VALIDATION=1 npm run build
|
||||
|
||||
|
||||
RUN echo "Build completed successfully"
|
||||
RUN echo "Build with BASE_URL=$BASE_URL and NEXT_PUBLIC_BASE_URL=$NEXT_PUBLIC_BASE_URL"
|
||||
|
||||
# Runner stage
|
||||
# This stage is used to run the built application
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
|
||||
|
|
@ -149,7 +134,5 @@ USER nextjs
|
|||
EXPOSE 3000
|
||||
ENV PORT=3000
|
||||
|
||||
RUN echo "Starting application with BASE_URL=$BASE_URL and NEXT_PUBLIC_BASE_URL=$NEXT_PUBLIC_BASE_URL"
|
||||
|
||||
CMD ["node", "server.js"]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue