structurizr / lite

Structurizr Lite
https://docs.structurizr.com/lite
MIT License
226 stars 26 forks source link

Support for container health check #131

Closed rvplauborg closed 4 months ago

rvplauborg commented 4 months ago

Description

We are running a GitHub workflow, and are using GitHub Action service container for spinning up Structurizr Lite and then exporting diagrams as PNG with Puppeteer. But unfortunately exporting the diagrams fails on waiting for some Structurizr functions to be ready in the DOM.

We have digged a bit and found that it is likely to happen because the service container is not really ready. So it would be brilliant if the Structurizr Lite docker image had a health command, so we can add health-check for the service-container. For Postgres for example, one can add below options for the service container, so it waits until Postgres is ready before marking container as healthy:

        options:
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

Example GitHub job where the last step node export-diagrams.js 'http://localhost:8080/workspace/diagrams' png fails.

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      OUTPUT_STRUCTURE: docs/diagrams/c4-model/views/
    services:
      structurizr-lite:
        image: structurizr/lite:latest
        ports:
          - 8080:8080
        volumes:
          - ${{ github.workspace }}:/usr/local/structurizr
        env:
          STRUCTURIZR_WORKSPACE_PATH: /docs/diagrams/c4-model
          STRUCTURIZR_WORKSPACE_FILENAME: views

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup node
        uses: actions/setup-node@v4

      - name: Prepare export-diagrams script
        shell: bash
        run: |
          npm i puppeteer
          curl https://raw.githubusercontent.com/structurizr/puppeteer/master/export-diagrams.js --output export-diagrams.js
      - name: Render diagrams png images
        run: |
          set -e

          echo '::group::Rendering...'
          node export-diagrams.js 'http://localhost:8080/workspace/diagrams' png
          echo '::endgroup::'

          output=$(mktemp -d)
          chmod +rx "$output"
          echo "output=$output" >> $GITHUB_ENV

          rm *-key.png || true
          mkdir -p $output/${{ env.OUTPUT_STRUCTURE }}
          mv *.png $output/${{ env.OUTPUT_STRUCTURE }}/

Priority

I have no budget and there's no rush, please add this feature for free

More information

No response

simonbrowndotje commented 4 months ago

I've added a /health endpoint that returns OK (and HTTP 200), which you should be able to use in conjunction with curl for your health check (e.g. https://stackoverflow.com/a/75520196).