From 0625e87da160c15f8a391ed23cc8268e0042afbd Mon Sep 17 00:00:00 2001 From: Illia Ananich Date: Tue, 18 Aug 2020 11:03:57 +0300 Subject: [PATCH 1/4] add Makefile --- .gitignore | 5 ++++- Makefile | 15 +++++++++++++++ README.md | 21 +++++++++++++++++++++ example.env | 15 +++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 Makefile create mode 100644 example.env diff --git a/.gitignore b/.gitignore index 496ee2c..efcb0e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -.DS_Store \ No newline at end of file +.DS_Store + +# local environment +.env diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..79b9c69 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +include .env +export + +run: + docker run -d -p ${TOR_ENTRY_PORT}:5566 -p ${HAPROXY_PORT}:4444 --env tors=${TOR_INSTANCES} --name ${CONTAINER_NAME} ${IMAGE_NAME} + +stop: + docker stop ${CONTAINER_NAME} + +rm: + docker rm ${CONTAINER_NAME} + +remove: + make stop + make rm diff --git a/README.md b/README.md index 6d3f907..ab534f4 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,27 @@ curl --proxy 127.0.0.1:5566 http://header.jsontest.com http://127.0.0.1:4444/haproxy?stats ``` +Usage with make +--------------- + +1. Install `make` command line utility + +2. Copy `example.env` as `.env` and edit settings + +3. Use `make` commands +```bash +# start docker container +make run + +# stop container +make stop + +# remove container +make rm + +# stop and remove container +make remove +``` Further Readings ---------------- diff --git a/example.env b/example.env new file mode 100644 index 0000000..563d3fd --- /dev/null +++ b/example.env @@ -0,0 +1,15 @@ + +# Docker container name +CONTAINER_NAME=rotating-proxy + +# Docker image name +IMAGE_NAME=mattes/rotating-proxy + +# How many parallel Tor instances to create +TOR_INSTANCES=16 + +# Entry port for Tor (http proxy) +TOR_ENTRY_PORT=5566 + +# Haproxy monitoring port +HAPROXY_PORT=4444 From b718eec3a127769177ff8dc40442d38320552402 Mon Sep 17 00:00:00 2001 From: Illia Ananich Date: Tue, 18 Aug 2020 11:34:38 +0300 Subject: [PATCH 2/4] add `ps` Makefile command --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 79b9c69..9a8b2bb 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,9 @@ export run: docker run -d -p ${TOR_ENTRY_PORT}:5566 -p ${HAPROXY_PORT}:4444 --env tors=${TOR_INSTANCES} --name ${CONTAINER_NAME} ${IMAGE_NAME} +ps: + docker ps -a | grep "${CONTAINER_NAME}" + stop: docker stop ${CONTAINER_NAME} From abf0242a1da0e36583555db2e8e365cdb70709bd Mon Sep 17 00:00:00 2001 From: Illia Ananich Date: Tue, 18 Aug 2020 11:39:53 +0300 Subject: [PATCH 3/4] add `log` and `flog` Makefile command --- Makefile | 6 ++++++ README.md | 8 ++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 9a8b2bb..f92b855 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,12 @@ run: ps: docker ps -a | grep "${CONTAINER_NAME}" +log: + docker logs ${CONTAINER_NAME} + +flog: + docker logs --follow ${CONTAINER_NAME} + stop: docker stop ${CONTAINER_NAME} diff --git a/README.md b/README.md index ab534f4..0a41366 100644 --- a/README.md +++ b/README.md @@ -47,16 +47,12 @@ Usage with make # start docker container make run -# stop container -make stop - -# remove container -make rm - # stop and remove container make remove ``` +See `Makefile` for full list of available shortcuts. + Further Readings ---------------- From 41075479e7778127d4c3579d8d78af591ddfe9ec Mon Sep 17 00:00:00 2001 From: Illia Ananich Date: Tue, 18 Aug 2020 11:42:00 +0300 Subject: [PATCH 4/4] add `Makefile` commands for Docker Service usage --- Makefile | 23 +++++++++++++++++++++++ README.md | 3 +++ example.env | 7 +++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f92b855..267d3a8 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ include .env export + +# Operating with simple Docker container +# -------------------------------------- + run: docker run -d -p ${TOR_ENTRY_PORT}:5566 -p ${HAPROXY_PORT}:4444 --env tors=${TOR_INSTANCES} --name ${CONTAINER_NAME} ${IMAGE_NAME} @@ -22,3 +26,22 @@ rm: remove: make stop make rm + + +# Operating with Docker service +# ----------------------------- + +service: + docker service create -p ${TOR_ENTRY_PORT}:5566 -p ${HAPROXY_PORT}:4444 --env tors=${TOR_INSTANCES} --name ${SERVICE_NAME} ${IMAGE_NAME} + +service-ls: + docker service ls | grep "${SERVICE_NAME}" + +service-log: + docker service logs ${SERVICE_NAME} + +service-flog: + docker service logs --follow ${SERVICE_NAME} + +service-rm: + docker service rm ${SERVICE_NAME} diff --git a/README.md b/README.md index 0a41366..9d4ed81 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,9 @@ make run # stop and remove container make remove + +# Alternatively, using Docker Service +make service ``` See `Makefile` for full list of available shortcuts. diff --git a/example.env b/example.env index 563d3fd..5fd3e2f 100644 --- a/example.env +++ b/example.env @@ -1,9 +1,12 @@ +# Docker image name +IMAGE_NAME=mattes/rotating-proxy + # Docker container name CONTAINER_NAME=rotating-proxy -# Docker image name -IMAGE_NAME=mattes/rotating-proxy +# Docker service name +SERVICE_NAME=rotating-proxy # How many parallel Tor instances to create TOR_INSTANCES=16