diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b09cd934d973ad4c225f670fa05a4c9060f853a4..aa6e065a7b8c3c657595382e51a3fcaffcc79605 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -39,7 +39,7 @@ variables: # TODO should/could we roll back the service to the last working revision on test failure? cache_lint: - image: 'europe-north1-docker.pkg.dev/holi-shared/docker-hub-remote/denoland/deno:2.1.9' + image: 'europe-north1-docker.pkg.dev/holi-shared/docker-hub-remote/denoland/deno:2.1.10' stage: 'test' script: - deno cache --allow-import --lock=deno.lock app/deps.ts app/dev_deps.ts diff --git a/Dockerfile b/Dockerfile index 6e98cbb1f2fcf450c49d2c1e34fdf0285437d7a0..ce4671ebb20b1ac4956798caf14a2425d68f4349 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM europe-north1-docker.pkg.dev/holi-shared/docker-hub-remote/denoland/deno:2.1.9 +FROM europe-north1-docker.pkg.dev/holi-shared/docker-hub-remote/denoland/deno:2.1.10 # The port that your application listens to. EXPOSE 8089 diff --git a/app/server.ts b/app/server.ts index a5855166cb8cdb6f1c077429603da88e6b65d5bb..aff8996caf0b53d54b9fc4e696414c995db1b046 100644 --- a/app/server.ts +++ b/app/server.ts @@ -81,7 +81,18 @@ export type GraphQLServer = any export const startServer = (config: ServerConfig): Promise<void> => { const graphQLServer: GraphQLServer = createGraphQLServer(config) - return serve(graphQLServer, { + + const handler = (request: Request): Response => { + const url = new URL(request.url) + + if (url.pathname === '/health') { + return new Response('OK', { status: 200 }) + } + + return graphQLServer.handleRequest(request) + } + + return serve(handler, { port: config.port, onListen({ port, hostname }) { logger.info( diff --git a/terraform/environments/deployment.tf b/terraform/environments/deployment.tf index 1958869a929b9fa1bfa842e449aef2fb114423bc..905316e7283805202e206563af129a2a680bf271 100644 --- a/terraform/environments/deployment.tf +++ b/terraform/environments/deployment.tf @@ -78,6 +78,24 @@ resource "google_cloud_run_v2_service" "translation_api_service" { cpu_idle = true startup_cpu_boost = true } + startup_probe { + http_get { + path = "/health" + } + initial_delay_seconds = 5 + failure_threshold = 3 + period_seconds = 5 + timeout_seconds = 2 + } + liveness_probe { + http_get { + path = "/health" + } + initial_delay_seconds = 10 + period_seconds = 30 + timeout_seconds = 2 + failure_threshold = 3 + } } scaling { @@ -106,8 +124,12 @@ resource "google_cloud_run_v2_service" "translation_api_service" { traffic { percent = 100 type = "TRAFFIC_TARGET_ALLOCATION_TYPE_LATEST" + + } + + depends_on = [google_project_service.service] }