From 53446d359e616bc383852da10bc8ded4dd672e5e Mon Sep 17 00:00:00 2001 From: maaikelimper Date: Tue, 19 Sep 2023 07:34:58 +0000 Subject: [PATCH] add healthcheck and new vite env variables --- .github/workflows/basic_test.yml | 2 +- test/docker-compose.yml | 4 ++-- webapp/Dockerfile | 6 ++++++ webapp/docker-entrypoint.sh | 35 ++++++++++++++++++++++++++++---- webapp/healthcheck.sh | 9 ++++++++ 5 files changed, 49 insertions(+), 7 deletions(-) create mode 100755 webapp/healthcheck.sh diff --git a/.github/workflows/basic_test.yml b/.github/workflows/basic_test.yml index c279282..fc43dd7 100644 --- a/.github/workflows/basic_test.yml +++ b/.github/workflows/basic_test.yml @@ -14,7 +14,7 @@ jobs: run: docker build -t wis2box-webapp ./webapp/ - name: Start Docker Compose services - run: docker-compose -f test/docker-compose.yml up -d + run: docker-compose -f test/docker-compose.yml up -d --build - name: Wait for service to start run: sleep 45 diff --git a/test/docker-compose.yml b/test/docker-compose.yml index 93917cc..47c716d 100644 --- a/test/docker-compose.yml +++ b/test/docker-compose.yml @@ -4,9 +4,9 @@ version: '3.3' services: wis2box-webapp-test: container_name: wis2box-webapp-test - image: wis2box-webapp:latest + build: ../webapp environment: - - WIS2BOX_API_URL=http://localhost/oapi + - WIS2BOX_URL=http://localhost - VITE_TEST_MODE=true ports: - 8080:4173 # port mapping for webapp diff --git a/webapp/Dockerfile b/webapp/Dockerfile index 1a7c553..c4a5e98 100644 --- a/webapp/Dockerfile +++ b/webapp/Dockerfile @@ -21,5 +21,11 @@ EXPOSE 4173 # Copy the entrypoint script into /app and make it executable RUN chmod +x /wis2box-webapp/docker-entrypoint.sh +COPY healthcheck.sh /wis2box-webapp/healthcheck.sh + +RUN chmod +x /wis2box-webapp/healthcheck.sh + +HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD /wis2box-webapp/healthcheck.sh + # Set the entrypoint ENTRYPOINT ["sh", "/wis2box-webapp/docker-entrypoint.sh"] \ No newline at end of file diff --git a/webapp/docker-entrypoint.sh b/webapp/docker-entrypoint.sh index 5a75822..df0d567 100755 --- a/webapp/docker-entrypoint.sh +++ b/webapp/docker-entrypoint.sh @@ -1,9 +1,36 @@ #!/bin/bash -# Set VITE_API_URL to the value of WIS2BOX_API_URL -echo "set VITE_API_URL to the value of WIS2BOX_API_URL in .env" -echo "VITE_API_URL=$WIS2BOX_API_URL" -export VITE_API_URL=$WIS2BOX_API_URL +# check WIS2BOX_URL is set +if [ -z "$WIS2BOX_URL" ]; then + echo "WIS2BOX_URL is not set" + exit 1 +fi + +# Set VITE_URL to the value of WIS2BOX_URL/oapi +echo "VITE_API_URL=$WIS2BOX_URL/oapi" +export VITE_API_URL=$WIS2BOX_URL/oapi + +# Set VITE_BASE_URL to the value of WIS2BOX_URL/wis2box-webapp +echo "VITE_BASE_URL=$WIS2BOX_URL/wis2box-webapp" +export VITE_BASE_URL=$WIS2BOX_URL/wis2box-webapp + +# Set VITE_BASEMAP_URL to WIS2BOX_BASEMAP_URL if it is set +if [ -z "$WIS2BOX_BASEMAP_URL" ]; then + echo "WIS2BOX_BASEMAP_URL is not set use default basemap" + VITE_BASEMAP_URL="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" +else + export VITE_BASEMAP_URL=$WIS2BOX_BASEMAP_URL +fi +echo "VITE_BASEMAP_URL=$VITE_BASEMAP_URL" + +# repeat for VITE_BASEMAP_ATTRIBUTION +if [ -z "$WIS2BOX_BASEMAP_ATTRIBUTION" ]; then + echo "WIS2BOX_BASEMAP_ATTRIBUTION is not set use default basemap attribution" + VITE_BASEMAP_ATTRIBUTION="OpenStreetMap contributors" +else + export VITE_BASEMAP_ATTRIBUTION=$WIS2BOX_BASEMAP_ATTRIBUTION +fi +echo "VITE_BASEMAP_ATTRIBUTION=$VITE_BASEMAP_ATTRIBUTION" npm run build npm run preview \ No newline at end of file diff --git a/webapp/healthcheck.sh b/webapp/healthcheck.sh new file mode 100755 index 0000000..4797d04 --- /dev/null +++ b/webapp/healthcheck.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# Custom health check script + +# Check if npm run preview is running +if ps aux | grep 'npm run preview' | grep -v grep; then + exit 0 # Process found, container is healthy +else + exit 1 # Process not found, container is not healthy +fi \ No newline at end of file