Skip to content

Improve Docker setup #655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,47 @@ SERVICES := db web proxy redis celery celery-beat
.PHONY: setup certs up build username pull down stop restart rm logs

certs: ## Generate certificates.
@${COMPOSE_PREFIX_CMD} docker-compose -f docker-compose.setup.yml run --rm certs
@${COMPOSE_PREFIX_CMD} docker compose -f docker-compose.setup.yml run --rm certs

setup: ## Generate certificates.
@make certs

up: ## Build and start all services.
${COMPOSE_PREFIX_CMD} docker-compose ${COMPOSE_ALL_FILES} up -d --build ${SERVICES}
up: ## Start all services.
${COMPOSE_PREFIX_CMD} docker compose ${COMPOSE_ALL_FILES} up -d ${SERVICES}

build: ## Build all services.
${COMPOSE_PREFIX_CMD} docker-compose ${COMPOSE_ALL_FILES} build ${SERVICES}
${COMPOSE_PREFIX_CMD} docker compose ${COMPOSE_ALL_FILES} build ${SERVICES}

username: ## Generate Username (Use only after make up).
${COMPOSE_PREFIX_CMD} docker-compose ${COMPOSE_ALL_FILES} exec web python3 manage.py createsuperuser
${COMPOSE_PREFIX_CMD} docker compose ${COMPOSE_ALL_FILES} exec web python3 manage.py createsuperuser

pull: ## Pull Docker images.
docker login docker.pkg.github.com
${COMPOSE_PREFIX_CMD} docker-compose ${COMPOSE_ALL_FILES} pull
${COMPOSE_PREFIX_CMD} docker compose ${COMPOSE_ALL_FILES} pull

down: ## Down all services.
${COMPOSE_PREFIX_CMD} docker-compose ${COMPOSE_ALL_FILES} down
${COMPOSE_PREFIX_CMD} docker compose ${COMPOSE_ALL_FILES} down

stop: ## Stop all services.
${COMPOSE_PREFIX_CMD} docker-compose ${COMPOSE_ALL_FILES} stop ${SERVICES}
${COMPOSE_PREFIX_CMD} docker compose ${COMPOSE_ALL_FILES} stop ${SERVICES}

restart: ## Restart all services.
${COMPOSE_PREFIX_CMD} docker-compose ${COMPOSE_ALL_FILES} restart ${SERVICES}
${COMPOSE_PREFIX_CMD} docker compose ${COMPOSE_ALL_FILES} restart ${SERVICES}

rm: ## Remove all services containers.
${COMPOSE_PREFIX_CMD} docker-compose $(COMPOSE_ALL_FILES) rm -f ${SERVICES}
${COMPOSE_PREFIX_CMD} docker compose $(COMPOSE_ALL_FILES) rm -f ${SERVICES}

test:
${COMPOSE_PREFIX_CMD} docker-compose $(COMPOSE_ALL_FILES) exec celery python3 -m unittest tests/test_scan.py

logs: ## Tail all logs with -n 1000.
${COMPOSE_PREFIX_CMD} docker-compose $(COMPOSE_ALL_FILES) logs --follow --tail=1000 ${SERVICES}
${COMPOSE_PREFIX_CMD} docker compose $(COMPOSE_ALL_FILES) logs --follow --tail=1000 ${SERVICES}

images: ## Show all Docker images.
${COMPOSE_PREFIX_CMD} docker-compose $(COMPOSE_ALL_FILES) images ${SERVICES}
${COMPOSE_PREFIX_CMD} docker compose $(COMPOSE_ALL_FILES) images ${SERVICES}

prune: ## Remove containers and delete volume data.
@make stop && make rm && docker volume prune -f

help: ## Show this help.
@echo "Make application docker images and manage containers using docker-compose files."
@echo "Make application docker images and manage containers using docker compose files."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@echo "Make application docker images and manage containers using docker compose files."
@echo "Make application Docker images and manage containers using Docker Compose files."

@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m (default: help)\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-12s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
13 changes: 7 additions & 6 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ services:

redis:
image: "redis:alpine"
hostname: redis
restart: always
networks:
- rengine_network

celery:
build:
context: ./web
build: ./web
image: yogeshojha/rengine:master
restart: always
entrypoint: /usr/src/app/celery-entrypoint.sh
# command: watchmedo auto-restart --recursive --pattern="*.py" --directory="/usr/src/app/reNgine/" -- celery -A reNgine.tasks worker --autoscale=10,0 -l INFO
Expand Down Expand Up @@ -56,6 +56,8 @@ services:

celery-beat:
build: ./web
image: yogeshojha/rengine:master
restart: always
entrypoint: /usr/src/app/beat-entrypoint.sh
command: celery -A reNgine beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler
depends_on:
Expand All @@ -81,11 +83,10 @@ services:
- rengine_network

web:
build:
context: ./web
build: ./web
entrypoint: /usr/src/app/entrypoint.sh
restart: always
image: docker.pkg.github.com/yogeshojha/rengine/rengine:latest
image: yogeshojha/rengine:master
environment:
- DEBUG=1
- CELERY_BROKER=redis://redis:6379/0
Expand Down
14 changes: 7 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ services:

redis:
image: "redis:alpine"
restart: always
hostname: redis
networks:
- rengine_network

