chore: update Dockerfile and add health check for storage service
This commit is contained in:
parent
5b009b209f
commit
bd6f3ed0fc
5 changed files with 52 additions and 21 deletions
|
|
@ -1,20 +1,11 @@
|
||||||
# Start from the latest golang base image
|
# Start from the latest golang base image
|
||||||
FROM golang:1.24-bullseye AS builder
|
FROM golang:1.24-alpine AS builder
|
||||||
|
|
||||||
# Set the Current Working Directory inside the container
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy go mod and sum files
|
|
||||||
COPY go.mod go.sum ./
|
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
|
RUN go mod download
|
||||||
|
|
||||||
# Copy the source from the current directory to the Working Directory inside the container
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-w -s" -trimpath -o main .
|
||||||
# Build the Go app
|
|
||||||
RUN CGO_ENABLED=0 GOOS=linux go build -o main .
|
|
||||||
|
|
||||||
# Start a new stage from alpine:latest
|
# Start a new stage from alpine:latest
|
||||||
FROM alpine:latest AS runner
|
FROM alpine:latest AS runner
|
||||||
|
|
@ -29,7 +20,8 @@ ARG CONCURRENT_IMAGES
|
||||||
ARG STORAGE_URL
|
ARG STORAGE_URL
|
||||||
ARG STORAGE_TOKEN
|
ARG STORAGE_TOKEN
|
||||||
|
|
||||||
RUN apk add --no-cache ffmpeg ca-certificates libc6-compat
|
RUN apk add --no-cache ca-certificates ffmpeg curl libwebp-tools
|
||||||
|
|
||||||
ENV GOMEMLIMIT=2750MiB
|
ENV GOMEMLIMIT=2750MiB
|
||||||
ENV GOGC=100
|
ENV GOGC=100
|
||||||
ENV PGHOST=$PGHOST
|
ENV PGHOST=$PGHOST
|
||||||
|
|
@ -46,20 +38,20 @@ WORKDIR /app
|
||||||
|
|
||||||
# Copy the Pre-built binary file from the previous stage
|
# Copy the Pre-built binary file from the previous stage
|
||||||
COPY --from=builder /app/main /app/.
|
COPY --from=builder /app/main /app/.
|
||||||
COPY --from=builder /app/public /app/public
|
|
||||||
COPY ./test.jpg /app/test.jpg
|
COPY ./test.jpg /app/test.jpg
|
||||||
COPY ./scripts /app/scripts
|
COPY ./scripts /app/scripts
|
||||||
COPY ./categorie.xml /app/categorie.xml
|
COPY ./categorie.xml /app/categorie.xml
|
||||||
COPY ./caratteristiche.xml /app/caratteristiche.xml
|
COPY ./caratteristiche.xml /app/caratteristiche.xml
|
||||||
RUN chmod +x /app/scripts/*.sh
|
RUN chmod +x /app/scripts/*.sh
|
||||||
|
|
||||||
#COPY --from=builder /app/.env /app/.env
|
RUN mkdir -p /app/.bin/webp \
|
||||||
# create folders
|
&& ln -s /usr/bin/cwebp /app/.bin/webp/cwebp \
|
||||||
RUN mkdir images
|
&& ln -s /usr/bin/dwebp /app/.bin/webp/dwebp \
|
||||||
RUN mkdir videos
|
&& ln -s /usr/bin/gif2webp /app/.bin/webp/gif2webp \
|
||||||
RUN mkdir failed_requests
|
&& ln -s /usr/bin/img2webp /app/.bin/webp/img2webp \
|
||||||
|
&& ln -s /usr/bin/webpmux /app/.bin/webp/webpmux
|
||||||
|
|
||||||
RUN apk add curl
|
RUN mkdir -p images videos failed_requests
|
||||||
|
|
||||||
# Expose port 1323 to the outside world
|
# Expose port 1323 to the outside world
|
||||||
EXPOSE 1323
|
EXPOSE 1323
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="element">
|
<div class="element">
|
||||||
<a href="/health" class="button" style="background-color: green;">Health DB</a>
|
<a href="/health" class="button" style="background-color: green;">Health Check</a>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,15 @@ func (s *Server) SetupRoutes() *echo.Echo {
|
||||||
})
|
})
|
||||||
e.GET("/health", func(c echo.Context) error {
|
e.GET("/health", func(c echo.Context) error {
|
||||||
h := queries.HealthCheck()
|
h := queries.HealthCheck()
|
||||||
return c.String(http.StatusOK, fmt.Sprintf("DB Connection: %v", h))
|
|
||||||
|
s_error := HealthCheckStorage()
|
||||||
|
var s string
|
||||||
|
if s_error != nil {
|
||||||
|
s = s_error.Error()
|
||||||
|
} else {
|
||||||
|
s = "OK"
|
||||||
|
}
|
||||||
|
return c.JSONPretty(http.StatusOK, fmt.Sprintf("DB Connection: %v, Storage Connection: %v", h, s), " ")
|
||||||
})
|
})
|
||||||
|
|
||||||
// MIOGEST ROUTES
|
// MIOGEST ROUTES
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,18 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func HealthCheckStorage() error {
|
||||||
|
resp, err := http.Get(config.Cfg.Storage.Endpoint + "/health")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("storage health check failed: %w", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return fmt.Errorf("storage health check failed: %s", resp.Status)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func DeleteFile(id string) error {
|
func DeleteFile(id string) error {
|
||||||
req, err := http.NewRequest("DELETE", config.Cfg.Storage.Endpoint+"/delete/"+id+"?token="+config.Cfg.Storage.Token, nil)
|
req, err := http.NewRequest("DELETE", config.Cfg.Storage.Endpoint+"/delete/"+id+"?token="+config.Cfg.Storage.Token, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
19
apps/backend/test.yml
Normal file
19
apps/backend/test.yml
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
services:
|
||||||
|
|
||||||
|
backend:
|
||||||
|
image: "test:latest"
|
||||||
|
ports:
|
||||||
|
- "1323:1323"
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
STORAGE_URL: http://host.docker.internal:8080
|
||||||
|
STORAGE_TOKEN: "test"
|
||||||
|
POSTGRES_USER: ${POSTGRES_USER}
|
||||||
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||||
|
POSTGRES_DB: ${POSTGRES_DB}
|
||||||
|
PGHOST: "host.docker.internal"
|
||||||
|
PGPORT: "5433"
|
||||||
|
IMAGEOPTION: "true"
|
||||||
|
CONCURRENT_IMAGES: ${CONCURRENT_IMAGES}
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Reference in a new issue