Skip to content

Commit 8569973

Browse files
Merge pull request #3 from OpenSIPS/dockerimage
Add Docker image
2 parents a550270 + 72e5f57 commit 8569973

File tree

7 files changed

+148
-1
lines changed

7 files changed

+148
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Push OpenSIPS Python Images to Docker Hub
2+
3+
on:
4+
push:
5+
workflow_dispatch:
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
11+
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Log in to Docker Hub
16+
uses: docker/login-action@v2.1.0
17+
with:
18+
username: ${{ secrets.DOCKER_USERNAME }}
19+
password: ${{ secrets.DOCKER_TOKEN }}
20+
21+
- name: Get latest tag if manually triggered
22+
id: get_tag
23+
run: |
24+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
25+
git fetch --tags
26+
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
27+
echo "tag=$LATEST_TAG" >> $GITHUB_ENV
28+
else
29+
echo "tag=${{ github.ref_name }}" >> $GITHUB_ENV
30+
fi
31+
32+
- name: Build and push Docker image
33+
uses: docker/build-push-action@v4
34+
with:
35+
context: .
36+
push: true
37+
tags: |
38+
opensips/python-opensips:latest
39+
opensips/python-opensips:${{ env.tag }}
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/python-opensips
24+
readme-filepath: ./docker/docker.md
25+
short-description: ${{ github.event.repository.description }}
26+
enable-url-completion: true

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# OpenSIPS Python Packages
22

3-
This repository contains a collection of Python packages for OpenSIPS. These modules are designed to be as lightweight as possible and provide a simple interface for interacting with OpenSIPS.
3+
This repository contains a collection of Python packages for OpenSIPS. These modules are designed to be as lightweight as possible and provide a simple interface for interacting with OpenSIPS. Alongside the source code, the repository also contains a [Docker](docker/Dockerfile) image that comes with the OpenSIPS Python packages pre-installed.
44

55
## Features
66

@@ -66,6 +66,7 @@ Currently, the following packages are available:
6666

6767
* [MI](docs/mi.md) - contains information about supported MI communication types and required parameters for each type.
6868
* [Event Interface](docs/event.md) - lists the supported event transport protocols and provides information about the required parameters for each protocol.
69+
* [Docker](docker/docker.md) - provides information about the Docker image that contains the OpenSIPS Python packages.
6970

7071
## Scripts
7172
### MI

docker/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3.9-slim-buster
2+
LABEL maintainer="Darius Stefan <darius.stefan@opensips.org>"
3+
4+
RUN pip install opensips
5+
6+
ADD "run.sh" "/run.sh"
7+
8+
ENV PYTHONPATH=/usr/lib/python3/dist-packages
9+
10+
ENTRYPOINT [ "/run.sh" ]

docker/Makefile

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

docker/docker.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# OpenSIPS Python Docker Image
2+
3+
Docker recipe for running a container with pre-installed OpenSIPS Python packages.
4+
5+
## Building the image
6+
You can build the docker image by running:
7+
```
8+
make build
9+
```
10+
11+
This command will build a docker image with OpenSIPS Python packages installed, along with
12+
`opensips-mi` and `opensips-event` command line tools.
13+
14+
## Parameters
15+
16+
The container receives parameters in the following format:
17+
```
18+
CMD [PARAMS]*
19+
```
20+
21+
Meaning of the parameters is as it follows:
22+
* `CMD` - the command used to run; if the `CMD` ends with `.sh` extension, it
23+
will be run as a bash script, if the `CMD` ends with `.py` extension, it is
24+
run as a python script, otherwise it is run as a `opensips-mi` command
25+
* `PARAMS` - optional additional parameters passed to `CMD`
26+
27+
## Run
28+
29+
To run a bash script, simply pass the connector followed by the bash script:
30+
```
31+
docker run --rm opensips/python-opensips:latest script.sh
32+
```
33+
34+
Similarly, run a python script:
35+
```
36+
docker run --rm opensips/python-opensips:latest script.py
37+
```
38+
39+
To run a single MI command, use:
40+
```
41+
docker run --rm opensips/python-opensips:latest -t datagram uptime
42+
```
43+
44+
## DockerHub
45+
46+
Docker images are available on
47+
[DockerHub](https://hub.docker.com/r/opensips/python-opensips).

docker/run.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
CMD=$1
4+
shift
5+
6+
if [[ CMD == *.py ]]; then
7+
TOOL=python3
8+
elif [[ CMD == *.sh ]]; then
9+
TOOL=bash
10+
else
11+
TOOL=opensips-mi
12+
fi
13+
14+
exec $TOOL $CMD "$@"

0 commit comments

Comments
 (0)