Skip to content

Commit e05b12d

Browse files
committed
add healthcheck for container composition
1 parent f0c9dc7 commit e05b12d

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

compose.yaml

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,39 @@ services:
1818
- data-uploads:/linuxfr.org/uploads
1919
tmpfs:
2020
- /linuxfr.org/public/tmp:size=100M
21+
healthcheck:
22+
test: curl --fail http://localhost:3000
2123
depends_on:
22-
- database
23-
- redis
24+
database:
25+
condition: service_completed_successfully
26+
restart: true
27+
redis:
28+
condition: service_completed_successfully
29+
restart: true
2430

2531
linuxfr-board:
2632
build:
2733
context: deployment/linuxfr-board
2834
env_file:
2935
- deployment/default.env
36+
healthcheck:
37+
test: curl --fail -I http://localhost:9000
3038
depends_on:
31-
- redis
39+
redis:
40+
condition: service_completed_successfully
41+
restart: true
3242

3343
linuxfr-img:
3444
build:
3545
context: deployment/linuxfr-img
3646
env_file:
3747
- deployment/default.env
48+
healthcheck:
49+
test: curl --fail http://localhost:8000/status
3850
depends_on:
39-
- redis
51+
redis:
52+
condition: service_completed_successfully
53+
restart: true
4054
volumes:
4155
- cache-img:/linuxfr-img/cache
4256

@@ -53,9 +67,15 @@ services:
5367
published: 127.0.0.1:80
5468
protocol: tcp
5569
depends_on:
56-
- linuxfr.org
57-
- linuxfr-board
58-
- linuxfr-img
70+
linuxfr.org:
71+
condition: service_completed_successfully
72+
restart: true
73+
linuxfr-board:
74+
condition: service_completed_successfully
75+
restart: true
76+
linuxfr-img:
77+
condition: service_completed_successfully
78+
restart: true
5979

6080
database:
6181
build:
@@ -66,11 +86,15 @@ services:
6686
- target: 3306
6787
published: 127.0.0.1:3306
6888
protocol: tcp
89+
healthcheck:
90+
test: mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD
6991
volumes:
7092
- data-database:/var/lib/mysql
7193

7294
redis:
7395
image: docker.io/redis:5
96+
healthcheck:
97+
test: redis-cli --raw incr ping
7498
volumes:
7599
- data-redis:/data
76100

deployment/linuxfr-board/Containerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ RUN \
1616
IFS=$'\n\t'; \
1717
apt-get update; \
1818
# Install dependencies \
19+
# and add curl to be used by the healthcheck defined in compose.yaml \
1920
apt-get install -y --no-install-recommends \
20-
build-essential git ruby ruby-dev; \
21+
build-essential git ruby ruby-dev \
22+
curl; \
2123
apt-get clean;
2224

2325
USER ${UID}

deployment/linuxfr-img/Containerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ FROM docker.io/debian:bullseye-slim as deploy
3131
USER ${UID}
3232
WORKDIR /linuxfr-img
3333

34+
# Install curl to be used by the healthcheck defined in compose.yaml
35+
RUN \
36+
set -eux; \
37+
IFS=$'\n\t'; \
38+
apt-get update; \
39+
apt-get install -y --no-install-recommends \
40+
curl; \
41+
apt-get clean;
42+
3443
COPY --from=build --chown=${UID}:0 --chmod=770 /linuxfr-img/bin/img-LinuxFr.org .
3544

3645
EXPOSE 8000

0 commit comments

Comments
 (0)