diff --git a/apps/backend/Dockerfile b/apps/backend/Dockerfile index 8c0d0c7..4e1b277 100644 --- a/apps/backend/Dockerfile +++ b/apps/backend/Dockerfile @@ -1,20 +1,11 @@ # 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 - -# 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 . +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-w -s" -trimpath -o main . # Start a new stage from alpine:latest FROM alpine:latest AS runner @@ -29,7 +20,8 @@ ARG CONCURRENT_IMAGES ARG STORAGE_URL 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 GOGC=100 ENV PGHOST=$PGHOST @@ -46,20 +38,20 @@ 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 COPY ./scripts /app/scripts 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 mkdir -p /app/.bin/webp \ + && ln -s /usr/bin/cwebp /app/.bin/webp/cwebp \ + && ln -s /usr/bin/dwebp /app/.bin/webp/dwebp \ + && ln -s /usr/bin/gif2webp /app/.bin/webp/gif2webp \ + && 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 1323 diff --git a/apps/backend/public/views/main.html b/apps/backend/public/views/main.html index daa91be..32f8af8 100644 --- a/apps/backend/public/views/main.html +++ b/apps/backend/public/views/main.html @@ -90,7 +90,7 @@
diff --git a/apps/backend/server.go b/apps/backend/server.go index 7df28c3..fee0d51 100644 --- a/apps/backend/server.go +++ b/apps/backend/server.go @@ -79,7 +79,15 @@ func (s *Server) SetupRoutes() *echo.Echo { }) e.GET("/health", func(c echo.Context) error { 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 diff --git a/apps/backend/storage.go b/apps/backend/storage.go index 3490e35..2b9d701 100644 --- a/apps/backend/storage.go +++ b/apps/backend/storage.go @@ -14,6 +14,18 @@ import ( "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 { req, err := http.NewRequest("DELETE", config.Cfg.Storage.Endpoint+"/delete/"+id+"?token="+config.Cfg.Storage.Token, nil) if err != nil { diff --git a/apps/backend/test.yml b/apps/backend/test.yml new file mode 100644 index 0000000..7d6371a --- /dev/null +++ b/apps/backend/test.yml @@ -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} + +