Skip to content

Commit

Permalink
Merge branch 'healthcheck' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
slotheth committed Jul 19, 2024
2 parents 187c59f + 985057e commit a992291
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM golang:1.21.6-alpine AS builder
WORKDIR /app/src

# Copy the Go module files first and download dependencies
COPY go.mod go.sum ./
COPY ./src/go.mod ./src/go.sum ./
RUN go mod download

# Copy the rest of the application code
Expand All @@ -18,12 +18,12 @@ FROM alpine:3.20.0
RUN apk --no-cache add ca-certificates

# Copy the built binary and configuration files from the builder stage
COPY --from=builder /app/proposal_monitor .
COPY --from=builder /app/config/config.yml ./config/config.yml
COPY --from=builder /app/src/proposal_monitor .
COPY --from=builder /app/src/config/config.yml ./src/config/config.yml

# Defind healthcheck
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD curl -f http://localhost/health || exit 1
CMD curl -f http://localhost:8080/health || exit 1

EXPOSE 8080

Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ services:
networks:
- backend
ports:
- "3000:3000"
- "3000:8080"
volumes:
- ./config:/app/config
- ./src/config:/app/src/config
environment:
- CONFIG_FILE=config/config.yml
- CONFIG_FILE=src/config/config.yml
restart: unless-stopped

networks:
Expand Down
8 changes: 7 additions & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (

func init() {
flag.BoolVar(&useMock, "mock", false, "Use mock data for testing")
configFile := flag.String("config", getEnv("CONFIG_FILE", "config/config.yml"), "Path to configuration file")
configFile := flag.String("config", getEnv("CONFIG_FILE", "src/config/config.yml"), "Path to configuration file")
flag.Parse()

log.Println("Starting Proposal Monitor Service...")
Expand Down Expand Up @@ -70,8 +70,14 @@ func triggerMonitor(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Monitor triggered successfully"))
}

func healthcheck(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
}

func main() {
http.HandleFunc("/trigger-monitor", triggerMonitor)
http.HandleFunc("/health", healthcheck)
log.Println("Server started on port 8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}

0 comments on commit a992291

Please sign in to comment.