From e61c5389952164a7b091cfdd7c973e410f29ff0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Wo=C5=BAniak?= <17177420+wozniakpl@users.noreply.github.com> Date: Wed, 3 Jul 2024 14:22:20 +0200 Subject: [PATCH] support cross platform build, compose healthchecks --- backend/Dockerfile | 12 ++--- .../{docker-entrypoint.sh => entrypoint.sh} | 0 docker-compose.yml => compose.yml | 54 +++++++++++++------ frontend/Dockerfile | 2 + 4 files changed, 47 insertions(+), 21 deletions(-) rename backend/{docker-entrypoint.sh => entrypoint.sh} (100%) rename docker-compose.yml => compose.yml (65%) diff --git a/backend/Dockerfile b/backend/Dockerfile index fef0788b..6273eaef 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -3,13 +3,13 @@ ARG BASE_IMAGE=python:3.12.1-alpine3.19 ########################################################### # Tools stage ########################################################### -FROM --platform=linux/amd64 ${BASE_IMAGE} AS tools +FROM ${BASE_IMAGE} AS tools # Install curl -RUN apk add --no-cache curl +RUN apk add --no-cache curl musl-dev libffi-dev gcc # Download waitforit -RUN curl -o /usr/local/bin/waitforit -sSL https://github.com/maxcnunes/waitforit/releases/download/v2.4.1/waitforit-linux_amd64 && \ +RUN curl -o /usr/local/bin/waitforit -sSL https://github.com/maxcnunes/waitforit/releases/download/v2.4.1/waitforit-linux_${TARGETARCH} && \ chmod +x /usr/local/bin/waitforit # Download poetry @@ -21,7 +21,7 @@ RUN curl -sSL https://install.python-poetry.org | python ########################################################### # Base stage ########################################################### -FROM --platform=linux/amd64 ${BASE_IMAGE} AS base +FROM ${BASE_IMAGE} AS base # Install runtime dependencies RUN apk add --no-cache bash libpq @@ -36,8 +36,8 @@ COPY --from=tools /usr/local/bin/waitforit /usr/local/bin/waitforit WORKDIR /src # Copy and set entrypoint script -COPY --chmod=755 docker-entrypoint.sh /usr/local/bin/ -ENTRYPOINT ["docker-entrypoint.sh"] +COPY --chmod=755 entrypoint.sh /usr/local/bin/ +ENTRYPOINT ["entrypoint.sh"] ########################################################### diff --git a/backend/docker-entrypoint.sh b/backend/entrypoint.sh similarity index 100% rename from backend/docker-entrypoint.sh rename to backend/entrypoint.sh diff --git a/docker-compose.yml b/compose.yml similarity index 65% rename from docker-compose.yml rename to compose.yml index bae942da..4d3a2352 100644 --- a/docker-compose.yml +++ b/compose.yml @@ -1,23 +1,32 @@ -version: '3.9' - volumes: - postgres_data: - fusionauth_config: + postgres-data: + fusionauth-config: services: proxy: - image: tivix/docker-nginx:v17 + image: tivix/docker-nginx:v18 restart: unless-stopped depends_on: - - frontend - - fusionauth - - api-server + frontend: + condition: service_healthy + fusionauth: + condition: service_healthy + api-server: + condition: service_healthy ports: - "8080:80" environment: - UPSTREAMS=/api:fusionauth:9011,/cpf/api:api-server:8000,/:frontend:3000 - WEBSOCKETS=true - + - HEALTHCHECK=/health + - HEALTHCHECK_PORT=8888 + - HEALTHCHECK_LISTEN=0.0.0.0 + healthcheck: + test: wget -q -O /dev/null http://proxy:8888/health + interval: 5s + timeout: 5s + retries: 5 + frontend: restart: unless-stopped stdin_open: true @@ -28,9 +37,14 @@ services: - ./frontend/src:/code/src - ./frontend/public:/code/public ports: - - '3000:3000' + - "3000:3000" env_file: - .env + healthcheck: # TODO: /health once available + test: wget -q -O /dev/null http://frontend:3000/auth + interval: 5s + timeout: 5s + retries: 5 api-server: image: cpf/backend-image @@ -47,8 +61,18 @@ services: - ./backend/src:/src stdin_open: true tty: true + depends_on: + data-loader: + condition: service_completed_successfully + fusionauth: + condition: service_healthy + healthcheck: + test: wget -q -O /dev/null http://api-server:8000/cpf/api/health + interval: 5s + timeout: 5s + retries: 5 - data_loader: + data-loader: image: cpf/backend-image restart: "no" build: @@ -72,14 +96,14 @@ services: env_file: - .env healthcheck: - test: [ "CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d postgres" ] + test: pg_isready -U ${POSTGRES_USER} -d postgres interval: 5s timeout: 5s retries: 5 ports: - "5432:5432" volumes: - - postgres_data:/var/lib/postgresql/data/ + - postgres-data:/var/lib/postgresql/data/ fusionauth: image: fusionauth/fusionauth-app:1.48.3 @@ -103,10 +127,10 @@ services: postgres: condition: service_healthy healthcheck: - test: curl --silent --fail http://localhost:9011/api/status -o /dev/null -w "%{http_code}" + test: curl --silent --fail http://fusionauth:9011/api/status -o /dev/null -w "%{http_code}" interval: 5s timeout: 5s retries: 5 volumes: - - fusionauth_config:/usr/local/fusionauth/config + - fusionauth-config:/usr/local/fusionauth/config - ./fusionauth/kickstart:/usr/local/fusionauth/kickstart diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 3d1d21e1..6259fa07 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -12,6 +12,8 @@ RUN yarn --frozen-lockfile FROM base AS development WORKDIR /code +RUN apt update && apt install -y wget && apt clean && rm -rf /var/lib/apt/lists/* + ENV NODE_ENV development COPY . .