Skip to content

Commit

Permalink
chore: fix misc issues with container generator scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanemachine committed Oct 6, 2023
1 parent 0258492 commit 9c7b6df
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
5 changes: 5 additions & 0 deletions support/containers/networks/compose.phoenix-expose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
services:
phoenix:
ports:
- "${PORT:?}:${PORT:?}"
5 changes: 5 additions & 0 deletions support/containers/networks/compose.postgres-expose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
services:
postgres:
ports:
- "5432:5432"
45 changes: 32 additions & 13 deletions support/scripts/systemd-container-service-file-generate
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
service_name="phoenix-todo-list"
service_file="${HOME}/systemd/user/${service_name}.service"
service_file="${HOME}/.config/systemd/user/${service_name}.service"

if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "This script generates a user-level systemd service file.
Expand All @@ -13,13 +13,19 @@ Optional arguments:
--podman - Use Podman instead of Docker.
--expose-phoenix - Expose the PHX_HOST port to the host environment
--postgres - Enables the use of a Postgres server container when running the service.
--expose-postgres - Expose Postgres port 5432 to the host environment
- Traefik-specific options:
--dev - Configures the service for a development environment (i.e. no HTTPS).
- If no option is selected, then 'dev' will be used by default.
--staging - Configures the service for a production environment (i.e. uses HTTPS).
--prod - Configures the service for a production environment (i.e. uses HTTPS).
--traefik-client - Configures the service to be used with Traefik.
Expand Down Expand Up @@ -65,10 +71,6 @@ while test $# -gt 0; do
# use docker instead of podman
use_podman=1
;;
--postgres)
# run a postgres server as part of the service
use_postgres=1
;;
--dev)
# configures traefik for use in a dev deployment (i.e. no HTTPS)
is_dev=1
Expand All @@ -81,6 +83,18 @@ while test $# -gt 0; do
# configures traefik for use in a production deployment (i.e. uses HTTPS)
is_prod=1
;;
--expose-phoenix)
# configure the service for use with traefik and start a traefik server
expose_phoenix=1
;;
--postgres)
# run a postgres server as part of the service
use_postgres=1
;;
--expose-postgres)
# configure the service for use with traefik and start a traefik server
expose_postgres=1
;;
--traefik-client)
# configure the service for use with traefik, but don't start a traefik server
use_traefik_client=1
Expand Down Expand Up @@ -130,7 +144,7 @@ else
use_docker=1 # use docker-specific options in the systemd service file
fi

# set deployment_environment (based on DEPLOYMENT_TYPE env var, or relevant flags)
# set deployment_environment (based on DEPLOYMENT_ENVIRONMENT env var, or relevant flags)
# shellcheck disable=SC2153
deployment_environment="$DEPLOYMENT_ENVIRONMENT" # use global env var by default
if [ "$is_dev" = 1 ]; then
Expand All @@ -149,18 +163,24 @@ fi
containers_to_run="-f compose.phoenix.yaml"

if [ "$use_traefik_client" = 1 ] || [ "$use_traefik_host" = 1 ]; then
if [ "$expose_phoenix" = 1 ]; then
printf "\033[33mYour configuration will expose the PHX_HOST port directly, while also proxying the service through Traefik. This is probably not necessary.\033[39m\n"
fi

containers_to_run="$containers_to_run -f networks/compose.phoenix-traefik.yaml -f compose.phoenix-config-traefik-${deployment_environment}.yaml"
elif [ "$expose_phoenix" = 1 ]; then
containers_to_run="$containers_to_run -f networks/compose.phoenix-expose.yaml"
else
containers_to_run="$containers_to_run -f networks/compose.phoenix-host.yaml"
printf "\033[33mNo host has been specified. You may not be able to connect to this service.\033[39m\n"
fi

# postgres
if [ "$use_postgres" = 1 ]; then
containers_to_run="$containers_to_run -f compose.phoenix-postgres.yaml -f compose.postgres.yaml"

if [ "$use_traefik_client" != 1 ] && [ "$use_traefik_host" != 1 ]; then
if [ "$expose_postgres" = 1 ]; then
# enable postgres host networking
containers_to_run="$containers_to_run -f networks/compose.postgres-host.yaml"
containers_to_run="$containers_to_run -f networks/compose.postgres-expose.yaml"
fi
fi

Expand All @@ -174,7 +194,7 @@ fi
if [ "$dry_run" = 1 ]; then
output_to=/dev/stdout
else
output_to="${HOME}/.config/systemd/user/${service_name}.service"
output_to="${service_file}"
fi

if [ "$dry_run" != 1 ]; then
Expand Down Expand Up @@ -232,9 +252,8 @@ Environment=AWS_SECRET=\"$AWS_SECRET\"
## sentry
Environment=SENTRY_DSN=\"$SENTRY_DSN\"
## traefik
Environment=TRAEFIK_DASHBOARD_FQDN=\"$TRAEFIK_DASHBOARD_FQDN\"
## traefik (used when running a Traefik host as part of this project's container service)
# Environment=TRAEFIK_DASHBOARD_FQDN=\"$TRAEFIK_DASHBOARD_FQDN\"
# LIFECYCLE #
ExecStartPre=$command_to_run down
Expand Down

0 comments on commit 9c7b6df

Please sign in to comment.