Skip to content

Commit

Permalink
- Microservice added to docker-compose.
Browse files Browse the repository at this point in the history
issue #25
  • Loading branch information
albamig committed Feb 10, 2022
1 parent f58ac19 commit b1d2cf7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ build_docker_compose(destination.parent.parent / "docker-compose.yml", name) }}
27 changes: 27 additions & 0 deletions microservice/language/python/init/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,30 @@ def build_deploy_playbook(path: Path) -> str:
data.append({"name": "Create Database", "import_playbook": "create-database.yaml"})

return yaml.dump(data, sort_keys=False)


def build_docker_compose(path: Path, microservice_name: str) -> str:
"""Build Docker Compose file content."""

if not path.exists():
raise ValueError("A base Compose file must exist.")

with path.open() as file:
data = yaml.safe_load(file)

microservice_container = {
"restart": "always",
"build": {
"context": f"microservices/{microservice_name}",
"target": "production"
},
"environment": data["x-microservice-environment"],
"depends_on": data["x-microservice-depends-on"]
}

data["services"][f"microservice-{microservice_name}"] = microservice_container

with path.open("w") as file:
yaml.dump(data, file, sort_keys=False)

return ""
3 changes: 2 additions & 1 deletion microservice/language/python/init/copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ deploy:
choices:
- docker-compose
- kubernetes
default: kubernetes
default: docker-compose

_envops:
block_start_string: "{%"
Expand All @@ -45,3 +45,4 @@ _exclude:

_functions:
- "_utils.build_deploy_playbook"
- "_utils.build_docker_compose"
10 changes: 10 additions & 0 deletions project/init/copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ project_version:
type: str
help: What is the version of the project?
default: 0.1.0
project_deploy:
type: str
link:
docker-compose: "{{ template_registry }}/project-deploy-docker-compose.tar.gz"
kubernetes: "{{ template_registry }}/project-deploy-kubernetes.tar.gz"
help: What deploy system do you want to use?
choices:
- docker-compose
- kubernetes
default: docker-compose

_envops:
block_start_string: "{%"
Expand Down

0 comments on commit b1d2cf7

Please sign in to comment.