Compare commits
2 Commits
882548344a
...
bf0bc3ceb8
| Author | SHA1 | Date | |
|---|---|---|---|
| bf0bc3ceb8 | |||
| 9159ae9f2f |
2
.gitignore
vendored
2
.gitignore
vendored
@ -24,3 +24,5 @@ go.work
|
|||||||
# .env file
|
# .env file
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
cctv/
|
||||||
|
compose.yml
|
||||||
|
|||||||
33
Dockerfile
33
Dockerfile
@ -1,34 +1,17 @@
|
|||||||
FROM golang:1.22 as builder
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
|
FROM golang:1.22
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy go module files and download dependencies
|
COPY go.mod .
|
||||||
COPY go.mod go.sum ./
|
|
||||||
RUN go mod download
|
RUN go mod tidy && go mod download
|
||||||
|
|
||||||
# Copy the rest of the application
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build the Go application
|
RUN go build -o /cctv ./cmd
|
||||||
RUN go build -o main ./...
|
|
||||||
|
|
||||||
# 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
|
EXPOSE 8080
|
||||||
|
|
||||||
# Run the application
|
CMD [ "/cctv" ]
|
||||||
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
|
|
||||||
|
|||||||
@ -251,6 +251,7 @@ func AuthMiddleware(next http.HandlerFunc) http.HandlerFunc {
|
|||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
|
|
||||||
authHeader := r.Header.Get("Authorization")
|
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") {
|
if !strings.HasPrefix(authHeader, "Bearer ") || strings.TrimPrefix(authHeader, "Bearer ") != os.Getenv("CCTV_BearerToken") {
|
||||||
LogFailedAttempt(ip)
|
LogFailedAttempt(ip)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user