Skip to content

Commit

Permalink
chore: configure healthchecks in all services
Browse files Browse the repository at this point in the history
  • Loading branch information
tonitienda committed May 2, 2024
1 parent ed49ccf commit b48cef8
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 3 deletions.
3 changes: 3 additions & 0 deletions backend-rest-go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ COPY --from=builder /app/server .

EXPOSE 8080


HEALTHCHECK --interval=10s --timeout=1s --retries=3 CMD wget --tries=1 --spider http://localhost:8080/healthz || exit 1

CMD ["./server"]
3 changes: 3 additions & 0 deletions backend-rest-js/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ FROM node:18-alpine as production
WORKDIR /app
COPY --from=build /app/dist/ ./dist/


HEALTHCHECK --interval=10s --timeout=1s --retries=3 CMD wget --tries=1 --spider http://localhost:8080/healthz || exit 1

CMD ["node", "dist/index.js"]
4 changes: 4 additions & 0 deletions backend-rest-js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ app.use((req, res, next) => {
next();
});

app.get("/healthz", (req, res) => {
res.json(`{"message": "OK"}`);
});

app.use("/v0", v0);
v0.use("/tasks", tasks);

Expand Down
3 changes: 2 additions & 1 deletion compose.e2e-cypress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ services:
dockerfile: Dockerfile
context: e2e-cypress
depends_on:
- webapp
webapp:
condition: service_healthy
volumes:
- ./e2e-cypress/cypress/screenshots:/app/cypress/screenshots
- .env:/app/.env
Expand Down
3 changes: 2 additions & 1 deletion compose.frontend-htmx-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ services:
context: ./webapp-htmx-go
dockerfile: Dockerfile
depends_on:
- backend
backend:
condition: service_healthy
env_file:
- .env
environment:
Expand Down
4 changes: 3 additions & 1 deletion compose.frontend-nextjs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ services:
dockerfile: Dockerfile
context: ./webapp-nextjs
depends_on:
- backend
backend:
condition: service_healthy
volumes:
- .env:/app/.env.local



3 changes: 3 additions & 0 deletions webapp-htmx-go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ COPY --from=builder /app/templates ./templates

EXPOSE 8080


HEALTHCHECK --interval=10s --timeout=1s --retries=3 CMD wget --tries=1 --spider http://localhost:8080/healthz || exit 1

CMD ["./server"]
6 changes: 6 additions & 0 deletions webapp-htmx-go/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ func main() {
return
}

http.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) {
fmt.Println("GET /healthz")

w.Write([]byte(`{"message":"OK" }`))
})

http.HandleFunc("GET /login", func(w http.ResponseWriter, r *http.Request) {

state, err := generateRandomState()
Expand Down
2 changes: 2 additions & 0 deletions webapp-nextjs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ COPY --from=build /app/.next ./.next

EXPOSE 3000

HEALTHCHECK --interval=10s --timeout=1s --retries=3 CMD wget --tries=1 --spider http://localhost:3000 || exit 1

CMD ["npm", "start"]

0 comments on commit b48cef8

Please sign in to comment.