Skip to content

Commit

Permalink
feat: compose
Browse files Browse the repository at this point in the history
  • Loading branch information
sanriodev committed Jan 9, 2025
1 parent 4239e3f commit 25ed47f
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 15 deletions.
29 changes: 29 additions & 0 deletions .env.compose.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
##############################
# 1. COMPOSE PROJECT PREFIX
# ############################
# necessary such that container
# names do not clash with
# those from other projects
COMPOSE_PROJECT_NAME=energy-householder

# define which services to boot up!
# for prod you probably want
# "infra_full,project_full" here,
# for staging "project_full" and for
# local dev purposes just the single
# services
COMPOSE_PROFILES=infra_full,project_full

# ############################
# 2. INFRASTRUCTURE CONFIGS
# ############################
# containers should know which
# docker networks to join ..
# see: `docker network ls`
HOST_NET_MONGO=XXX_MONGO_NETWORK_XXX

# ############################
# 3. HOST URL FOR PROJECT
# ############################
TRAEFIK_HOST_URL=XXX_TRAEFIK_HOST_URL_XXX

26 changes: 26 additions & 0 deletions compose.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

if [ -e $ENV ]; then
ENV_FILE=".env"
else
ENV_FILE=".env.compose.$ENV"
fi

set -o allexport
. $ENV_FILE
set +o allexport

cat << EOF
******************************
* EMATRIC / PROJECT LAUNCHER *
******************************
Launched Profiles: ${COMPOSE_PROFILES}
EOF


if [ -e $ENV ]; then
ENV=prod
fi

docker compose --env-file $ENV_FILE -f compose.base.yml -f compose.$ENV.yml $@
10 changes: 0 additions & 10 deletions deploy.sh

This file was deleted.

52 changes: 47 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,58 @@
version: '3'
services:
energy-householder:
hostname: energy-householder
backend:
hostname: backend
pull_policy: always
image: ghcr.io/sanriodev/energy-householder:dev
image: ghcr.io/sanriodev/energy-housholder:dev
volumes:
- .env:/home/node/.env.prod
- .env.prod:/home/node/.env.prod
environment:
NODE_ENV: prod
ports:
- 3000:3000
restart: unless-stopped
labels:
- "traefik.enable=true"
- "traefik.http.routers.$COMPOSE_PROJECT_NAME-backend-api.tls=true"
- "traefik.http.routers.$COMPOSE_PROJECT_NAME-backend-api.entrypoints=websecure"
- "traefik.http.routers.$COMPOSE_PROJECT_NAME-backend-api.rule=(Host(`$TRAEFIK_HOST_URL`)) && PathPrefix(`/api`)"
- "traefik.http.routers.$COMPOSE_PROJECT_NAME-backend.tls=true"
- "traefik.http.routers.$COMPOSE_PROJECT_NAME-backend.rule=(Host(`$TRAEFIK_HOST_URL`)) && PathPrefix(`/service/backend`)"
- "traefik.http.middlewares.$COMPOSE_PROJECT_NAME-backend-strip.stripprefixregex.regex=/service/backend"
- "traefik.http.routers.$COMPOSE_PROJECT_NAME-backend.middlewares=$COMPOSE_PROJECT_NAME-backend-strip@docker"
- "traefik.http.services.$COMPOSE_PROJECT_NAME-backend.loadbalancer.server.port=3000"
- "traefik.http.services.$COMPOSE_PROJECT_NAME-backend-api.loadbalancer.server.port=3000"
- "traefik.http.routers.$COMPOSE_PROJECT_NAME-backend.service=$COMPOSE_PROJECT_NAME-backend@docker"
- "traefik.http.routers.$COMPOSE_PROJECT_NAME-backend-api.service=$COMPOSE_PROJECT_NAME-backend-api@docker"
- "traefik.http.routers.$COMPOSE_PROJECT_NAME-backend-wss.tls=true"
- "traefik.http.routers.$COMPOSE_PROJECT_NAME-backend-wss.entrypoints=websecure"
- "traefik.http.routers.$COMPOSE_PROJECT_NAME-backend-wss.rule=(Host(`$TRAEFIK_HOST_URL`)) && PathPrefix(`/wss`)"
- "traefik.http.middlewares.$COMPOSE_PROJECT_NAME-backend-wss-strip.stripprefixregex.regex=/wss"
- "traefik.http.routers.$COMPOSE_PROJECT_NAME-backend-wss.middlewares=$COMPOSE_PROJECT_NAME-backend-wss-strip@docker"
- "traefik.http.services.$COMPOSE_PROJECT_NAME-backend-wss.loadbalancer.server.port=1234"
- "traefik.http.routers.$COMPOSE_PROJECT_NAME-backend-wss.service=$COMPOSE_PROJECT_NAME-backend-wss@docker"
profiles:
- project_full
- backend
networks:
- mongo

frontend:
image: ghcr.io/sanriodev/energy-householder-angular:dev
restart: unless-stopped
labels:
- "traefik.enable=true"
- "traefik.http.routers.$COMPOSE_PROJECT_NAME-frontend.tls=true"
- "traefik.http.routers.$COMPOSE_PROJECT_NAME-frontend.entrypoints=websecure"
- "traefik.http.routers.$COMPOSE_PROJECT_NAME-frontend.rule=(Host(`$TRAEFIK_HOST_URL`))"
- "traefik.http.services.$COMPOSE_PROJECT_NAME-frontend.loadbalancer.server.port=80"
volumes: []
networks:
- backbone
profiles:
- project_full
- frontend

mongo:
image: mongo:6.0.3
hostname: mongo
Expand Down Expand Up @@ -42,7 +81,10 @@ services:
restart: unless-stopped
networks:
- mongo
profiles:
- infra_full
- mongo

networks:
mongo:
name: mongo
name: $HOST_NET_MONGO

0 comments on commit 25ed47f

Please sign in to comment.