Skip to content

Commit

Permalink
Merge pull request #3 from OpenSIPS/dockerimage
Browse files Browse the repository at this point in the history
Add Docker image
  • Loading branch information
razvancrainea authored Nov 14, 2024
2 parents a550270 + 72e5f57 commit 8569973
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 1 deletion.
39 changes: 39 additions & 0 deletions .github/workflows/docker-push-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Push OpenSIPS Python Images to Docker Hub

on:
push:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'

steps:
- uses: actions/checkout@v3

- name: Log in to Docker Hub
uses: docker/login-action@v2.1.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Get latest tag if manually triggered
id: get_tag
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
git fetch --tags
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "tag=$LATEST_TAG" >> $GITHUB_ENV
else
echo "tag=${{ github.ref_name }}" >> $GITHUB_ENV
fi
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
opensips/python-opensips:latest
opensips/python-opensips:${{ env.tag }}
26 changes: 26 additions & 0 deletions .github/workflows/docker-readme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: Update Docker Hub Description
on:
push:
branches:
- main
paths:
- docker/docker.md
- .github/workflows/docker-readme.yml

jobs:
dockerHubDescription:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4


- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
repository: opensips/python-opensips
readme-filepath: ./docker/docker.md
short-description: ${{ github.event.repository.description }}
enable-url-completion: true
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OpenSIPS Python Packages

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.
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.

## Features

Expand Down Expand Up @@ -66,6 +66,7 @@ Currently, the following packages are available:

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

## Scripts
### MI
Expand Down
10 changes: 10 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.9-slim-buster
LABEL maintainer="Darius Stefan <darius.stefan@opensips.org>"

RUN pip install opensips

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 8569973

Please sign in to comment.