Skip to content

Commit

Permalink
Merge with Dockerfile repo
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusstefan committed Nov 14, 2024
1 parent 4a0e40f commit 3171f51
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 8 deletions.
22 changes: 14 additions & 8 deletions .github/workflows/docker-push-image.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
name: Trigger OpenSIPS CLI Images build and publish
name: Push OpenSIPS CLI Images in Docker Hub

on:
push:
repository_dispatch:
workflow_dispatch:

jobs:

build:

runs-on: ubuntu-latest

steps:
- name: Repository Dispatch
uses: myrotvorets/[email protected]
- uses: actions/checkout@v3

- name: Log in to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
token: ${{ secrets.DOCKER_OPENSIPS_CLI_PAT }}
repo: OpenSIPS/docker-opensips-cli
type: OpenSIPS CLI Trigger
context: ./docker/
push: true
tags: opensips/opensips-cli:latest
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/opensips-cli
readme-filepath: ./docker/docker.md
short-description: ${{ github.event.repository.description }}
enable-url-completion: true
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ args = OpenSIPSCLIArgs(communcation_type = "http",
...
```

### Docker Image

The OpenSIPS CLI tool can be run in a Docker container. The image is available
on Docker Hub at [opensips/opensips-cli](https://hub.docker.com/r/opensips/opensips-cli).
For more information on how to run the tool in a Docker container, please refer to the
[OpenSIPS CLI Docker Image](docker/docker.md) documentation.

## Configuration

OpenSIPS CLI accepts a configuration file, formatted as an `ini` or `cfg`
Expand Down
27 changes: 27 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM python:3.9-slim-buster
LABEL maintainer="Razvan Crainea <[email protected]>"

USER root

# Set Environment Variables
ENV DEBIAN_FRONTEND noninteractive

#install basic components
RUN apt-get -y update -qq && \
apt-get -y install git default-libmysqlclient-dev gcc

#add keyserver, repository
RUN git clone https://github.com/OpenSIPS/opensips-cli.git /usr/src/opensips-cli && \
cd /usr/src/opensips-cli && \
python3 setup.py install clean --all && \
cd / && rm -rf /usr/src/opensips-cli

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

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

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

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

all: build start

.PHONY: build start
build:
docker build \
--tag="opensips/opensips-cli:$(OPENSIPS_DOCKER_TAG)" \
.

start:
docker run -d --name $(NAME) opensips/opensips-cli:$(OPENSIPS_DOCKER_TAG)
55 changes: 55 additions & 0 deletions docker/docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# OpenSIPS CLI Docker Image

Docker recipe for running [OpenSIPS Command Line
Interface](https://github.com/OpenSIPS/opensips-cli).

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

This command will build a docker image with OpenSIPS CLI master version taken from
the git repository

## Parameters

The container receives parameters in the following format:
```
[-o KEY=VALUE]* CMD [PARAMS]*
```

Meaning of the parameters is as it follows:

* `-o KEY=VALUE` - used to tune `opensips-cli` at runtime; these parameters
will end up in opensips-cli config file, in the `default` section, as
`KEY: VALUE` lines
* `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-cli` 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 -d --name opensips-cli opensips/opensips-cli:latest \
-o url=http://8.8.8.8:8888/mi script.sh
```

Similarly, run a python script:
```
docker run -d --name opensips-cli opensips/opensips-cli:latest \
-o url=http://8.8.8.8:8888/mi script.py
```

To run a single MI command, use:
```
docker run -d --name opensips-cli opensips/opensips-cli:latest \
-o url=http://8.8.8.8:8888/mi -x mi ps
```

## DockerHub

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

OPTS=
CMD=
PARAMS=
CFG=/etc/opensips-cli.cfg

echo "[default]" > "$CFG"

while [[ $# -gt 0 ]]; do
case "$1" in
-o|--option)
shift
P=$(cut -d'=' -f1 <<<"$1")
V=$(cut -d'=' -f2- <<<"$1")
echo "$P: $V" >> "$CFG"
;;
*)
if [ -z "$CMD" ]; then
CMD="$1"
else
PARAMS="${PARAMS} ${1}"
fi
;;
esac
shift
done

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

exec $TOOL $CMD $PARAMS

0 comments on commit 3171f51

Please sign in to comment.