feat: health check for backend in docker-compose;
feat: go dockerfile preinstalls curl; refactor: reduced go image size by using a 2 stage dockerfile; refactor: switch frontend dockerfile
This commit is contained in:
@@ -1,12 +1,30 @@
|
||||
FROM golang:1.24
|
||||
# Stage 1: Build the binary
|
||||
FROM golang:1.24 AS builder
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
WORKDIR /app
|
||||
|
||||
# Copy dependencies and download
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# Copy source and build static binary
|
||||
COPY . .
|
||||
RUN go build -v -o /usr/local/bin/app ./...
|
||||
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /main ./cmd/main.go
|
||||
|
||||
CMD ["app"]
|
||||
# Stage 2: Lightweight runtime with tools
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
# Install curl, shell (sh), and SSL certificates
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends curl ca-certificates && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Create non-root user and set ownership
|
||||
RUN groupadd -r appuser && useradd -r -g appuser appuser
|
||||
USER appuser
|
||||
|
||||
# Copy compiled binary
|
||||
COPY --from=builder /main /main
|
||||
|
||||
# Execute the binary
|
||||
CMD ["/main"]
|
||||
|
||||
@@ -7,5 +7,5 @@ import (
|
||||
)
|
||||
|
||||
func HealthCheck(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"status": "ok"})
|
||||
c.JSON(http.StatusOK, gin.H{"healthy": true})
|
||||
}
|
||||
|
||||
@@ -3,6 +3,13 @@ services:
|
||||
backend:
|
||||
build: ./backend
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "/usr/bin/curl", "-f", "http://localhost:8080/service/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
ports:
|
||||
- "8080:8080"
|
||||
networks:
|
||||
- easywish-network
|
||||
|
||||
|
||||
@@ -1,16 +1,25 @@
|
||||
FROM node:18-alpine AS builder
|
||||
WORKDIR /app
|
||||
COPY package*.json .
|
||||
RUN npm ci
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
RUN npm prune --production
|
||||
#Dockerfile
|
||||
|
||||
FROM node:18-alpine
|
||||
# Use this image as the platform to build the app
|
||||
FROM node:20.11-alpine AS external-website
|
||||
|
||||
# The WORKDIR instruction sets the working directory for everything that will happen next
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/build build/
|
||||
COPY --from=builder /app/node_modules node_modules/
|
||||
COPY package.json .
|
||||
EXPOSE 3000
|
||||
ENV NODE_ENV=production
|
||||
CMD [ "node", "build" ]
|
||||
|
||||
# Copy all local files into the image
|
||||
COPY . .
|
||||
|
||||
# Clean install all node modules
|
||||
RUN npm ci
|
||||
|
||||
# Build SvelteKit app
|
||||
RUN npm run build
|
||||
|
||||
# Delete source code files that were used to build the app that are no longer needed
|
||||
RUN rm -rf src/
|
||||
|
||||
# The USER instruction sets the user name to use as the default user for the remainder of the current stage
|
||||
USER node:node
|
||||
|
||||
# This is the command that will be run inside the image when you tell Docker to start the container
|
||||
CMD ["node","build/index.js"]
|
||||
|
||||
Reference in New Issue
Block a user