Skip to content
Draft
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
15 changes: 15 additions & 0 deletions docker-compose.selenium_chrome.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3'

services:
selenium_chrome:
image: selenium/standalone-chrome-debug
logging:
driver: none
ports:
- "5900:5900"
networks:
- coral_net

networks:
coral_net:
external: true
25 changes: 25 additions & 0 deletions docker-compose.webpacker_dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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:
- .docker-env/development/database
- .docker-env/development/web
environment:
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0
networks:
- coral_net

volumes:
gem_cache:

networks:
coral_net:
external: true
25 changes: 0 additions & 25 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,6 @@ services:
networks:
- coral_net

webpacker_dev:
build: rails
command: ./bin/webpack-dev-server
ports:
- "3035:3035"
volumes:
- ./rails:/srv/coral
- gem_cache:/var/lib/ruby/gems
env_file:
- .docker-env/development/database
- .docker-env/development/web
environment:
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0
networks:
- coral_net

selenium_chrome:
image: selenium/standalone-chrome-debug
logging:
driver: none
ports:
- "5900:5900"
networks:
- coral_net

redis:
image: redis
networks:
Expand Down
2 changes: 1 addition & 1 deletion rails/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 && \
Expand Down
2 changes: 1 addition & 1 deletion rails/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ gem "jbuilder", "~> 2.5"
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'bcrypt', '~> 3.1.13'

# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
Expand Down
8 changes: 4 additions & 4 deletions rails/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ default: &default
# For details on connection pooling, see Rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
# host: <%= ENV.fetch("DATABASE_HOST") { "localhost" } %>
# database: <%= ENV.fetch("POSTGRES_DB") %>
# username: <%= ENV.fetch("POSTGRES_USER") { "postgres" } %>
# password: <%= ENV.fetch("POSTGRES_PASS") %>
host: <%= ENV.fetch("DATABASE_HOST") { "localhost" } %>
database: <%= ENV.fetch("POSTGRES_DB") %>
username: <%= ENV.fetch("POSTGRES_USER") { "postgres" } %>
password: <%= ENV.fetch("POSTGRES_PASS") %>

development:
<<: *default
Expand Down
56 changes: 56 additions & 0 deletions scripts/bootstrap
Original file line number Diff line number Diff line change
@@ -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
77 changes: 77 additions & 0 deletions scripts/server
Original file line number Diff line number Diff line change
@@ -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
79 changes: 79 additions & 0 deletions scripts/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/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"

# Setup database
echo "Setting up database..."
docker-compose -f ${SCRIPT_DIR}/../docker-compose.yml run web bundle exec bin/rails db:setup
DB_SETUP_RESULT=$?
if [ ${DB_SETUP_RESULT} != 0 ]; then
echo "Error setting up database"
exit ${DB_SETUP_RESULT}
fi
echo "Migrating up database..."
docker-compose.yml run web bundle exec bin/rails db:migrate
DB_MIGRATE_RESULT=$?
if [ ${DB_MIGRATE_RESULT} != 0 ]; then
echo "Error migrating up database"
exit ${DB_MIGRATE_RESULT}
fi
echo "Seeding database..."
docker-compose.yml run web bundle exec bin/rails db:seed
DB_SEED_RESULT=$?
if [ ${DB_SEED_RESULT} != 0 ]; then
echo "Error migrating up database"
exit ${DB_SEED_RESULT}
fi

echo "Successfully setup application"
exit 0