From 64c905d7d2137272a35a3c075b9b0d6e6e2cc3b4 Mon Sep 17 00:00:00 2001 From: Stefan Darius <94108614+dariusstefan@users.noreply.github.com> Date: Mon, 21 Oct 2024 14:27:07 +0300 Subject: [PATCH 1/6] add docker image --- docker/Dockerfile | 20 ++++++++++++++++++++ docker/Makefile | 10 ++++++++++ docker/docker.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ docker/run.sh | 14 ++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 docker/Dockerfile create mode 100644 docker/Makefile create mode 100644 docker/docker.md create mode 100755 docker/run.sh diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..ea3cad7 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,20 @@ +FROM python:3.9-slim-buster +LABEL maintainer="Darius Stefan " + +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" ] diff --git a/docker/Makefile b/docker/Makefile new file mode 100644 index 0000000..fbb691d --- /dev/null +++ b/docker/Makefile @@ -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)" \ + . diff --git a/docker/docker.md b/docker/docker.md new file mode 100644 index 0000000..b0ccc55 --- /dev/null +++ b/docker/docker.md @@ -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). diff --git a/docker/run.sh b/docker/run.sh new file mode 100755 index 0000000..4e975bd --- /dev/null +++ b/docker/run.sh @@ -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 "$@" From 5c855c8dc0d422c1a310a9801992bcf9bc6ba415 Mon Sep 17 00:00:00 2001 From: Stefan Darius <94108614+dariusstefan@users.noreply.github.com> Date: Mon, 21 Oct 2024 14:32:12 +0300 Subject: [PATCH 2/6] update Readme about new Docker image --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4a0b5d5..a59a53b 100644 --- a/README.md +++ b/README.md @@ -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 From e9e562b8da13d064324220733aaffbb2a4b783ed Mon Sep 17 00:00:00 2001 From: Stefan Darius <94108614+dariusstefan@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:57:08 +0200 Subject: [PATCH 3/6] install opensips package using pip --- .github/workflows/docker-push-image.yml | 28 +++++++++++++++++++++++++ .github/workflows/docker-readme.yml | 26 +++++++++++++++++++++++ docker/Dockerfile | 12 +---------- 3 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/docker-push-image.yml create mode 100644 .github/workflows/docker-readme.yml diff --git a/.github/workflows/docker-push-image.yml b/.github/workflows/docker-push-image.yml new file mode 100644 index 0000000..d6f44f7 --- /dev/null +++ b/.github/workflows/docker-push-image.yml @@ -0,0 +1,28 @@ +name: Push OpenSIPS Python Images in Docker Hub + +on: + push: + repository_dispatch: + workflow_dispatch: + +jobs: + + build: + + runs-on: ubuntu-latest + + 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: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: opensips/python-opensips:latest diff --git a/.github/workflows/docker-readme.yml b/.github/workflows/docker-readme.yml new file mode 100644 index 0000000..dad2ad1 --- /dev/null +++ b/.github/workflows/docker-readme.yml @@ -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 diff --git a/docker/Dockerfile b/docker/Dockerfile index ea3cad7..6270687 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,17 +1,7 @@ FROM python:3.9-slim-buster LABEL maintainer="Darius Stefan " -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 +RUN pip install opensips ADD "run.sh" "/run.sh" From 23b954c0094c87fd7acffe59d85b167742ecd86f Mon Sep 17 00:00:00 2001 From: Darius Stefan Date: Thu, 14 Nov 2024 14:54:33 +0200 Subject: [PATCH 4/6] Mention Docker image in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a59a53b..d542fcb 100644 --- a/README.md +++ b/README.md @@ -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 From dd70eb07232dd790fdd8b845aa37ea564764dd09 Mon Sep 17 00:00:00 2001 From: Darius Stefan Date: Thu, 14 Nov 2024 15:19:22 +0200 Subject: [PATCH 5/6] Only publish Docker image on new release --- .github/workflows/docker-push-image.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker-push-image.yml b/.github/workflows/docker-push-image.yml index d6f44f7..7d800fc 100644 --- a/.github/workflows/docker-push-image.yml +++ b/.github/workflows/docker-push-image.yml @@ -2,14 +2,12 @@ name: Push OpenSIPS Python Images in Docker Hub on: push: - repository_dispatch: workflow_dispatch: jobs: - build: - runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') # only publish to Docker Hub on tag pushes steps: - uses: actions/checkout@v3 @@ -25,4 +23,6 @@ jobs: with: context: . push: true - tags: opensips/python-opensips:latest + tags: | + opensips/python-opensips:latest + opensips/python-opensips:${{ github.ref_name }} From 72e5f57990975fc4c2bd88172fe41f60b9ef3e0c Mon Sep 17 00:00:00 2001 From: Darius Stefan Date: Thu, 14 Nov 2024 15:25:21 +0200 Subject: [PATCH 6/6] Add manually triggered Docker Hub publish --- .github/workflows/docker-push-image.yml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-push-image.yml b/.github/workflows/docker-push-image.yml index 7d800fc..3c6845f 100644 --- a/.github/workflows/docker-push-image.yml +++ b/.github/workflows/docker-push-image.yml @@ -1,4 +1,4 @@ -name: Push OpenSIPS Python Images in Docker Hub +name: Push OpenSIPS Python Images to Docker Hub on: push: @@ -7,7 +7,7 @@ on: jobs: build: runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/') # only publish to Docker Hub on tag pushes + if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' steps: - uses: actions/checkout@v3 @@ -18,6 +18,17 @@ jobs: 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: @@ -25,4 +36,4 @@ jobs: push: true tags: | opensips/python-opensips:latest - opensips/python-opensips:${{ github.ref_name }} + opensips/python-opensips:${{ env.tag }}