Skip to content

Commit 9f86c6f

Browse files
dariusstefanNFhookrazvancrainea
authored
Add OpenSIPS-CLI based healthcheck (#24)
* add healthcheck * Update Dockerfile * github: add docker push readme action * docker-publish: bump login-action to v3 * Add build in opensips-publish * quote extra modules * add support for using a particular apt component This provides a more flexible component, rather than hardcoded version+build * github: fix opensips modules quoting * github: change quotes * Make healthcheck to depend on CLI arg --------- Co-authored-by: NFhook <telegant@qq.com> Co-authored-by: Răzvan Crainea <razvan@opensips.org>
1 parent 5b00259 commit 9f86c6f

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

Dockerfile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM debian:bullseye
1+
FROM debian:bullseye AS base
22
LABEL maintainer="Razvan Crainea <razvan@opensips.org>"
33

44
USER root
@@ -27,6 +27,8 @@ RUN apt-get -y update -qq && \
2727
opensips${OPENSIPS_VERSION_MINOR:+=$OPENSIPS_VERSION.$OPENSIPS_VERSION_MINOR-$OPENSIPS_VERSION_REVISION}
2828

2929
ARG OPENSIPS_CLI=false
30+
ENV OPENSIPS_CLI_ENV=${OPENSIPS_CLI}
31+
3032
RUN if [ ${OPENSIPS_CLI} = true ]; then \
3133
echo "deb https://apt.opensips.org bullseye cli-nightly" >/etc/apt/sources.list.d/opensips-cli.list \
3234
&& apt-get -y update -qq && apt-get -y install opensips-cli \
@@ -42,5 +44,16 @@ RUN sed -i "s/stderror_enabled=no/stderror_enabled=yes/g" /etc/opensips/opensips
4244
sed -i "s/syslog_enabled=yes/syslog_enabled=no/g" /etc/opensips/opensips.cfg
4345

4446
EXPOSE 5060/udp
45-
47+
HEALTHCHECK --interval=15s --timeout=5s \
48+
CMD opensips-cli -x mi uptime|grep -q "Up time" || exit 1
4649
ENTRYPOINT ["/usr/sbin/opensips", "-F"]
50+
51+
FROM base AS no-healthcheck
52+
HEALTHCHECK NONE
53+
54+
FROM base AS with-healthcheck
55+
HEALTHCHECK --interval=15s --timeout=5s \
56+
CMD if [ "$OPENSIPS_CLI_ENV" != "true" ]; then \
57+
exit 0; \
58+
fi; \
59+
opensips-cli -x mi uptime | grep -q "Up Time" || exit 1

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,25 @@ OPENSIPS_BUILD ?= releases
66
OPENSIPS_COMPONENT ?=
77
OPENSIPS_DOCKER_TAG ?= latest
88
OPENSIPS_CLI ?= true
9+
WITH_HEALTHCHECK ?= true
910
OPENSIPS_EXTRA_MODULES ?=
1011
DOCKER_ARGS ?=
1112

13+
DOCKER_TARGET = no-healthcheck
14+
15+
ifeq ($(OPENSIPS_CLI),true)
16+
ifeq ($(WITH_HEALTHCHECK),true)
17+
DOCKER_TARGET = with-healthcheck
18+
endif
19+
endif
20+
1221
all: build start
1322

1423
.PHONY: build start
1524
build:
1625
docker build \
1726
--no-cache \
27+
--target=$(DOCKER_TARGET) \
1828
--build-arg=OPENSIPS_BUILD=$(OPENSIPS_BUILD) \
1929
--build-arg=OPENSIPS_VERSION=$(OPENSIPS_VERSION) \
2030
--build-arg=OPENSIPS_VERSION_MINOR=$(OPENSIPS_VERSION_MINOR) \

0 commit comments

Comments
 (0)