Skip to content

Commit 3171f51

Browse files
committed
Merge with Dockerfile repo
1 parent 4a0e40f commit 3171f51

File tree

7 files changed

+179
-8
lines changed

7 files changed

+179
-8
lines changed
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
name: Trigger OpenSIPS CLI Images build and publish
1+
name: Push OpenSIPS CLI Images in Docker Hub
22

33
on:
44
push:
55
repository_dispatch:
66
workflow_dispatch:
77

88
jobs:
9-
109
build:
11-
1210
runs-on: ubuntu-latest
1311

1412
steps:
15-
- name: Repository Dispatch
16-
uses: myrotvorets/[email protected]
13+
- uses: actions/checkout@v3
14+
15+
- name: Log in to Docker Hub
16+
uses: docker/[email protected]
17+
with:
18+
username: ${{ secrets.DOCKER_USERNAME }}
19+
password: ${{ secrets.DOCKER_TOKEN }}
20+
21+
- name: Build and push Docker image
22+
uses: docker/build-push-action@v4
1723
with:
18-
token: ${{ secrets.DOCKER_OPENSIPS_CLI_PAT }}
19-
repo: OpenSIPS/docker-opensips-cli
20-
type: OpenSIPS CLI Trigger
24+
context: ./docker/
25+
push: true
26+
tags: opensips/opensips-cli:latest

.github/workflows/docker-readme.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
name: Update Docker Hub Description
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- ./docker/docker.md
9+
- .github/workflows/docker-readme.yml
10+
11+
jobs:
12+
dockerHubDescription:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
18+
- name: Docker Hub Description
19+
uses: peter-evans/dockerhub-description@v4
20+
with:
21+
username: ${{ secrets.DOCKER_USERNAME }}
22+
password: ${{ secrets.DOCKER_TOKEN }}
23+
repository: opensips/opensips-cli
24+
readme-filepath: ./docker/docker.md
25+
short-description: ${{ github.event.repository.description }}
26+
enable-url-completion: true

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ args = OpenSIPSCLIArgs(communcation_type = "http",
8383
...
8484
```
8585

86+
### Docker Image
87+
88+
The OpenSIPS CLI tool can be run in a Docker container. The image is available
89+
on Docker Hub at [opensips/opensips-cli](https://hub.docker.com/r/opensips/opensips-cli).
90+
For more information on how to run the tool in a Docker container, please refer to the
91+
[OpenSIPS CLI Docker Image](docker/docker.md) documentation.
92+
8693
## Configuration
8794

8895
OpenSIPS CLI accepts a configuration file, formatted as an `ini` or `cfg`

docker/Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM python:3.9-slim-buster
2+
LABEL maintainer="Razvan Crainea <[email protected]>"
3+
4+
USER root
5+
6+
# Set Environment Variables
7+
ENV DEBIAN_FRONTEND noninteractive
8+
9+
#install basic components
10+
RUN apt-get -y update -qq && \
11+
apt-get -y install git default-libmysqlclient-dev gcc
12+
13+
#add keyserver, repository
14+
RUN git clone https://github.com/OpenSIPS/opensips-cli.git /usr/src/opensips-cli && \
15+
cd /usr/src/opensips-cli && \
16+
python3 setup.py install clean --all && \
17+
cd / && rm -rf /usr/src/opensips-cli
18+
19+
RUN apt-get purge -y git gcc && \
20+
apt-get autoremove -y && \
21+
apt-get clean
22+
23+
ADD "run.sh" "/run.sh"
24+
25+
ENV PYTHONPATH /usr/lib/python3/dist-packages
26+
27+
ENTRYPOINT ["/run.sh", "-o", "communication_type=http"]

docker/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
NAME ?= opensips-cli
2+
OPENSIPS_DOCKER_TAG ?= latest
3+
4+
all: build start
5+
6+
.PHONY: build start
7+
build:
8+
docker build \
9+
--tag="opensips/opensips-cli:$(OPENSIPS_DOCKER_TAG)" \
10+
.
11+
12+
start:
13+
docker run -d --name $(NAME) opensips/opensips-cli:$(OPENSIPS_DOCKER_TAG)

docker/docker.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# OpenSIPS CLI Docker Image
2+
3+
Docker recipe for running [OpenSIPS Command Line
4+
Interface](https://github.com/OpenSIPS/opensips-cli).
5+
6+
## Building the image
7+
You can build the docker image by running:
8+
```
9+
make build
10+
```
11+
12+
This command will build a docker image with OpenSIPS CLI master version taken from
13+
the git repository
14+
15+
## Parameters
16+
17+
The container receives parameters in the following format:
18+
```
19+
[-o KEY=VALUE]* CMD [PARAMS]*
20+
```
21+
22+
Meaning of the parameters is as it follows:
23+
24+
* `-o KEY=VALUE` - used to tune `opensips-cli` at runtime; these parameters
25+
will end up in opensips-cli config file, in the `default` section, as
26+
`KEY: VALUE` lines
27+
* `CMD` - the command used to run; if the `CMD` ends with `.sh` extension, it
28+
will be run as a bash script, if the `CMD` ends with `.py` extension, it is
29+
run as a python script, otherwise it is run as a `opensips-cli` command
30+
* `PARAMS` - optional additional parameters passed to `CMD`
31+
32+
## Run
33+
34+
To run a bash script, simply pass the connector followed by the bash script:
35+
```
36+
docker run -d --name opensips-cli opensips/opensips-cli:latest \
37+
-o url=http://8.8.8.8:8888/mi script.sh
38+
```
39+
40+
Similarly, run a python script:
41+
```
42+
docker run -d --name opensips-cli opensips/opensips-cli:latest \
43+
-o url=http://8.8.8.8:8888/mi script.py
44+
```
45+
46+
To run a single MI command, use:
47+
```
48+
docker run -d --name opensips-cli opensips/opensips-cli:latest \
49+
-o url=http://8.8.8.8:8888/mi -x mi ps
50+
```
51+
52+
## DockerHub
53+
54+
Docker images are available on
55+
[DockerHub](https://hub.docker.com/r/opensips/opensips-cli).

docker/run.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
OPTS=
4+
CMD=
5+
PARAMS=
6+
CFG=/etc/opensips-cli.cfg
7+
8+
echo "[default]" > "$CFG"
9+
10+
while [[ $# -gt 0 ]]; do
11+
case "$1" in
12+
-o|--option)
13+
shift
14+
P=$(cut -d'=' -f1 <<<"$1")
15+
V=$(cut -d'=' -f2- <<<"$1")
16+
echo "$P: $V" >> "$CFG"
17+
;;
18+
*)
19+
if [ -z "$CMD" ]; then
20+
CMD="$1"
21+
else
22+
PARAMS="${PARAMS} ${1}"
23+
fi
24+
;;
25+
esac
26+
shift
27+
done
28+
29+
if [[ $CMD == *.py ]]; then
30+
TOOL=python3
31+
elif [[ $CMD == *.sh ]]; then
32+
TOOL=bash
33+
else
34+
TOOL=opensips-cli
35+
fi
36+
37+
exec $TOOL $CMD $PARAMS

0 commit comments

Comments
 (0)