first commit
This commit is contained in:
commit
2281e6eb41
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*.pyc
|
||||
venv/
|
11
Pulumi.yaml
Normal file
11
Pulumi.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
name: pulumi4
|
||||
description: pulumi
|
||||
runtime:
|
||||
name: python
|
||||
options:
|
||||
toolchain: pip
|
||||
virtualenv: venv
|
||||
config:
|
||||
pulumi:tags:
|
||||
value:
|
||||
pulumi:template: python
|
82
__main__.py
Normal file
82
__main__.py
Normal file
@ -0,0 +1,82 @@
|
||||
import pulumi
|
||||
import pulumi_docker as docker
|
||||
import json
|
||||
|
||||
# Load the configuration from the JSON file
|
||||
with open('config.json') as f:
|
||||
config_data = json.load(f)
|
||||
|
||||
# Create a Docker network
|
||||
network = docker.Network("testNetwork")
|
||||
|
||||
# Initialize the containers list
|
||||
containers = []
|
||||
|
||||
|
||||
# Initialize the URL dictionary for export
|
||||
urls = {}
|
||||
|
||||
# Create containers based on the configuration
|
||||
for container in config_data["containers"]:
|
||||
container_name = container["name"]
|
||||
container_envs = [f"{key}={value}" for key, value in container.get("env", {}).items()]
|
||||
|
||||
# Create the container
|
||||
docker_container = docker.Container(
|
||||
container_name,
|
||||
name=container_name,
|
||||
image=container["image"],
|
||||
envs=container_envs,
|
||||
ports=[docker.ContainerPortArgs(
|
||||
internal=port["internal"],
|
||||
external=port["external"]
|
||||
) for port in container["ports"]],
|
||||
network_mode=network.name,
|
||||
command=container.get("command", None) or container.get("entrypoint", None),
|
||||
##container.get("entrypoint", "/usr/local/bin/entrypoint.sh")
|
||||
|
||||
volumes=[docker.ContainerVolumeArgs(
|
||||
host_path=vol["host_path"],
|
||||
container_path=vol["container_path"]
|
||||
) for vol in container.get("volumes", [])]
|
||||
)
|
||||
containers.append(docker_container)
|
||||
|
||||
# Add the URLs for the container
|
||||
for port in container["ports"]:
|
||||
urls[f"{container_name}_url"] = f"http://localhost:{port['external']}"
|
||||
|
||||
# Scale Prometheus containers
|
||||
for i in range(config_data.get("prometheus_scale", 1)): # Default to 1 if not specified
|
||||
prometheus_instance = docker.Container(
|
||||
f"prometheus-instance-{i}",
|
||||
name=f"prometheus-{i}",
|
||||
image="prom/prometheus:latest",
|
||||
ports=[docker.ContainerPortArgs(internal=9090, external=9090 + i)],
|
||||
network_mode=network.name
|
||||
)
|
||||
containers.append(prometheus_instance)
|
||||
|
||||
# Add the Prometheus URLs
|
||||
urls[f"prometheus_{i}_url"] = f"http://localhost:{9090 + i}"
|
||||
|
||||
# Scale Fluentd containers
|
||||
fluentd_scale = config_data.get("fluentd_scale", 1) # Default to 1 if not specified
|
||||
|
||||
for i in range(fluentd_scale): # This will scale based on the value from config_data
|
||||
fluentd_instance = docker.Container(
|
||||
f"fluentd-instance-{i}",
|
||||
name=f"fluentd-{i}",
|
||||
image="fluent/fluentd:v1.14-1", # Corrected image name
|
||||
ports=[docker.ContainerPortArgs(internal=24224, external=24224 + i)], # Assign unique external port for each container
|
||||
network_mode=network.name
|
||||
)
|
||||
containers.append(fluentd_instance)
|
||||
|
||||
# Add the Fluentd URLs
|
||||
urls[f"fluentd_{i}_url"] = f"http://localhost:{24224 + i}"
|
||||
|
||||
# Export network and container details
|
||||
pulumi.export("network_name", network.name)
|
||||
pulumi.export("containers", [c.name for c in containers])
|
||||
pulumi.export("urls", urls)
|
51
config.json
Normal file
51
config.json
Normal file
@ -0,0 +1,51 @@
|
||||
{
|
||||
"containers": [
|
||||
{
|
||||
"name": "postgres",
|
||||
"image": "postgres:16.5",
|
||||
"env": {
|
||||
"POSTGRES_USER": "odoo",
|
||||
"POSTGRES_PASSWORD": "odoo",
|
||||
"POSTGRES_DB": "postgres",
|
||||
"POSTGRES_HOST_AUTH_METHOD": "trust"
|
||||
},
|
||||
"ports": [
|
||||
{"internal": 5432, "external": 5432}
|
||||
],
|
||||
"volumes": [
|
||||
{"host_path": "/local/path/postgresql/data", "container_path": "/var/lib/postgresql/data"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "odoo",
|
||||
"image": "odoo:latest",
|
||||
"env": {
|
||||
"HOST": "postgres",
|
||||
"USER": "odoo",
|
||||
"PASSWORD": "odoo",
|
||||
"DATABASE": "postgres",
|
||||
"ODOO_PASSWORD": "admin"
|
||||
},
|
||||
"ports": [
|
||||
{"internal": 8069, "external": 8069}
|
||||
],
|
||||
"command": [
|
||||
"/bin/bash", "-c", "until pg_isready -h postgres -U odoo; do echo 'Waiting for PostgreSQL...'; sleep 2; done; odoo -i base"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "grafana",
|
||||
"image": "grafana/grafana:latest",
|
||||
"env": {
|
||||
"GF_SECURITY_ADMIN_PASSWORD": "grafana_pwd",
|
||||
"GF_DATASOURCES_PROMETHEUS_URL": "http://prometheus:9090"
|
||||
},
|
||||
"ports": [
|
||||
{"internal": 3000, "external": 3000}
|
||||
]
|
||||
}
|
||||
],
|
||||
"prometheus_scale": 2,
|
||||
"fluentd_scale": 2
|
||||
}
|
||||
|
6
entrypoint.sh
Normal file
6
entrypoint.sh
Normal file
@ -0,0 +1,6 @@
|
||||
# Wait for PostgreSQL to be ready
|
||||
until pg_isready -h $HOST -U $USER; do
|
||||
echo "Waiting for PostgreSQL..."
|
||||
sleep 2
|
||||
done
|
||||
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
pulumi>=3.0.0,<4.0.0
|
Loading…
Reference in New Issue
Block a user