Skip to content

Commit

Permalink
feat(compose): compelete compose prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
abolfazl8131 committed Dec 3, 2024
1 parent 7c593ab commit 91a80bd
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
39 changes: 39 additions & 0 deletions app/directory_generators/compose_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os

project_name = "app/media/MyCompose"
compose_file_path = os.path.join(project_name, "docker-compose.yaml")

# Create project directories
os.makedirs(project_name, exist_ok=True)

# Create docker-compose.yaml
with open(compose_file_path, "w") as compose_file:
compose_file.write("version: '3'\n")
compose_file.write("services:\n")
compose_file.write(" web_server:\n")
compose_file.write(" image: nginx:latest\n")
compose_file.write(" volumes:\n")
compose_file.write(" - ./nginx/nginx.conf:/etc/nginx/nginx.conf\n")
compose_file.write(" depends_on:\n")
compose_file.write(" - string\n")
compose_file.write(" ports:\n")
compose_file.write(" - '80:80'\n")
compose_file.write(" environment:\n")
compose_file.write(" - foo=bar\n")
compose_file.write(" networks:\n")
compose_file.write(" - app_network\n")
compose_file.write(" monitoring_server:\n")
compose_file.write(" image: grafana:latest\n")
compose_file.write(" volumes:\n")
compose_file.write(" - ./nginx/nginx.conf:/etc/nginx/nginx.conf\n")
compose_file.write(" depends_on:\n")
compose_file.write(" - string\n")
compose_file.write(" ports:\n")
compose_file.write(" - '82:80'\n")
compose_file.write(" environment:\n")
compose_file.write(" - foo=bar\n")
compose_file.write(" networks:\n")
compose_file.write(" - app_network\n")
compose_file.write("networks:\n")
compose_file.write(" app_network:\n")
compose_file.write(" driver: bridge\n")
27 changes: 26 additions & 1 deletion app/media/MyCompose/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
version: '3'
services:
web_server:
image: nginx:latest
build:
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
depends_on:
- string
ports:
- '80:80'
environment:
- foo=bar
networks:
- app_network
monitoring_server:
image: grafana:latest
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
depends_on:
- string
ports:
- '82:80'
environment:
- foo=bar
networks:
- app_network
networks:
app_network:
driver: bridge
21 changes: 20 additions & 1 deletion app/template_generators/docker/compose.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
def docker_compose_generator(input):
compose_network = input.network.name
compose_services = input.services
services = [i.container_name for i in compose_services]
images = [{i.container_name:i.image_full} for i in compose_services]
Expand All @@ -13,13 +14,31 @@ def docker_compose_generator(input):
generate a python code (with out any ```python entry or additionals) with generates a docker-compose.yaml file in the directory 'app/media/MyCompose'
the docker-compose.yaml, must following there instructions:
the version must be = 3
set services following this list: {services}
set images to serivce following this dict : {images}
set volumes to service following this dict : {volumes}
set depends_on to service following this dict : {depends_on}
set ports to service following this dict : {ports}
set environment to service following this dict : {env}
set netwotks to service following this dict : {networks}
finally, at the end of docker-compose file, add following block:
```
networks:
{compose_network}:
driver: bridge
```
finally just give me a python code without any note that can generate a project folder with the
given schema without ```python entry. and we dont need any base directory in the python code.
the final ansible template must work very well without any error!
the python code you give me, must have structure like that:
import os
Expand Down

0 comments on commit 91a80bd

Please sign in to comment.