From 7fbecb172851b78e16e7d1a318bea86830f83cdb Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 26 Oct 2021 22:38:58 +0100 Subject: [PATCH] build(docker): make Compose file more configurable Allow for configuring volume mounts, ports, the site URL, and volume mounts within the Docker Compose file using environment variables from within and .env file. This means that the same Docker Compose file could be used to generate and serve the site locally using an anonymous volume, as well as generate a one-time build into a local directory to be served by Apache or Nginx on production. --- .env | 3 --- .env.example | 29 +++++++++++++++++++++++++++++ .gitignore | 1 + docker-compose.yaml | 32 +++++++++----------------------- 4 files changed, 39 insertions(+), 26 deletions(-) delete mode 100644 .env create mode 100644 .env.example diff --git a/.env b/.env deleted file mode 100644 index 0244590b..00000000 --- a/.env +++ /dev/null @@ -1,3 +0,0 @@ -COMPOSE_PROJECT_NAME=oliverdavies-uk - -DOCKER_WEB_PORT_FORWARD=80 diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..f7707ba1 --- /dev/null +++ b/.env.example @@ -0,0 +1,29 @@ +COMPOSE_PROJECT_NAME=oliverdavies-uk + +# The volume to store the generated output files. +# +# For development, an anonymous volume should be sufficient as the generated +# files don't need to be accessible locally. +# +# For production, you may want to output the files into a directory so that +# they can be served by a web server like Apache or Nginx. +#DOCKER_OUTPUT_VOLUME=./output_dev:/app/output_dev +#DOCKER_OUTPUT_VOLUME=./output_prod:/app/output_prod +DOCKER_OUTPUT_VOLUME=/app/output_dev + +# The environment to generate the site for (e.g. dev or prod). +#SCULPIN_ENV=prod +SCULPIN_ENV=dev + +# The port on which to serve the site if the --server option is specified. +#SCULPIN_PORT=80 +SCULPIN_PORT=8000 + +# The default URL to use if one hasn't been specified in the environment's +# configuration file. +#SCULPIN_URL=https://example.com +SCULPIN_URL=http://localhost + +# Any additional arguments to pass to the "sculpin generate" command. +#SCULPIN_GENERATE_ARGS= +SCULPIN_GENERATE_ARGS="--server --watch" diff --git a/.gitignore b/.gitignore index 30428fde..525a7b96 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /output_*/ /source/build/ /vendor/ +/.env /.phpunit.cache diff --git a/docker-compose.yaml b/docker-compose.yaml index 30458085..57444b87 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,34 +1,20 @@ -version: '2.4' - services: - proxy: - image: nginxproxy/nginx-proxy:alpine - volumes: - - /var/run/docker.sock:/tmp/docker.sock:ro - ports: - - "${DOCKER_WEB_PORT_FORWARD:-80}:80" - app: build: context: . dockerfile: tools/docker/images/Dockerfile target: app - expose: - - 80 - command: - - generate - - --server - - --watch - - --port - - '80' - - --url - - http://oliverdavies.localhost + command: generate --port "${SCULPIN_PORT:-80}" --url "${SCULPIN_URL:-http://localhost}" --env "${SCULPIN_ENV:-dev}" "${SCULPIN_GENERATE_ARGS}" volumes: - assets:/app/source/build - - /app/output_dev - .:/app - environment: - VIRTUAL_HOST: oliverdavies.localhost + - "${DOCKER_OUTPUT_VOLUME:-./output_prod:/app/output_prod}" + ports: + - "${SCULPIN_PORT:-80}:${SCULPIN_PORT:-80}" + env_file: + - .env + depends_on: + - assets assets: image: node:14 @@ -50,4 +36,4 @@ services: - assets-watch volumes: - assets: + assets: {}