diff --git a/.gitignore b/.gitignore index 09d3f74..004de41 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ go.work # .env file .env +cctv/ +compose.yml diff --git a/Dockerfile b/Dockerfile index ab7ca58..10647df 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" ] diff --git a/internal/server.go b/internal/server.go index 3191d70..b71bca5 100644 --- a/internal/server.go +++ b/internal/server.go @@ -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)