This commit is contained in:
Jan Barfuss 2025-03-02 12:03:17 +01:00
commit d37cacf2b7
3 changed files with 11 additions and 25 deletions

2
.gitignore vendored
View File

@ -24,3 +24,5 @@ go.work
# .env file
.env
cctv/
compose.yml

View File

@ -1,34 +1,17 @@
FROM golang:1.22 as builder
# syntax=docker/dockerfile:1
FROM golang:1.22
WORKDIR /app
# Copy go module files and download dependencies
COPY go.mod go.sum ./
RUN go mod download
COPY go.mod .
RUN go mod tidy && go mod download
# Copy the rest of the application
COPY . .
# Build the Go application
RUN go build -o main ./...
RUN go build -o /cctv ./cmd
# Stage 2: Create a minimal production image
FROM alpine:latest
WORKDIR /app
# Copy the built application from the builder stage
COPY --from=builder /app/main .
# Copy the .env file (if exists)
COPY .env .env
# Expose the necessary port (change as needed)
EXPOSE 8080
# Run the application
CMD ["./main"]
# Healthcheck to ensure the app is running
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
CMD [ "/cctv" ]

View File

@ -251,6 +251,7 @@ func AuthMiddleware(next http.HandlerFunc) http.HandlerFunc {
mu.Unlock()
authHeader := r.Header.Get("Authorization")
fmt.Println(authHeader,"-", os.Getenv("CCTV_BearerToken"))
if !strings.HasPrefix(authHeader, "Bearer ") || strings.TrimPrefix(authHeader, "Bearer ") != os.Getenv("CCTV_BearerToken") {
LogFailedAttempt(ip)