-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e0183c
commit 9419e4e
Showing
6 changed files
with
98 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,3 +142,6 @@ cython_debug/ | |
.vscode/ | ||
.idea/ | ||
.vim/ | ||
|
||
# Development Docker Compose file | ||
docker-compose.dev.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Any | ||
|
||
import yaml | ||
|
||
|
||
class YamlProcessor(ABC): | ||
@abstractmethod | ||
def process(self, data: Any) -> Any: | ||
pass | ||
|
||
|
||
class LocalBuildStrategy(YamlProcessor): | ||
def process(self, data: Any) -> Any: | ||
if data["x-artemis-build-or-image"].get("image"): | ||
del data["x-artemis-build-or-image"]["image"] | ||
data["x-artemis-build-or-image"]["build"] = {"context": ".", "dockerfile": "docker/Dockerfile"} | ||
return data | ||
return data | ||
|
||
|
||
class WebCommandStrategy(YamlProcessor): | ||
def process(self, data: Any) -> Any: | ||
for service in data["services"]: | ||
if service == "web": | ||
data["services"][service]["command"] = "uvicorn artemis.main:app --host 0.0.0.0 --port 5000 --reload" | ||
return data | ||
|
||
|
||
class VolumeDevelopStrategy(YamlProcessor): | ||
def process(self, data: Any) -> Any: | ||
for service in data["services"]: | ||
if service == "web" and "./:/opt" not in data["services"][service]["volumes"]: | ||
data["services"][service]["volumes"].append("./:/opt") | ||
return data | ||
|
||
|
||
class LocalBuildContainersStrategy(YamlProcessor): | ||
def process(self, data: Any) -> Any: | ||
for service in data["services"]: | ||
if data["services"][service]["image"] == "certpl/artemis:latest": | ||
del data["services"][service]["image"] | ||
data["services"][service]["build"] = {"context": ".", "dockerfile": "docker/Dockerfile"} | ||
return data | ||
|
||
|
||
class FileProcessor: | ||
def __init__(self, input_file: str, output_file: str) -> None: | ||
self.docker_compose_data = None | ||
self.input_file = input_file | ||
self.output_file = output_file | ||
|
||
def set_data(self) -> None: | ||
self.docker_compose_data = yaml.safe_load(open(self.input_file)) | ||
|
||
def process_file(self, strategy: YamlProcessor) -> None: | ||
self.docker_compose_data = strategy.process(self.docker_compose_data) | ||
|
||
with open(self.output_file, "w") as file: | ||
yaml.dump(self.docker_compose_data, file) | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
input_yaml_file = "docker-compose.yaml" | ||
output_yaml_file = "docker-compose.dev.yaml" | ||
|
||
processor = FileProcessor(input_yaml_file, output_yaml_file) | ||
processor.set_data() | ||
|
||
processor.process_file(LocalBuildStrategy()) | ||
|
||
processor.process_file(WebCommandStrategy()) | ||
|
||
processor.process_file(VolumeDevelopStrategy()) | ||
|
||
processor.process_file(LocalBuildContainersStrategy()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
cd $(dirname $0)/.. | ||
python3 scripts/create_development_docker_compose.py | ||
|
||
ADDITIONAL_DOCKER_COMPOSE_OPTIONS="-f docker-compose.dev.yaml" ./scripts/start |