55 lines
1.9 KiB
Docker
55 lines
1.9 KiB
Docker
# ──────────────────────────────────────────
|
|
# Stage 1: Build del frontend (assets JS/CSS)
|
|
# ──────────────────────────────────────────
|
|
FROM node:20-alpine AS frontend
|
|
WORKDIR /app
|
|
|
|
COPY package.json webpack.mix.js postcss.config.js tailwind.config.js ./
|
|
RUN npm install --legacy-peer-deps
|
|
|
|
COPY resources/ resources/
|
|
COPY public/ public/
|
|
RUN npm run production
|
|
|
|
# ──────────────────────────────────────────
|
|
# Stage 2: Build del binario Go
|
|
# ──────────────────────────────────────────
|
|
FROM golang:1.22-alpine AS builder
|
|
WORKDIR /app
|
|
|
|
# Instalar dependencias del sistema necesarias para CGO (argon2, etc.)
|
|
RUN apk add --no-cache gcc musl-dev
|
|
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
|
|
COPY . .
|
|
# Copiar assets del frontend compilados
|
|
COPY --from=frontend /app/public ./public
|
|
|
|
RUN CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w" -o apiv2 .
|
|
|
|
# ──────────────────────────────────────────
|
|
# Stage 3: Imagen final mínima
|
|
# ──────────────────────────────────────────
|
|
FROM alpine:3.20
|
|
WORKDIR /app
|
|
|
|
# Certificados TLS y timezone
|
|
RUN apk add --no-cache ca-certificates tzdata
|
|
|
|
# Copiar binario compilado
|
|
COPY --from=builder /app/apiv2 .
|
|
|
|
# Copiar archivos estáticos y plantillas
|
|
COPY --from=builder /app/public ./public
|
|
COPY --from=builder /app/resources/views ./resources/views
|
|
COPY --from=builder /app/assets ./assets
|
|
|
|
# config.yml se monta como volumen o se inyecta vía env en Coolify
|
|
COPY config.sample.yml ./config.yml
|
|
|
|
EXPOSE 8080
|
|
|
|
ENTRYPOINT ["./apiv2", "-config", "config.yml"]
|