diff --git a/support/containers/networks/compose.phoenix-expose.yaml b/support/containers/networks/compose.phoenix-expose.yaml new file mode 100644 index 0000000..e4c4924 --- /dev/null +++ b/support/containers/networks/compose.phoenix-expose.yaml @@ -0,0 +1,5 @@ +--- +services: + phoenix: + ports: + - "${PORT:?}:${PORT:?}" diff --git a/support/containers/networks/compose.postgres-expose.yaml b/support/containers/networks/compose.postgres-expose.yaml new file mode 100644 index 0000000..a006ad8 --- /dev/null +++ b/support/containers/networks/compose.postgres-expose.yaml @@ -0,0 +1,5 @@ +--- +services: + postgres: + ports: + - "5432:5432" diff --git a/support/scripts/systemd-container-service-file-generate b/support/scripts/systemd-container-service-file-generate index c9ffb5e..9472ef0 100755 --- a/support/scripts/systemd-container-service-file-generate +++ b/support/scripts/systemd-container-service-file-generate @@ -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. @@ -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. @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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