diff --git a/.gitignore b/.gitignore index af63df9..a554d33 100755 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,7 @@ # Go workspace file go.work -.env \ No newline at end of file +.env + +log.txt +main \ No newline at end of file diff --git a/dev/.env.example b/dev/.env.example new file mode 100644 index 0000000..c15d575 --- /dev/null +++ b/dev/.env.example @@ -0,0 +1,12 @@ +## for Asterisk only +AMI_HOST=155.138.131.82 +AMI_PORT=5038 +AMI_USER=ami +AMI_PASS=123 + +ARI_USERNAME=ariuser +ARI_PASSWORD=myaripassword + +LINEBLOCS_KEY=123 + +VERSION=master \ No newline at end of file diff --git a/dev/README.md b/dev/README.md new file mode 100644 index 0000000..dde7a7e --- /dev/null +++ b/dev/README.md @@ -0,0 +1,93 @@ +# Use Docker Compose to develop lineblocs - ari-apps + +## Notice +Please make sure use docker compose with minimal version 2.2 + +## Structure of directory +```shell +ari-apps +├── api +├── bitbucket-pipelines.yml +├── dev +| ├── docker-compose.yaml +| └── entrypoint.sh +| └── README.md +| └── .env +├── Dockerfile +├── entrypoint.sh +├── go.mod +├── go.sum +├── grpc +├── helpers +├── keys +├── lineblocs.proto +├── logger +├── log.txt +├── main +├── main.go +├── mngrs +├── netdiscover +├── README.md +├── router +├── router.proto +├── types +└── utils +asterisk + +``` + +## Simple running +```shell +$ git clone https://github.com/Lineblocs/ari-apps.git +$ cp .env.docker .env +$ cd ari-apps/dev +$ cp .env.example .env +$ docker compose --profile asterisk-cloud up -d +$ docker compose watch +``` + +## Advance running + +### Clone ari-apps project +Clone docker compose and move to directory. +```shell +$ git clone https://github.com/Lineblocs/ari-apps.git +``` + +### Make .env file and configure +env file for ari-apps +```shell +$ cp .env.docker .env +``` +### Move to dev directory +``` +$ cd ari-apps/dev +``` + +### Make .env file and configure +env file for docker compose and asterisk +```shell +$ cp .env.example .env +``` + +### create container +Create and run container with this command below. + +```shell +$ docker compose --profile asterisk-cloud up -d +``` + +While want to modify asterisk configuration, build asterisk on local. Use profile asterisk-local to do that. Also clone asterisk project, put on same directory with ari-apps project. Create and run container with this command below. +```shell +$ docker compose --profile asterisk-local up -d +$ docker compose watch +``` + +### Useful command +Check log `docker logs -f lineblocs-ari-apps` + +Log in to terminal of container -> `docker exec -it lineblocs-ari-apps bash` + +Modify project under `ari-apps` directory + +After change configuration, Please run `docker compose restart` diff --git a/dev/docker-compose.yaml b/dev/docker-compose.yaml new file mode 100644 index 0000000..069c905 --- /dev/null +++ b/dev/docker-compose.yaml @@ -0,0 +1,101 @@ +version: "3.6" +x-logging: &default-logging + options: + max-size: "100m" + max-file: "5" + driver: json-file +services: + ari_apps: + build: + context: .. + dockerfile: Dockerfile + image: lineblocs-ari-apps + logging: *default-logging + container_name: lineblocs-ari-apps + # Please choose, use block of "volumes" or "develop" + # volumes: + # - ..:/app + # - ../netdiscover:/bin/netdiscover + # - ../go.mod:/go.mod + # - ../go.sum:/go.sum + develop: + watch: + - action: sync + path: .. + target: /app + - action: sync+restart + path: ./entrypoint.sh + target: /app/dev/entrypoint.sh + - action: sync+restart + path: ../netdiscover + target: /bin/netdiscover + - action: sync+restart + path: ../go.mod + target: /go.mod + - action: sync+restart + path: ../go.sum + target: /go.sum + - action: rebuild + path: ./Dockerfile + - action: rebuild + path: ./docker-compose.yaml + restart: unless-stopped + # environment: + # - DEPLOYMENT_DOMAIN=${DEPLOYMENT_DOMAIN} + # - ARI_HOST=${ARI_HOST} + # - ARI_PORT=${ARI_PORT} + # - ARI_USERNAME=${ARI_USERNAME} + # - ARI_PASSWORD=${ARI_PASSWORD} + # - ARI_USE_PROXY=${ARI_USE_PROXY} + # - LINEBLOCS_KEY=${LINEBLOCS_KEY} + # - NATSGW_URL= + # - PROXY_HOST= + # - USE_DOTENV= + entrypoint: + sh -c " + /bin/bash ; + /app/dev/entrypoint.sh ; + " + network_mode: "host" + + asterisk: + build: + context: ../../asterisk/ + dockerfile: Dockerfile + image: lineblocs-asterisk + volumes: + - ../../asterisk/configs:/etc/asterisk/ + logging: *default-logging + container_name: lineblocs-asterisk + restart: unless-stopped + environment: + - AMI_USER=${AMI_USER} + - AMI_PASS=${AMI_PASS} + - AMI_PORT=${AMI_PORT} + - AMI_HOST=${AMI_HOST} + - ARI_USERNAME=${ARI_USERNAME} + - ARI_PASSWORD=${ARI_PASSWORD} + - LINEBLOCS_KEY=${LINEBLOCS_KEY} + profiles: + - asterisk-local + network_mode: "host" + + asterisk-cloud: + image: lineblocs/asterisk:${VERSION} + # to enable costum config. Please uncomment volumes and that value. Also make sure, you have asterisk project + # volumes: + # - ../../asterisk/configs:/etc/asterisk/ + logging: *default-logging + container_name: lineblocs-asterisk-cloud + restart: unless-stopped + environment: + - AMI_USER=${AMI_USER} + - AMI_PASS=${AMI_PASS} + - AMI_PORT=${AMI_PORT} + - AMI_HOST=${AMI_HOST} + - ARI_USERNAME=${ARI_USERNAME} + - ARI_PASSWORD=${ARI_PASSWORD} + - LINEBLOCS_KEY=${LINEBLOCS_KEY} + profiles: + - asterisk-cloud + network_mode: "host" \ No newline at end of file diff --git a/dev/entrypoint.sh b/dev/entrypoint.sh new file mode 100644 index 0000000..0f3e49b --- /dev/null +++ b/dev/entrypoint.sh @@ -0,0 +1,24 @@ +#! /bin/bash +# determine proxy host to use + +if [[ -z "${ARI_URL}" ]]; then + : ${CLOUD=""} # One of aws, azure, do, gcp, or empty + if [ "$CLOUD" != "" ]; then + PROVIDER="-provider ${CLOUD}" + fi + + PRIVATE_IPV4=$(netdiscover -field privatev4 ${PROVIDER}) + #PRIVATE_IPV4="172.24.0.1" + PUBLIC_IPV4=$(netdiscover -field publicv4 ${PROVIDER}) + + export PROXY_HOST=${PUBLIC_IPV4} + export ARI_URL="http://${PROXY_HOST}:8088/ari" + export ARI_WSURL="ws://${PROXY_HOST}:8088/ari/events" +fi + +cd /app +go mod download + +go build -o main main.go + +./main \ No newline at end of file