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

feat: allow multiple Postal instances to run on the same host #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
config/**/*
/docker-compose.*
worker-replicas
docker-project-name
config-dir-path
hooks/**/*
54 changes: 48 additions & 6 deletions bin/postal
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ ROOT_DIR=$( cd "$( dirname "${ORIGINAL_SCRIPT}" )/.." && pwd )
DEV_MODE="false"
GIT_PULL="true"
FORCE_VERSION=""
DEFAULT_DOCKER_PROJECT_NAME="postal"
DEFAULT_CONFIG_DIR_PATH="/opt/postal/config"

if command -v gsed &> /dev/null
then
Expand Down Expand Up @@ -66,11 +68,13 @@ run-docker-compose() {
set-postal-version $latest_version
fi

local docker_project_name=`get-docker-project-name`

if command -v docker-compose &> /dev/null
then
run "docker-compose -p postal $@"
run "docker-compose -p $docker_project_name $@"
else
run "docker compose -p postal $@"
run "docker compose -p $docker_project_name $@"
fi
}

Expand Down Expand Up @@ -102,6 +106,11 @@ set-postal-version() {
worker_replicas=1
fi

# Replace the config directory path
local config_dir_path=$(get-config-dir-path)
local escaped_config_dir_path=$(escape-sed-chars "$config_dir_path")
$SED -i "s/{{config-dir}}/$escaped_config_dir_path/" docker-compose.yml

# Replace the worker counter
$SED -i "s/{{worker-replicas}}/$worker_replicas/" docker-compose.yml

Expand All @@ -111,6 +120,34 @@ set-postal-version() {
call-hook "set-postal-version"
}

escape-sed-chars() {
local input="$1"

echo "$input" | $SED -e 's/[]\/$*.^|[]/\\&/g'
}

get-docker-project-name() {
if [ -f "docker-project-name" ]
then
local docker_project_name=$(cat docker-project-name | tr -d " \n")
else
local docker_project_name=$DEFAULT_DOCKER_PROJECT_NAME
fi

echo $docker_project_name
}

get-config-dir-path() {
if [ -f "config-dir-path" ]
then
local config_dir=$(cat config-dir-path | tr -d " \n")
else
local config_dir=$DEFAULT_CONFIG_DIR_PATH
fi

echo $config_dir
}

get-latest-postal-version() {

if ! command -v curl &> /dev/null
Expand Down Expand Up @@ -273,17 +310,22 @@ case "$1" in

call-hook "pre-bootstrap"

if [ "$output_path" == "" ]; then
output_path=/opt/postal/config
fi

if [ "$hostname" == "" ]; then
echo 'hostname is missing.'
echo
echo 'usage: ./bin/postal postal.mydomain.com [path/to/config]'
exit 1
fi

if [ "$output_path" == "" ]; then
output_path=$DEFAULT_CONFIG_DIR_PATH
fi

# Write the output path if it's not the default
if [ ! $output_path == $DEFAULT_CONFIG_DIR_PATH ]; then
echo $output_path > config-dir-path
fi

# Get the latest verison of Postal as the starting version for a
# new installation.
if [ ! $FORCE_VERSION == "" ]; then
Expand Down
12 changes: 6 additions & 6 deletions templates/docker-compose.v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
command: postal web-server
network_mode: host
volumes:
- /opt/postal/config:/config
- "{{config-dir}}:/config"
restart: unless-stopped

smtp:
Expand All @@ -15,31 +15,31 @@ services:
cap_add:
- NET_BIND_SERVICE
volumes:
- /opt/postal/config:/config
- "{{config-dir}}:/config"
restart: unless-stopped

worker:
image: ghcr.io/postalserver/postal:{{version}}
command: postal worker
network_mode: host
volumes:
- /opt/postal/config:/config
- "{{config-dir}}:/config"
restart: unless-stopped

cron:
image: ghcr.io/postalserver/postal:{{version}}
command: postal cron
network_mode: host
volumes:
- /opt/postal/config:/config
- "{{config-dir}}:/config"
restart: unless-stopped

requeuer:
image: ghcr.io/postalserver/postal:{{version}}
command: postal requeuer
network_mode: host
volumes:
- /opt/postal/config:/config
- "{{config-dir}}:/config"
restart: unless-stopped

runner:
Expand All @@ -48,4 +48,4 @@ services:
command: postal
network_mode: host
volumes:
- /opt/postal/config:/config
- "{{config-dir}}:/config"
8 changes: 4 additions & 4 deletions templates/docker-compose.v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
command: postal web-server
network_mode: host
volumes:
- /opt/postal/config:/config
- "{{config-dir}}:/config"
restart: unless-stopped

smtp:
Expand All @@ -15,15 +15,15 @@ services:
cap_add:
- NET_BIND_SERVICE
volumes:
- /opt/postal/config:/config
- "{{config-dir}}:/config"
restart: unless-stopped

worker:
image: ghcr.io/postalserver/postal:{{version}}
command: postal worker
network_mode: host
volumes:
- /opt/postal/config:/config
- "{{config-dir}}:/config"
restart: unless-stopped

runner:
Expand All @@ -32,4 +32,4 @@ services:
command: postal
network_mode: host
volumes:
- /opt/postal/config:/config
- "{{config-dir}}:/config"