Skip to content

Commit 2e883b4

Browse files
authored
Add docker healthcheck (#29351)
* Add docker healthcheck and test ELEMENT_WEB_PORT envvar Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> --------- Signed-off-by: Michael Telatynski <[email protected]>
1 parent 14e3a77 commit 2e883b4

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

.github/workflows/docker.yaml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ jobs:
1717
permissions:
1818
id-token: write # needed for signing the images with GitHub OIDC Token
1919
packages: write # needed for publishing packages to GHCR
20-
env:
21-
TEST_TAG: vectorim/element-web:test
2220
steps:
2321
- uses: actions/checkout@v4
2422
with:
@@ -52,26 +50,41 @@ jobs:
5250
password: ${{ secrets.GITHUB_TOKEN }}
5351

5452
- name: Build and load
53+
id: test-build
5554
uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991 # v6
5655
with:
5756
context: .
5857
load: true
59-
tags: ${{ env.TEST_TAG }}
6058

6159
- name: Test the image
60+
env:
61+
IMAGEID: ${{ steps.test-build.outputs.imageid }}
6262
run: |
63+
set -x
64+
6365
# Make a fake module to test the image
6466
MODULE_PATH="modules/module_name/index.js"
6567
mkdir -p $(dirname $MODULE_PATH)
6668
echo 'alert("Testing");' > $MODULE_PATH
6769
6870
# Spin up a container of the image
69-
CONTAINER_ID=$(docker run --rm -dp 80:80 -v $(pwd)/modules:/tmp/element-web-modules ${{ env.TEST_TAG }})
71+
ELEMENT_WEB_PORT=8181
72+
CONTAINER_ID=$(
73+
docker run \
74+
--rm \
75+
-e "ELEMENT_WEB_PORT=$ELEMENT_WEB_PORT" \
76+
-dp "$ELEMENT_WEB_PORT:$ELEMENT_WEB_PORT" \
77+
-v $(pwd)/modules:/tmp/element-web-modules \
78+
"$IMAGEID" \
79+
)
7080
7181
# Run some smoke tests
72-
wget --retry-connrefused --tries=5 -q --wait=3 --spider http://localhost:80/modules/module_name/index.js
73-
MODULE_1=$(curl http://localhost:80/config.json | jq -r .modules[0])
74-
test "$MODULE_1" = "/${MODULE_PATH}"
82+
wget --retry-connrefused --tries=5 -q --wait=3 --spider "http://localhost:$ELEMENT_WEB_PORT/modules/module_name/index.js"
83+
MODULE_0=$(curl "http://localhost:$ELEMENT_WEB_PORT/config.json" | jq -r .modules[0])
84+
test "$MODULE_0" = "/${MODULE_PATH}"
85+
86+
# Check healthcheck
87+
test "$(docker inspect -f {{.State.Running}} $CONTAINER_ID)" == "true"
7588
7689
# Clean up
7790
docker stop "$CONTAINER_ID"

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ USER nginx
4646

4747
# HTTP listen port
4848
ENV ELEMENT_WEB_PORT=80
49+
50+
HEALTHCHECK --start-period=5s CMD wget --retry-connrefused --tries=5 -q --wait=3 --spider http://localhost:$ELEMENT_WEB_PORT/config.json

0 commit comments

Comments
 (0)