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 ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|
||||||
|
# Copy source and build static binary
|
||||||
COPY . .
|
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) {
|
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:
|
backend:
|
||||||
build: ./backend
|
build: ./backend
|
||||||
restart: unless-stopped
|
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:
|
networks:
|
||||||
- easywish-network
|
- easywish-network
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,25 @@
|
|||||||
FROM node:18-alpine AS builder
|
#Dockerfile
|
||||||
WORKDIR /app
|
|
||||||
COPY package*.json .
|
|
||||||
RUN npm ci
|
|
||||||
COPY . .
|
|
||||||
RUN npm run build
|
|
||||||
RUN npm prune --production
|
|
||||||
|
|
||||||
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
|
WORKDIR /app
|
||||||
COPY --from=builder /app/build build/
|
|
||||||
COPY --from=builder /app/node_modules node_modules/
|
# Copy all local files into the image
|
||||||
COPY package.json .
|
COPY . .
|
||||||
EXPOSE 3000
|
|
||||||
ENV NODE_ENV=production
|
# Clean install all node modules
|
||||||
CMD [ "node", "build" ]
|
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