Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .github/workflows/docker-push-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,22 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
- name: Build and push Debian image
uses: docker/build-push-action@v7
with:
context: ./docker/
file: ./docker/Dockerfile
push: true
tags: |
opensips/opensips-cli:latest
ghcr.io/opensips/opensips-cli:latest

- name: Build and push Alpine image
uses: docker/build-push-action@v7
with:
context: ./docker/
file: ./docker/Dockerfile.alpine
push: true
tags: |
opensips/opensips-cli:alpine
ghcr.io/opensips/opensips-cli:alpine
31 changes: 12 additions & 19 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
FROM python:slim-trixie
LABEL maintainer="Razvan Crainea <razvan@opensips.org>"

USER root
ARG BASE_IMAGE=python:slim-trixie

# Set Environment Variables
ENV DEBIAN_FRONTEND noninteractive
FROM ${BASE_IMAGE} AS builder

#install basic components
RUN apt-get -y update -qq && \
apt-get -y install git
apt-get -y --no-install-recommends install git && \
git clone https://github.com/OpenSIPS/opensips-cli.git /usr/src/opensips-cli && \
python3 -m pip install --no-cache-dir /usr/src/opensips-cli

#add keyserver, repository
RUN git clone https://github.com/OpenSIPS/opensips-cli.git /usr/src/opensips-cli && \
cd /usr/src/opensips-cli && \
python3 -m pip install . && \
cd / && rm -rf /usr/src/opensips-cli
FROM ${BASE_IMAGE}
LABEL maintainer="Razvan Crainea <razvan@opensips.org>"

RUN apt-get purge -y git && \
apt-get autoremove -y && \
apt-get clean
COPY --from=builder /usr/local/lib /usr/local/lib
COPY --from=builder /usr/local/bin/opensips-cli /usr/local/bin/opensips-cli

ADD "run.sh" "/run.sh"
RUN python3 -m compileall -q /usr/local/lib

ENV PYTHONPATH /usr/lib/python3/dist-packages
COPY run.sh /run.sh

ENTRYPOINT ["/run.sh", "-o", "communication_type=http"]
ENTRYPOINT [ "/run.sh", "-o", "communication_type=http" ]
19 changes: 19 additions & 0 deletions docker/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ARG BASE_IMAGE=python:alpine

FROM ${BASE_IMAGE} AS builder

RUN apk add --no-cache git && \
git clone https://github.com/OpenSIPS/opensips-cli.git /usr/src/opensips-cli && \
python3 -m pip install --no-cache-dir /usr/src/opensips-cli

FROM ${BASE_IMAGE}
LABEL maintainer="Razvan Crainea <razvan@opensips.org>"

COPY --from=builder /usr/local/lib /usr/local/lib
COPY --from=builder /usr/local/bin/opensips-cli /usr/local/bin/opensips-cli

RUN python3 -m compileall -q /usr/local/lib

COPY run.sh /run.sh

ENTRYPOINT [ "/run.sh", "-o", "communication_type=http" ]
13 changes: 10 additions & 3 deletions docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ OPENSIPS_DOCKER_TAG ?= latest

all: build start

.PHONY: build start
build:
docker build \
.PHONY: build build-debian build-alpine start
build-debian:
docker build -f Dockerfile \
--tag="opensips/opensips-cli:$(OPENSIPS_DOCKER_TAG)" \
.

build: build-debian

build-alpine:
docker build -f Dockerfile.alpine \
--tag="opensips/opensips-cli:alpine-$(OPENSIPS_DOCKER_TAG)" \
.

start:
docker run -d --name $(NAME) opensips/opensips-cli:$(OPENSIPS_DOCKER_TAG)
27 changes: 20 additions & 7 deletions docker/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ Docker recipe for running [OpenSIPS Command Line
Interface](https://github.com/OpenSIPS/opensips-cli).

## Building the image
You can build the docker image by running:
You can build the Debian-based docker image by running:
```
make build
make build-debian
```

This command will build a docker image with OpenSIPS CLI master version taken from
the git repository
Or the Alpine-based image (smaller footprint) with:
```
make build-alpine
```

`make build` is an alias for `make build-debian`.

All variants install OpenSIPS CLI from the latest master branch on GitHub.

## Parameters

Expand All @@ -25,13 +31,20 @@ Meaning of the parameters is as it follows:
will end up in opensips-cli config file, in the `default` section, as
`KEY: VALUE` lines
* `CMD` - the command used to run; if the `CMD` ends with `.sh` extension, it
will be run as a bash script, if the `CMD` ends with `.py` extension, it is
run as a python script, otherwise it is run as a `opensips-cli` command
will be run as a POSIX shell (`sh`) script, if the `CMD` ends with `.py`
extension, it is run as a python script, otherwise it is run as a
`opensips-cli` command
* `PARAMS` - optional additional parameters passed to `CMD`

## Run

To run a bash script, simply pass the connector followed by the bash script:
The entrypoint script (`run.sh`) is POSIX `sh`-compatible and requires no
additional shell. As a result, the Alpine image ships no extra packages beyond
the base Python Alpine image. Shell scripts passed as `CMD` must also be POSIX
`sh`-compatible, or include their own `#!/bin/bash` shebang with bash installed
separately.

To run a shell script, simply pass the connector followed by the script:
```
docker run -d --name opensips-cli opensips/opensips-cli:latest \
-o url=http://8.8.8.8:8888/mi script.sh
Expand Down
21 changes: 9 additions & 12 deletions docker/run.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#!/bin/bash
#!/bin/sh

OPTS=
CMD=
PARAMS=
CFG=/etc/opensips-cli.cfg

echo "[default]" > "$CFG"

while [[ $# -gt 0 ]]; do
while [ $# -gt 0 ]; do
case "$1" in
-o|--option)
shift
P=$(cut -d'=' -f1 <<<"$1")
V=$(cut -d'=' -f2- <<<"$1")
P=$(echo "$1" | cut -d'=' -f1)
V=$(echo "$1" | cut -d'=' -f2-)
echo "$P: $V" >> "$CFG"
;;
*)
Expand All @@ -26,12 +25,10 @@ while [[ $# -gt 0 ]]; do
shift
done

if [[ $CMD == *.py ]]; then
TOOL=python3
elif [[ $CMD == *.sh ]]; then
TOOL=bash
else
TOOL=opensips-cli
fi
case "$CMD" in
*.py) TOOL=python3 ;;
*.sh) TOOL=sh ;;
*) TOOL=opensips-cli ;;
esac

exec $TOOL $CMD $PARAMS