Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Add support for configurable ports in Docker Compose #46 #52

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ The following services are exposed:
- There is a default namespace reserved for developers to specify default secrets for all the PS. Secrets defined under `project/default-dev-secrets` are used if `project/feature-branch` secret path is empty.
- If the default namespace is not configured as well, Sarthi automatically tries to find `sample.env`, `env.sample`, `.env.sample` and similar sample env files in the root directory and loads those sample environment variables to both `default-dev-secrets` and `project/feature-branch`

### Modifying docker-compose.yml

1. There is a python script for modifying the docker compose file.

### Tips 💡

1. Use `docker-compose's` service discovery to connect within the same services in your projects.
Expand Down
95 changes: 95 additions & 0 deletions docker-compose-modified.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
services:
grafana:
depends_on:
- loki
image: grafana/grafana:10.1.10-ubuntu
ports:
- ${PORT_GRAFANA:-3000}:3000
restart: always
volumes:
- grafana:/var/lib/grafana
- ./logging-config/grafana/dashboards:/etc/grafana/provisioning/dashboards
- ./logging-config/grafana/datasources:/etc/grafana/provisioning/datasources
loki:
command: -config.file=/etc/loki/loki-config.yaml
depends_on:
- promtail
image: grafana/loki:2.9.5
ports:
- ${PORT_LOKI:-3100}:3100
restart: always
volumes:
- ./logging-config/loki:/etc/loki
nginx:
container_name: sarthi_nginx
depends_on:
- portainer
- vault
- sarthi
- grafana
extra_hosts:
- host.docker.internal:host-gateway
image: nginx:1.26.0
ports:
- ${PORT_NGINX:-80}:80
restart: always
volumes:
- ./nginx-confs:/etc/nginx/conf.d
- ./sarthi.conf:/etc/nginx/conf.d/sarthi.conf
portainer:
image: portainer/portainer-ce:2.20.2
restart: unless-stopped
volumes:
- portainer_data:/data
- /var/run/docker.sock:/var/run/docker.sock
promtail:
command: -config.file=/etc/promtail/promtail-config.yaml
image: grafana/promtail:main-8978ecf
restart: always
volumes:
- /var/log:/var/log
- ./logging-config/promtail:/etc/promtail
sarthi:
build: .
depends_on:
- vault
environment:
DEPLOYMENTS_MOUNT_DIR: ${DEPLOYMENTS_MOUNT_DIR}
DOMAIN_NAME: ${DOMAIN_NAME:-localhost}
ENV: ${ENV:-local}
NGINX_PROXY_CONF_LOCATION: ${NGINX_PROXY_CONF_LOCATION}
SECRET_TEXT: ${SECRET_TEXT}
VAULT_BASE_URL: ${VAULT_BASE_URL:-http://vault:8200}
VAULT_TOKEN: ${VAULT_TOKEN}
extra_hosts:
- host.docker.internal:host-gateway
restart: always
volumes:
- ./deployments:${DEPLOYMENTS_MOUNT_DIR:-/deployments}
- ./nginx-confs:${NGINX_PROXY_CONF_LOCATION:-/nginx-confs}
- /var/run/docker.sock:/var/run/docker.sock
vault:
cap_add:
- IPC_LOCK
command: vault server -config=/vault/config/vault.json
environment:
VAULT_ADDR: http://0.0.0.0:8200
VAULT_ADDRESS: http://0.0.0.0:8200
VAULT_API_ADDR: http://0.0.0.0:8200
healthcheck:
interval: 10s
retries: 3
test:
- CMD-SHELL
- wget --spider http://127.0.0.1:8200/v1/sys/health || exit 1
timeout: 5s
image: hashicorp/vault:1.16
restart: always
volumes:
- ./vault/vault.json:/vault/config/vault.json
- vault-secrets:/vault/file
version: "3"
volumes:
grafana: null
portainer_data: null
vault-secrets: null
9 changes: 4 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ services:
nginx:
image: nginx:1.26.0
restart: always
# container name is used internally in code - don't change it
container_name: sarthi_nginx
ports:
- "80:80"
- "${PORT_NGINX:-80}:80" # Modified: Port number made variable
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
Expand All @@ -23,8 +22,6 @@ services:
build: .
restart: always
volumes:
# hack to bypass file resource sharing error
# not tested and no support for windows server 💩
- ./deployments:${DEPLOYMENTS_MOUNT_DIR:-/deployments}
- ./nginx-confs:${NGINX_PROXY_CONF_LOCATION:-/nginx-confs}
- /var/run/docker.sock:/var/run/docker.sock
Expand All @@ -45,7 +42,7 @@ services:
image: grafana/loki:2.9.5
restart: always
ports:
- 127.0.0.1:3100:3100
- "${PORT_LOKI:-3100}:3100" # Modified: Port number made variable
volumes:
- ./logging-config/loki:/etc/loki
command: -config.file=/etc/loki/loki-config.yaml
Expand All @@ -63,6 +60,8 @@ services:
grafana:
image: grafana/grafana:10.1.10-ubuntu
restart: always
ports:
- "${PORT_GRAFANA:-3000}:3000" # Modified: Port number made variable
volumes:
- grafana:/var/lib/grafana
- ./logging-config/grafana/dashboards:/etc/grafana/provisioning/dashboards
Expand Down
26 changes: 26 additions & 0 deletions modify_compose.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import yaml


def modify_compose(compose_file_path):
# Load the Docker Compose file
with open(compose_file_path, "r") as file:
compose_data = yaml.safe_load(file)

# Perform modifications here
# Example :
# compose_data['services']['web']['ports'] = ["8000:80"]
# For example, you can add or update services, adjust configurations, etc.

# Save the modified Docker Compose file
modified_compose_path = compose_file_path.replace(".yml", "-modified.yml")
with open(modified_compose_path, "w") as file:
yaml.dump(compose_data, file)

print(f"Modified Docker Compose file saved to: {modified_compose_path}")


if __name__ == "__main__":
compose_file_path = (
"docker-compose.yml" # Specify the path to your Docker Compose file
)
modify_compose(compose_file_path)
195 changes: 195 additions & 0 deletions processed-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
name: sarthi
services:
grafana:
depends_on:
loki:
condition: service_started
image: grafana/grafana:10.1.10-ubuntu
networks:
default: null
ports:
- mode: ingress
target: 3000
published: "3000"
protocol: tcp
restart: always
volumes:
- type: volume
source: grafana
target: /var/lib/grafana
volume: {}
- type: bind
source: /Users/gauravjisrivastava/Desktop/sarthi/logging-config/grafana/dashboards
target: /etc/grafana/provisioning/dashboards
bind:
create_host_path: true
- type: bind
source: /Users/gauravjisrivastava/Desktop/sarthi/logging-config/grafana/datasources
target: /etc/grafana/provisioning/datasources
bind:
create_host_path: true
loki:
command:
- -config.file=/etc/loki/loki-config.yaml
depends_on:
promtail:
condition: service_started
image: grafana/loki:2.9.5
networks:
default: null
ports:
- mode: ingress
target: 3100
published: "3100"
protocol: tcp
restart: always
volumes:
- type: bind
source: /Users/gauravjisrivastava/Desktop/sarthi/logging-config/loki
target: /etc/loki
bind:
create_host_path: true
nginx:
container_name: sarthi_nginx
depends_on:
grafana:
condition: service_started
portainer:
condition: service_started
sarthi:
condition: service_started
vault:
condition: service_started
extra_hosts:
host.docker.internal: host-gateway
image: nginx:1.26.0
networks:
default: null
ports:
- mode: ingress
target: 80
published: "80"
protocol: tcp
restart: always
volumes:
- type: bind
source: /Users/gauravjisrivastava/Desktop/sarthi/nginx-confs
target: /etc/nginx/conf.d
bind:
create_host_path: true
- type: bind
source: /Users/gauravjisrivastava/Desktop/sarthi/sarthi.conf
target: /etc/nginx/conf.d/sarthi.conf
bind:
create_host_path: true
portainer:
image: portainer/portainer-ce:2.20.2
networks:
default: null
restart: unless-stopped
volumes:
- type: volume
source: portainer_data
target: /data
volume: {}
- type: bind
source: /var/run/docker.sock
target: /var/run/docker.sock
bind:
create_host_path: true
promtail:
command:
- -config.file=/etc/promtail/promtail-config.yaml
image: grafana/promtail:main-8978ecf
networks:
default: null
restart: always
volumes:
- type: bind
source: /var/log
target: /var/log
bind:
create_host_path: true
- type: bind
source: /Users/gauravjisrivastava/Desktop/sarthi/logging-config/promtail
target: /etc/promtail
bind:
create_host_path: true
sarthi:
build:
context: /Users/gauravjisrivastava/Desktop/sarthi
dockerfile: Dockerfile
depends_on:
vault:
condition: service_started
environment:
DEPLOYMENTS_MOUNT_DIR: your_value
DOMAIN_NAME: localhost
ENV: local
NGINX_PROXY_CONF_LOCATION: your_value
SECRET_TEXT: your_value
VAULT_BASE_URL: http://vault:8200
VAULT_TOKEN: your_value
extra_hosts:
host.docker.internal: host-gateway
networks:
default: null
restart: always
volumes:
- type: bind
source: /Users/gauravjisrivastava/Desktop/sarthi/deployments
target: your_value
bind:
create_host_path: true
- type: bind
source: /Users/gauravjisrivastava/Desktop/sarthi/nginx-confs
target: your_value
bind:
create_host_path: true
- type: bind
source: /var/run/docker.sock
target: /var/run/docker.sock
bind:
create_host_path: true
vault:
cap_add:
- IPC_LOCK
command:
- vault
- server
- -config=/vault/config/vault.json
environment:
VAULT_ADDR: http://0.0.0.0:8200
VAULT_ADDRESS: http://0.0.0.0:8200
VAULT_API_ADDR: http://0.0.0.0:8200
healthcheck:
test:
- CMD-SHELL
- wget --spider http://127.0.0.1:8200/v1/sys/health || exit 1
timeout: 5s
interval: 10s
retries: 3
image: hashicorp/vault:1.16
networks:
default: null
restart: always
volumes:
- type: bind
source: /Users/gauravjisrivastava/Desktop/sarthi/vault/vault.json
target: /vault/config/vault.json
bind:
create_host_path: true
- type: volume
source: vault-secrets
target: /vault/file
volume: {}
networks:
default:
name: sarthi_default
volumes:
grafana:
name: sarthi_grafana
portainer_data:
name: sarthi_portainer_data
vault-secrets:
name: sarthi_vault-secrets
Loading