Skip to content

Commit

Permalink
Merge pull request #293 from plivo/local-docker-enhancement
Browse files Browse the repository at this point in the history
Local docker enhancement
  • Loading branch information
renoldthomas-plivo authored Mar 17, 2023
2 parents de012aa + 93a75b1 commit 0de6790
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ubuntu:18.04

WORKDIR /usr/src/app
RUN apt-get update && apt-get install -y wget git vim
RUN apt-get update && apt-get install -y wget git vim make

# Install node using nvm
RUN mkdir -p /usr/src/.nvm
Expand Down
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
.PHONY: build test
.PHONY: build test run

build:
docker-compose up --build --remove-orphans

test:
docker exec -it $$CONTAINER /bin/bash -c "npm install request --no-save && npm test"
@[ "${CONTAINER}" ] && \
(docker exec -it $$CONTAINER /bin/bash -c "npm install request --no-save && npm test") || \
(npm install request --no-save && npm test)

run:
@[ "${CONTAINER}" ] && \
(docker exec -it $$CONTAINER /bin/bash -c 'cd /usr/src/app/node-sdk-test/ && node test.js') || \
(cd /usr/src/app/node-sdk-test/ && node test.js)
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,10 @@ export PLIVO_API_PROD_HOST=<plivoapi_public_endpoint>
5. The sdk directory will be mounted as a volume in the container. So any changes in the sdk code will also be reflected inside the container. However, when any change is made, the dependencies for the test program need to be re-installed. To do that:
* Either restart the docker container
* Or Run the `setup_sdk.sh` script
6. To run unit tests, run `make test CONTAINER=<cont_id>` in host, where `<cont_id>` is the docker container id created in 2.
(The docker container should be running)
6. To run test code, run `make run CONTAINER=<cont_id>` in host.
7. To run unit tests, run `make test CONTAINER=<cont_id>` in host.
> `<cont_id>` is the docker container id created in 2.
(The docker container should be running)

> Test code and unit tests can also be run within the container using
`make run` and `make test` respectively. (`CONTAINER` argument should be omitted when running from the container)
18 changes: 11 additions & 7 deletions setup_sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ npm init -y
npm install $package
rm $package

echo -e "\n\nSDK setup complete!"
echo "To test your changes:"
echo -e "\t1. Add your test code in <path_to_cloned_sdk>/$testDir/test.js on host (or /usr/src/app/$testDir/test.js in the container)"
echo -e "\t2. Run a terminal in the container using: $GREEN docker exec -it $HOSTNAME /bin/bash$NC"
echo -e "\t3. Navigate to the test directory: $GREEN cd /usr/src/app/$testDir$NC"
echo -e "\t4. Run your test file: $GREEN node test.js$NC"
echo -e "\t5. For running unit tests, run on host: $GREEN make test CONTAINER=$HOSTNAME$NC"
echo -e "\n\nSDK setup complete! You can test changes either on host or inside the docker container:"
echo -e "\ta. To test your changes ON HOST:"
echo -e "\t\t1. Add your test code in <path_to_cloned_sdk>/$testDir/test.js"
echo -e "\t\t2. Run your test file using: $GREEN make run CONTAINER=$HOSTNAME$NC"
echo -e "\t\t3. Run unit tests using: $GREEN make test CONTAINER=$HOSTNAME$NC"
echo
echo -e "\tb. To test your changes INSIDE CONTAINER:"
echo -e "\t\t1. Run a terminal in the container using: $GREEN docker exec -it $HOSTNAME /bin/bash$NC"
echo -e "\t\t2. Add your test code in /usr/src/app/$testDir/test.js"
echo -e "\t\t3. Run your test file using: $GREEN make run$NC"
echo -e "\t\t4. Run unit tests using: $GREEN make test$NC"

# To keep the container running post setup
/bin/bash

0 comments on commit 0de6790

Please sign in to comment.