celery:
build:
context: ./web
build: ./web
image: yogeshojha/rengine:master
restart: always
entrypoint: /usr/src/app/celery-entrypoint.sh
# command: celery -A reNgine worker --autoscale=${MAX_CONCURRENCY},${MIN_CONCURRENCY} -l INFO
Expand Down Expand Up @@ -55,6 +56,8 @@ services:

celery-beat:
build: ./web
image: yogeshojha/rengine:master
restart: always
entrypoint: /usr/src/app/beat-entrypoint.sh
command: celery -A reNgine beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler
environment:
Expand All @@ -79,11 +82,10 @@ services:
- rengine_network

web:
build:
context: ./web
build: ./web
entrypoint: /usr/src/app/entrypoint.sh
restart: always
image: docker.pkg.github.com/yogeshojha/rengine/rengine:latest
image: yogeshojha/rengine:master
environment:
- DEBUG=0
- CELERY_BROKER=redis://redis:6379/0
Expand All @@ -106,8 +108,6 @@ services:
- nuclei_templates:/root/nuclei-templates
- tool_config:/root/.config
- static_volume:/usr/src/app/staticfiles/
ports:
- "8000:8000"
depends_on:
- db
- celery
Expand Down
14 changes: 0 additions & 14 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,6 @@ else
tput setaf 2; echo "Docker installed!!!"
fi

echo " "
tput setaf 4;
echo "#########################################################################"
echo "Installing docker-compose"
echo "#########################################################################"
if [ -x "$(command -v docker-compose)" ]; then
tput setaf 2; echo "docker-compose already installed, skipping."
else
curl -L "https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
tput setaf 2; echo "docker-compose installed!!!"
fi

echo " "
tput setaf 4;
echo "#########################################################################"
Expand Down
30 changes: 15 additions & 15 deletions make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ set COMPOSE_ALL_FILES = -f docker-compose.yml
set SERVICES = db web proxy redis celery celery-beat

:: Generate certificates.
if "%1" == "certs" docker-compose -f docker-compose.setup.yml run --rm certs
if "%1" == "certs" docker compose -f docker-compose.setup.yml run --rm certs
:: Generate certificates.
if "%1" == "setup" docker-compose -f docker-compose.setup.yml run --rm certs
:: Build and start all services.
if "%1" == "up" docker-compose %COMPOSE_ALL_FILES% up -d --build %SERVICES%
if "%1" == "setup" docker compose -f docker-compose.setup.yml run --rm certs
:: Start all services.
if "%1" == "up" docker compose %COMPOSE_ALL_FILES% up -d %SERVICES%
:: Build all services.
if "%1" == "build" docker-compose %COMPOSE_ALL_FILES% build %SERVICES%
if "%1" == "build" docker compose %COMPOSE_ALL_FILES% build %SERVICES%
:: Generate Username (Use only after make up).
if "%1" == "username" docker-compose %COMPOSE_ALL_FILES% exec web python3 manage.py createsuperuser
if "%1" == "username" docker compose %COMPOSE_ALL_FILES% exec web python3 manage.py createsuperuser
:: Pull Docker images.
if "%1" == "pull" docker login docker.pkg.github.com & docker-compose %COMPOSE_ALL_FILES% pull
if "%1" == "pull" docker compose %COMPOSE_ALL_FILES% pull
:: Down all services.
if "%1" == "down" docker-compose %COMPOSE_ALL_FILES% down
if "%1" == "down" docker compose %COMPOSE_ALL_FILES% down
:: Stop all services.
if "%1" == "stop" docker-compose %COMPOSE_ALL_FILES% stop %SERVICES%
if "%1" == "stop" docker compose %COMPOSE_ALL_FILES% stop %SERVICES%
:: Restart all services.
if "%1" == "restart" docker-compose %COMPOSE_ALL_FILES% restart %SERVICES%
if "%1" == "restart" docker compose %COMPOSE_ALL_FILES% restart %SERVICES%
:: Remove all services containers.
if "%1" == "rm" docker-compose %COMPOSE_ALL_FILES% rm -f %SERVICES%
if "%1" == "rm" docker compose %COMPOSE_ALL_FILES% rm -f %SERVICES%
:: Tail all logs with -n 1000.
if "%1" == "logs" docker-compose %COMPOSE_ALL_FILES% logs --follow --tail=1000 %SERVICES%
if "%1" == "logs" docker compose %COMPOSE_ALL_FILES% logs --follow --tail=1000 %SERVICES%
:: Show all Docker images.
if "%1" == "images" docker-compose %COMPOSE_ALL_FILES% images %SERVICES%
if "%1" == "images" docker compose %COMPOSE_ALL_FILES% images %SERVICES%
:: Remove containers and delete volume data.
if "%1" == "prune" docker-compose %COMPOSE_ALL_FILES% stop %SERVICES% & docker-compose %COMPOSE_ALL_FILES% rm -f %SERVICES% & docker volume prune -f
if "%1" == "prune" docker compose %COMPOSE_ALL_FILES% stop %SERVICES% & docker compose %COMPOSE_ALL_FILES% rm -f %SERVICES% & docker volume prune -f
:: Show this help.
if "%1" == "help" @echo Make application docker images and manage containers using docker-compose files only for windows.
if "%1" == "help" @echo Make application docker images and manage containers using docker compose files only for windows.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if "%1" == "help" @echo Make application docker images and manage containers using docker compose files only for windows.
if "%1" == "help" @echo Make application Docker images and manage containers using Docker Compose files only for Windows.

Small nit.