Skip to content

Commit

Permalink
add docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusstefan committed Oct 21, 2024
1 parent 46e1d0f commit 64c905d
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3.9-slim-buster
LABEL maintainer="Darius Stefan <[email protected]>"

RUN apt-get -y update -qq && \
apt-get -y install git

RUN git clone https://github.com/OpenSIPS/python-opensips.git /usr/src/python-opensips && \
cd /usr/src/python-opensips && \
python3 setup.py install &&\
cd / && rm -rf /usr/src/python-opensips

RUN apt-get purge -y git && \
apt-get autoremove -y && \
apt-get clean

ADD "run.sh" "/run.sh"

ENV PYTHONPATH=/usr/lib/python3/dist-packages

ENTRYPOINT [ "/run.sh" ]
10 changes: 10 additions & 0 deletions docker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
NAME ?= pyhton-opensips
OPENSIPS_DOCKER_TAG ?= latest

all: build

.PHONY: build
build:
docker build \
--tag="opensips/pyhton-opensips:$(OPENSIPS_DOCKER_TAG)" \
.
47 changes: 47 additions & 0 deletions docker/docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# OpenSIPS Python Docker Image

Docker recipe for running a container with pre-installed OpenSIPS Python packages.

## Building the image
You can build the docker image by running:
```
make build
```

This command will build a docker image with OpenSIPS Python packages installed, along with
`opensips-mi` and `opensips-event` command line tools.

## Parameters

The container receives parameters in the following format:
```
CMD [PARAMS]*
```

Meaning of the parameters is as it follows:
* `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-mi` command
* `PARAMS` - optional additional parameters passed to `CMD`

## Run

To run a bash script, simply pass the connector followed by the bash script:
```
docker run --rm opensips/python-opensips:latest script.sh
```

Similarly, run a python script:
```
docker run --rm opensips/python-opensips:latest script.py
```

To run a single MI command, use:
```
docker run --rm opensips/python-opensips:latest -t datagram uptime
```

## DockerHub

Docker images are available on
[DockerHub](https://hub.docker.com/r/opensips/python-opensips).
14 changes: 14 additions & 0 deletions docker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

CMD=$1
shift

if [[ CMD == *.py ]]; then
TOOL=python3
elif [[ CMD == *.sh ]]; then
TOOL=bash
else
TOOL=opensips-mi
fi

exec $TOOL $CMD "$@"

0 comments on commit 64c905d

Please sign in to comment.