From 59026fe6532eed3bdc7c293f146d951eba22ddc8 Mon Sep 17 00:00:00 2001 From: "Ryan B. Harvey" Date: Fri, 26 Jul 2019 02:23:53 -0500 Subject: [PATCH 1/4] Split docker-compose to enable running without dev dependencies --- docker-compose.selenium_chrome.yml | 9 +++++++++ docker-compose.webpacker_dev.yml | 19 +++++++++++++++++++ docker-compose.yml | 21 --------------------- rails/Dockerfile | 2 +- 4 files changed, 29 insertions(+), 22 deletions(-) create mode 100644 docker-compose.selenium_chrome.yml create mode 100644 docker-compose.webpacker_dev.yml diff --git a/docker-compose.selenium_chrome.yml b/docker-compose.selenium_chrome.yml new file mode 100644 index 00000000..c12bf96a --- /dev/null +++ b/docker-compose.selenium_chrome.yml @@ -0,0 +1,9 @@ +version: '3' + +services: + selenium_chrome: + image: selenium/standalone-chrome-debug + logging: + driver: none + ports: + - "5900:5900" diff --git a/docker-compose.webpacker_dev.yml b/docker-compose.webpacker_dev.yml new file mode 100644 index 00000000..c822d0aa --- /dev/null +++ b/docker-compose.webpacker_dev.yml @@ -0,0 +1,19 @@ +version: '3' + +services: + webpacker_dev: + build: rails + command: ./bin/webpack-dev-server + ports: + - "3035:3035" + volumes: + - ./rails:/srv/coral + - gem_cache:/var/lib/ruby/gems + env_file: + - .env/development/database + - .env/development/web + environment: + - WEBPACKER_DEV_SERVER_HOST=0.0.0.0 + +volumes: + gem_cache: diff --git a/docker-compose.yml b/docker-compose.yml index 144cdb29..61050660 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -38,27 +38,6 @@ services: env_file: - .env/development/storage - webpacker_dev: - build: rails - command: ./bin/webpack-dev-server - ports: - - "3035:3035" - volumes: - - ./rails:/srv/coral - - gem_cache:/var/lib/ruby/gems - env_file: - - .env/development/database - - .env/development/web - environment: - - WEBPACKER_DEV_SERVER_HOST=0.0.0.0 - - selenium_chrome: - image: selenium/standalone-chrome-debug - logging: - driver: none - ports: - - "5900:5900" - redis: image: redis diff --git a/rails/Dockerfile b/rails/Dockerfile index 71562eab..21df314f 100644 --- a/rails/Dockerfile +++ b/rails/Dockerfile @@ -1,4 +1,4 @@ -from ruby:2.6.3-alpine +FROM ruby:2.6.3-alpine RUN set -ex && \ apk add --update build-base yarn nodejs postgresql-dev tzdata && \ From 7bda2a7102bc9b0880e6d0652d7bea32266bd888 Mon Sep 17 00:00:00 2001 From: "Ryan B. Harvey" Date: Fri, 26 Jul 2019 02:24:29 -0500 Subject: [PATCH 2/4] Add dependencies bootstrapping script --- scripts/bootstrap | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 scripts/bootstrap diff --git a/scripts/bootstrap b/scripts/bootstrap new file mode 100755 index 00000000..2432a46c --- /dev/null +++ b/scripts/bootstrap @@ -0,0 +1,56 @@ +#!/bin/bash + +# Get script directory +SOURCE="${BASH_SOURCE[0]}" +while [ -h "${SOURCE}" ]; do # resolve ${SOURCE} until the file is no longer a symlink + DIR="$( cd -P "$( dirname "${SOURCE}" )" >/dev/null 2>&1 && pwd )" + SOURCE="$(readlink "${SOURCE}")" + [[ ${SOURCE} != /* ]] && SOURCE="${DIR}/${SOURCE}" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +SCRIPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" >/dev/null 2>&1 && pwd )" + +# Check type of bash +UNAME_OUT="$(uname -s)" +case "${UNAME_OUT}" in + Linux*) RUNTIME="Linux";; + Darwin*) RUNTIME="macOS";; + CYGWIN*) RUNTIME="Cygwin";; + MINGW*) RUNTIME="MinGw";; + *) RUNTIME="UNKNOWN:${UNAME_OUT}" +esac +if [[ ${RUNTIME:0:8} = "UNKNOWN:" ]]; then + echo "Could not detect system runtime. Exiting." + exit 1 +fi +echo "Detected system runtime: ${RUNTIME}" + +# Check for docker installation +if [ ! -n $(which docker) ]; then + echo "Docker installation not found. Please install, and then run this script again." + echo "To install, see the docker installation documentation at:" + if [[ ${RUNTIME} = "Cygwin" ]]; then + echo "https://docs.docker.com/docker-for-windows/install/" + elif [[ ${RUNTIME} = "MinGw" ]]; then + echo "https://docs.docker.com/docker-for-windows/install/" + elif [[ ${RUNTIME} = "Mac" ]]; then + echo "https://docs.docker.com/docker-for-mac/install/" + else + echo "https://docs.docker.com/install/#server" + fi + exit 1 +else + echo "Found docker installation at: $(which docker)" +fi + +# Check for docker-compose installation +if [ ! -n $(which docker-compose) ]; then + echo "Docker Compose not found. On Linux systems, you may need to install compose separately." + echo "See install documentation at:" + echo "https://docs.docker.com/compose/install/" + exit 1 +else + echo "Found docker compose installation at: $(which docker-compose)" +fi + +echo "All Docker dependencies found. Ready to setup application components." +exit 0 From 9e4d6a06e8caa3a9d25bd999f06299c61766bb82 Mon Sep 17 00:00:00 2001 From: "Ryan B. Harvey" Date: Fri, 26 Jul 2019 02:24:44 -0500 Subject: [PATCH 3/4] Add app setup script --- scripts/setup | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 scripts/setup diff --git a/scripts/setup b/scripts/setup new file mode 100755 index 00000000..98264548 --- /dev/null +++ b/scripts/setup @@ -0,0 +1,56 @@ +#!/bin/bash + +# Get script directory +SOURCE="${BASH_SOURCE[0]}" +while [ -h "${SOURCE}" ]; do # resolve ${SOURCE} until the file is no longer a symlink + DIR="$( cd -P "$( dirname "${SOURCE}" )" >/dev/null 2>&1 && pwd )" + SOURCE="$(readlink "${SOURCE}")" + [[ ${SOURCE} != /* ]] && SOURCE="${DIR}/${SOURCE}" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +SCRIPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" >/dev/null 2>&1 && pwd )" + +# Ensure docker dependencies are available +${SCRIPT_DIR}/bootstrap +BOOTSTRAP_RESULT=$? +if [ ${BOOTSTRAP_RESULT} != 0 ]; then + echo "Error bootstrapping dependencies" + exit ${BOOTSTRAP_RESULT} +fi + +# Pull containers +echo "Pulling container images..." +docker-compose -f ${SCRIPT_DIR}/../docker-compose.yml pull +PULL_RESULT=$? +if [ ${PULL_RESULT} != 0 ]; then + echo "Error pulling container images for main compose file" + exit ${PULL_RESULT} +fi +docker-compose -f ${SCRIPT_DIR}/../docker-compose.webpacker_dev.yml pull +PULL_RESULT=$? +if [ ${PULL_RESULT} != 0 ]; then + echo "Error pulling container images for webpacker_dev compose file" + exit ${PULL_RESULT} +fi +docker-compose -f ${SCRIPT_DIR}/../docker-compose.selenium_chrome.yml pull +PULL_RESULT=$? +if [ ${PULL_RESULT} != 0 ]; then + echo "Error pulling container images for selenium_chrome" + exit ${PULL_RESULT} +fi +echo "Successfully pulled container images" + +# Build web and webpacker_dev +echo "Building containers" +CURRENT_DIR=$(pwd) +cd ${SCRIPT_DIR}/.. +docker-compose -f ${SCRIPT_DIR}/../docker-compose.yml -f ${SCRIPT_DIR}/../docker-compose.webpacker_dev.yml -f ${SCRIPT_DIR}/../docker-compose.selenium_chrome.yml build +BUILD_RESULT=$? +cd ${CURRENT_DIR} +if [ ${BUILD_RESULT} != 0 ]; then + echo "Error building containers" + exit ${BUILD_RESULT} +fi +echo "Successfully built containers" + +echo "Successfully setup application" +exit 0 From 006ece82f5f42ad024f7d458b112ffac7bf3c21c Mon Sep 17 00:00:00 2001 From: "Ryan B. Harvey" Date: Fri, 26 Jul 2019 02:25:10 -0500 Subject: [PATCH 4/4] Add script to run the app/server --- scripts/server | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 scripts/server diff --git a/scripts/server b/scripts/server new file mode 100755 index 00000000..32bc2e4f --- /dev/null +++ b/scripts/server @@ -0,0 +1,77 @@ +#!/bin/bash + +# Get script directory +SOURCE="${BASH_SOURCE[0]}" +while [ -h "${SOURCE}" ]; do # resolve ${SOURCE} until the file is no longer a symlink + DIR="$( cd -P "$( dirname "${SOURCE}" )" >/dev/null 2>&1 && pwd )" + SOURCE="$(readlink "${SOURCE}")" + [[ ${SOURCE} != /* ]] && SOURCE="${DIR}/${SOURCE}" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +SCRIPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" >/dev/null 2>&1 && pwd )" + +# Print usage when called +usage () { + echo "USAGE:" + echo " $0 [+webpacker_dev|+selenium_chrome|+dev]" + echo "PARAMETERS:" + echo " +webpacker_dev - include the webpacker_dev container when running" + echo " +selenium_chrome - include the selenium_chrome container when running" + echo " +dev - include all dev dependencies when running (includes both webpacker_dev and selenium_chrome)" +} + +# Process CLI arguments +PARAM1=$1 +PARAM2=$2 +if [[ ${PARAM1} = "help" ]]; then + usage + exit 0 +fi + +# Set flags +INCLUDE_WEBPACKER_DEV=0 +INCLUDE_SELENIUM_CHROME=0 +EXCLUDE_ALL_DEV=1 +if [[ ${PARAM1} = "+webpacker_dev" || ${PARAM2} = "+webpacker_dev" ]]; then + INCLUDE_WEBPACKER_DEV=1 + EXCLUDE_ALL_DEV=0 +fi +if [[ ${PARAM1} = "+selenium_chrome" || ${PARAM2} = "+selenium_chrome" ]]; then + INCLUDE_SELENIUM_CHROME=1 + EXCLUDE_ALL_DEV=0 +fi +if [[ ${PARAM1} = "+dev" ]]; then + INCLUDE_WEBPACKER_DEV=1 + INCLUDE_SELENIUM_CHROME=1 + EXCLUDE_ALL_DEV=0 +fi + +# Check dependencies/ensure setup +${SCRIPT_DIR}/setup +SETUP_RESULT=$? +echo "${SETUP_RESULT}" +if [ ${SETUP_RESULT} != 0 ]; then + echo "Error setting up app" + exit ${SETUP_RESULT} +fi + +# Construct command +CMD="docker-compose -f ${SCRIPT_DIR}/../docker-compose.yml" +if [ ${INCLUDE_WEBPACKER_DEV} = 1 ]; then + echo "Including webpacker_dev container..." + CMD="${CMD} -f ${SCRIPT_DIR}/../docker-compose.webpacker_dev.yml" +fi +if [ ${INCLUDE_SELENIUM_CHROME} = 1 ]; then + echo "Including selenium_chrome container..." + CMD="${CMD} -f ${SCRIPT_DIR}/../docker-compose.selenium_chrome.yml" +fi +if [ ${EXCLUDE_ALL_DEV} = 1 ]; then + echo "Excluding all dev dependencies..." +fi +CMD="${CMD} up -d" + +${CMD} +START_RESULT=$? +if [ ${START_RESULT} != 0 ]; then + echo "Error starting application" + exit ${START_RESULT} +fi