From d3e96bbdf5512928e6f6edaf38d2ce3823c0cbbc Mon Sep 17 00:00:00 2001 From: isnoor Date: Tue, 10 Oct 2023 19:55:31 +0700 Subject: [PATCH 1/3] first commit docker-compose for development --- dev/README.md | 72 +++++++++++++++++++++++++++++++++++++++++ dev/docker-compose.yaml | 38 ++++++++++++++++++++++ dev/entrypoint.sh | 24 ++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 dev/README.md create mode 100644 dev/docker-compose.yaml create mode 100644 dev/entrypoint.sh diff --git a/dev/README.md b/dev/README.md new file mode 100644 index 0000000..27a62f0 --- /dev/null +++ b/dev/README.md @@ -0,0 +1,72 @@ +# Use Docker Compose to develop lineblocs - ari-apps + +## Structure of directory +```shell +. +├── api +├── bitbucket-pipelines.yml +├── dev +| ├── docker-compose.yaml +| └── entrypoint.sh +├── 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 + +``` + +## Simple running +```shell +$ git clone https://github.com/Lineblocs/ari-apps.git +$ cp .env.docker .env +$ cd ari-apps/dev +$ docker compose up -d +``` + +## 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 confige +```shell +$ cp .env.docker .env +``` +### Move to dev directory +``` +$ cd ari-apps/dev +``` + +### create container +Create and run container with this command below. + +```shell +$ docker compose up -d +``` + +### 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..efb0655 --- /dev/null +++ b/dev/docker-compose.yaml @@ -0,0 +1,38 @@ +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 + volumes: + - ..:/app + - ../netdiscover:/bin/netdiscover + - ../go.mod:/go.mod + - ../go.sum:/go.sum + + 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" \ 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 From 8f5917348edc0e7e04247ae1bf075aed231ab9a5 Mon Sep 17 00:00:00 2001 From: is noor Date: Thu, 19 Oct 2023 09:28:52 +0700 Subject: [PATCH 2/3] add asterisk continer --- .gitignore | 5 ++++- dev/.env.example | 12 ++++++++++++ dev/README.md | 24 +++++++++++++++++++---- dev/docker-compose.yaml | 42 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 dev/.env.example 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 index 27a62f0..35888cf 100644 --- a/dev/README.md +++ b/dev/README.md @@ -2,12 +2,14 @@ ## Structure of directory ```shell -. +ari-apps ├── api ├── bitbucket-pipelines.yml ├── dev | ├── docker-compose.yaml | └── entrypoint.sh +| └── README.md +| └── .env ├── Dockerfile ├── entrypoint.sh ├── go.mod @@ -27,6 +29,7 @@ ├── router.proto ├── types └── utils +asterisk ``` @@ -35,7 +38,8 @@ $ git clone https://github.com/Lineblocs/ari-apps.git $ cp .env.docker .env $ cd ari-apps/dev -$ docker compose up -d +$ cp .env.example .env +$ docker compose --profile asterisk-cloud up -d ``` ## Advance running @@ -46,7 +50,8 @@ Clone docker compose and move to directory. $ git clone https://github.com/Lineblocs/ari-apps.git ``` -### Make .env file and confige +### Make .env file and configure +env file for ari-apps ```shell $ cp .env.docker .env ``` @@ -55,11 +60,22 @@ $ cp .env.docker .env $ 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 up -d +$ 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 ``` ### Useful command diff --git a/dev/docker-compose.yaml b/dev/docker-compose.yaml index efb0655..40de7d3 100644 --- a/dev/docker-compose.yaml +++ b/dev/docker-compose.yaml @@ -35,4 +35,46 @@ services: /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 From 4e136a991fbb3e396f94104ce6cd39e75af19908 Mon Sep 17 00:00:00 2001 From: is noor Date: Thu, 7 Dec 2023 22:17:28 +0700 Subject: [PATCH 3/3] add docker watch --- dev/README.md | 5 +++++ dev/docker-compose.yaml | 33 +++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/dev/README.md b/dev/README.md index 35888cf..dde7a7e 100644 --- a/dev/README.md +++ b/dev/README.md @@ -1,5 +1,8 @@ # 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 @@ -40,6 +43,7 @@ $ cp .env.docker .env $ cd ari-apps/dev $ cp .env.example .env $ docker compose --profile asterisk-cloud up -d +$ docker compose watch ``` ## Advance running @@ -76,6 +80,7 @@ $ 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 diff --git a/dev/docker-compose.yaml b/dev/docker-compose.yaml index 40de7d3..069c905 100644 --- a/dev/docker-compose.yaml +++ b/dev/docker-compose.yaml @@ -12,12 +12,33 @@ services: image: lineblocs-ari-apps logging: *default-logging container_name: lineblocs-ari-apps - volumes: - - ..:/app - - ../netdiscover:/bin/netdiscover - - ../go.mod:/go.mod - - ../go.sum:/go.sum - + # 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}