diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 56b91c750e..3ebf0b2036 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -17,8 +17,6 @@ jobs: permissions: id-token: write # needed for signing the images with GitHub OIDC Token packages: write # needed for publishing packages to GHCR - env: - TEST_TAG: vectorim/element-web:test steps: - uses: actions/checkout@v4 with: @@ -52,26 +50,41 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Build and load + id: test-build uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991 # v6 with: context: . load: true - tags: ${{ env.TEST_TAG }} - name: Test the image + env: + IMAGEID: ${{ steps.test-build.outputs.imageid }} run: | + set -x + # Make a fake module to test the image MODULE_PATH="modules/module_name/index.js" mkdir -p $(dirname $MODULE_PATH) echo 'alert("Testing");' > $MODULE_PATH # Spin up a container of the image - CONTAINER_ID=$(docker run --rm -dp 80:80 -v $(pwd)/modules:/tmp/element-web-modules ${{ env.TEST_TAG }}) + ELEMENT_WEB_PORT=8181 + CONTAINER_ID=$( + docker run \ + --rm \ + -e "ELEMENT_WEB_PORT=$ELEMENT_WEB_PORT" \ + -dp "$ELEMENT_WEB_PORT:$ELEMENT_WEB_PORT" \ + -v $(pwd)/modules:/tmp/element-web-modules \ + "$IMAGEID" \ + ) # Run some smoke tests - wget --retry-connrefused --tries=5 -q --wait=3 --spider http://localhost:80/modules/module_name/index.js - MODULE_1=$(curl http://localhost:80/config.json | jq -r .modules[0]) - test "$MODULE_1" = "/${MODULE_PATH}" + wget --retry-connrefused --tries=5 -q --wait=3 --spider "http://localhost:$ELEMENT_WEB_PORT/modules/module_name/index.js" + MODULE_0=$(curl "http://localhost:$ELEMENT_WEB_PORT/config.json" | jq -r .modules[0]) + test "$MODULE_0" = "/${MODULE_PATH}" + + # Check healthcheck + test "$(docker inspect -f {{.State.Running}} $CONTAINER_ID)" == "true" # Clean up docker stop "$CONTAINER_ID" diff --git a/Dockerfile b/Dockerfile index dd8be21932..1103d7336f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,3 +46,5 @@ USER nginx # HTTP listen port ENV ELEMENT_WEB_PORT=80 + +HEALTHCHECK --start-period=5s CMD wget --retry-connrefused --tries=5 -q --wait=3 --spider http://localhost:$ELEMENT_WEB_PORT/config.json