Skip to content

Commit e14894d

Browse files
hakbaileyabikouo
authored andcommitted
set up docker for local development
1 parent 163e1c2 commit e14894d

File tree

19 files changed

+374
-23
lines changed

19 files changed

+374
-23
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/db.sqlite3

Dockerfile.dev

Lines changed: 0 additions & 21 deletions
This file was deleted.

Makefile

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ help: ## Show this help message
1414
CONTAINER_RUNTIME ?= podman
1515
IMAGE_NAME ?= pattern-service
1616
IMAGE_TAG ?= latest
17+
QUAY_NAMESPACE ?= ansible
18+
BUILD_ARGS ?= "--arch amd64"
1719

1820
ensure-namespace:
1921
@test -n "$$QUAY_NAMESPACE" || (echo "Error: QUAY_NAMESPACE is required to push quay.io" && exit 1)
2022

2123
.PHONY: build
2224
build: ## Build the container image
2325
@echo "Building container image..."
24-
$(CONTAINER_RUNTIME) build -t $(IMAGE_NAME):$(IMAGE_TAG) -f Dockerfile.dev --arch amd64 .
26+
$(CONTAINER_RUNTIME) build -t $(IMAGE_NAME):$(IMAGE_TAG) -f tools/docker/Dockerfile.dev $(BUILD_ARGS) .
2527

2628
.PHONY: clean
2729
clean: ## Remove container image
@@ -34,6 +36,30 @@ push: ensure-namespace build ## Tag and push container image to Quay.io
3436
$(CONTAINER_RUNTIME) tag $(IMAGE_NAME):$(IMAGE_TAG) quay.io/$(QUAY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG)
3537
$(CONTAINER_RUNTIME) push quay.io/$(QUAY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG)
3638

39+
#--------------------------------------
40+
# Compose
41+
# -------------------------------------
42+
.PHONY: compose-build
43+
compose-build:
44+
$(CONTAINER_RUNTIME) compose -f tools/docker/docker-compose.yaml $(COMPOSE_OPTS) build
45+
46+
.PHONY: compose-up
47+
compose-up:
48+
$(CONTAINER_RUNTIME) compose -f tools/docker/docker-compose.yaml $(COMPOSE_OPTS) up $(COMPOSE_UP_OPTS) --remove-orphans
49+
50+
.PHONY: compose-down
51+
compose-down:
52+
$(CONTAINER_RUNTIME) compose -f tools/docker/docker-compose.yaml $(COMPOSE_OPTS) down --remove-orphans
53+
54+
.PHONY: compose-clean
55+
compose-clean:
56+
$(CONTAINER_RUNTIME) compose -f tools/docker/docker-compose.yaml rm -sf
57+
docker rmi --force localhost/ansible-pattern-service-api localhost/ansible-pattern-service-worker
58+
docker volume rm -f postgres_data
59+
60+
.PHONY: compose-restart
61+
compose-restart: compose-down compose-clean compose-up
62+
3763
# -------------------------------------
3864
# Dependencies
3965
# -------------------------------------

core/apps.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
import logging
2+
import os
3+
4+
from dispatcherd.config import setup as dispatcher_setup
15
from django.apps import AppConfig
6+
from django.conf import settings
7+
8+
logger = logging.getLogger(__name__)
29

310

411
class CoreConfig(AppConfig):
512
default_auto_field = "django.db.models.BigAutoField"
613
name = "core"
14+
15+
def ready(self) -> None:
16+
dispatcher_feature = os.environ.get(
17+
"PATTERN_SERVICE_FEATURE_DISPATCHERD", "false"
18+
)
19+
if dispatcher_feature.lower() in ("true", "1", "yes"):
20+
# Setup dispatcher configuration
21+
dispatcher_setup(config=settings.DISPATCHER_CONFIG)

core/management/__init__.py

Whitespace-only changes.

core/management/commands/__init__.py

Whitespace-only changes.

core/management/commands/worker.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import logging
2+
3+
from dispatcherd import run_service
4+
from django.core.management.base import BaseCommand
5+
6+
logger = logging.getLogger(__name__)
7+
8+
9+
class Command(BaseCommand):
10+
"""Wrapper for worker command."""
11+
12+
def handle(self, *args: tuple, **options: dict) -> None:
13+
logger.info("Starting Pattern service dispatcherd worker.")
14+
run_service()

core/tasks/__init__.py

Whitespace-only changes.

core/tasks/hazmat.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import django
2+
from django.core.cache import cache
3+
from django.db import connection
4+
5+
"""This module is an optimization for dispatcherd workers
6+
This sets up Django pre-fork, which must be implemented as a module to run
7+
on-import for compatibility with multiprocessing forkserver.
8+
This should never be imported by other modules, which is why it is called
9+
hazmat.
10+
"""
11+
12+
13+
django.setup()
14+
15+
# connections may or may not be open, but
16+
# before forking, all connections should be closed
17+
18+
cache.close()
19+
connection.close()

pattern_service/settings/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from ansible_base.lib.dynamic_config import load_envvars
66
from ansible_base.lib.dynamic_config import load_standard_settings_files
77

8+
from .dispatcher import override_dispatcher_settings
9+
810
try:
911
from dotenv import load_dotenv
1012

@@ -24,4 +26,5 @@
2426
)
2527
load_standard_settings_files(DYNACONF)
2628
load_envvars(DYNACONF)
29+
override_dispatcher_settings(DYNACONF)
2730
export(__name__, DYNACONF)

0 commit comments

Comments
 (0)