Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
development Docker Compose file complete (+4 squashed commits)
Browse files Browse the repository at this point in the history
Squashed commits:
[b7b3f74] close but no cigar
[0c5633a] figuring out the separation between build and run
[3b49ae0] config and compose
[91adc3b] use absolute path on swagger docs, rename DB to production
  • Loading branch information
jakevose committed Jun 15, 2016
1 parent 95e5178 commit b912363
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -11,5 +11,6 @@ tmp/
data/*
.env
public/swagger_docs/
public/assets/
.ruby-gemset
coverage/
17 changes: 17 additions & 0 deletions Dockerfile
@@ -0,0 +1,17 @@
FROM ctac/base-ruby:2.1

ENV APP_HOME /var/app/social_media

RUN mkdir /var/app && mkdir $APP_HOME
WORKDIR $APP_HOME

RUN apt-get update && apt-get install git -y --no-install-recommends

ADD Gemfile* $APP_HOME/

ARG RAILS_ENV

RUN bundle install

ADD . $APP_HOME
RUN bundle exec rake assets:precompile
2 changes: 1 addition & 1 deletion app/views/public/swagger/index.html.erb
Expand Up @@ -66,7 +66,7 @@
<script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
url: "https://<%= request.host_with_port %>/swagger_docs/api-docs.json",
url: "<%= ENV['REGISTRY_HOSTNAME'] %>/swagger_docs/api-docs.json",
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
onComplete: function(swaggerApi, swaggerUi){
Expand Down
10 changes: 9 additions & 1 deletion config/database.yml
Expand Up @@ -6,6 +6,10 @@ default: &default
development:
<<: *default
database: ringsail_development
username: root
password:
host: db

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
Expand All @@ -15,4 +19,8 @@ test:

production:
<<: *default
database: ringsail_development
host: <%= ENV['REGISTRY_DB_HOST'] %>
port: <%= ENV['REGISTRY_DB_PORT'] %>
database: <%= ENV['REGISTRY_DB_NAME'] %>
username: <%= ENV['REGISTRY_DB_USER'] %>
password: <%= ENV['REGISTRY_DB_PASS'] %>
10 changes: 5 additions & 5 deletions db/schema.rb
Expand Up @@ -141,7 +141,7 @@

create_table "mobile_app_versions", force: :cascade do |t|
t.integer "mobile_app_id", limit: 4
t.string "store_url", limit: 255
t.text "store_url", limit: 65535
t.string "platform", limit: 255
t.string "version_number", limit: 255
t.datetime "publish_date"
Expand All @@ -158,7 +158,7 @@
add_index "mobile_app_versions", ["platform"], name: "index_mobile_app_versions_on_platform", using: :btree

create_table "mobile_apps", force: :cascade do |t|
t.string "name", limit: 255
t.text "name", limit: 65535
t.text "short_description", limit: 65535
t.text "long_description", limit: 65535
t.text "icon_url", limit: 65535
Expand Down Expand Up @@ -232,7 +232,7 @@
add_index "outlets", ["service"], name: "index_outlets_on_service", using: :btree

create_table "rails_admin_histories", force: :cascade do |t|
t.text "message", limit: 16777215
t.text "message", limit: 65535
t.string "username", limit: 255
t.integer "item", limit: 4
t.string "table", limit: 255
Expand Down Expand Up @@ -274,9 +274,9 @@
end

create_table "users", force: :cascade do |t|
t.string "email", limit: 255, default: "", null: false
t.string "email", limit: 255
t.datetime "remember_created_at"
t.integer "sign_in_count", limit: 4, default: 0
t.integer "sign_in_count", limit: 4
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip", limit: 255
Expand Down
1 change: 0 additions & 1 deletion db/seeds.rb
@@ -1,5 +1,4 @@
PublicActivity.enabled = false
DatabaseCleaner.clean_with :truncation

AGENCIES_NUM = 3
USERS_NUM = 100 #users will always make a minimum of 4 (one for each role)
Expand Down
2 changes: 2 additions & 0 deletions development.sh
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
./wait-for-it.sh db:3306 -- bundle exec rake db:create db:migrate services:load db:seed swagger:docs && bundle exec rails s --port 80 --binding '0.0.0.0'
40 changes: 40 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,40 @@
version: '2'
services:
db:
image: mysql:5.6
ports:
- "3306:3306"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
web:
build:
context: .
dockerfile: Dockerfile
args:
# build-time ENV parameters
RAILS_ENV: development
depends_on:
- db
command: ./development.sh
env_file: ./env
ports:
- "80:80"
environment:
# runtime ENV parameters4
RAILS_ENV: development
REGISTRY_RAILS_COOKIE_TOKEN: 8db388d70170c0ec9dedf836b5c8060c1a871b1abc2487e50ee5111be20f5740bc1aad2a2f39fb0dff88bd849db14170b96cf6f70f84cee0526920f1bd4bac25
REGISTRY_HOSTNAME: http://spoofedapp.com
REGISTRY_API_HOST: http://spoofedapp.com
volumes:
- .:/var/app/social_media
#
# - ./etc/nginx/conf.d:/etc/nginx/conf.d:ro
# - ./etc/nginx/certs:/etc/nginx/certs:ro
# - ./etc/php-fpm.d/zz-www.conf:/usr/local/etc/php-fpm.d/zz-www.conf:ro
# - ./etc/php/conf.d/zz-php.ini:/usr/local/etc/php/conf.d/zz-php.ini:ro
# - ./apps/gsa-cmp-drupal:/var/www/gsa-cmp-drupal
# - ./apps/html:/var/www/html
# - ./apps/etl-migration:/var/www/etl-migration
#- ./log/php_error.log:/var/log/php_error.log
#- ./log/php_access.log:/var/log/php_access.log
#- ./log/php_slow.log:/var/log/php_slow.log
15 changes: 15 additions & 0 deletions env
@@ -0,0 +1,15 @@
REGISTRY_EMAIL_SERVER='smtp.gmail.com'
REGISTRY_EMAIL_PORT='587'
REGISTRY_EMAIL_DOMAIN='gmail.com'
REGISTRY_EMAIL_USER='test@gmail.com'
REGISTRY_EMAIL_PASS='testpassword'
REGISTRY_RAILS_COOKIE_TOKEN='at least 30 random hex digits'
REGISTRY_USER_GROUP='AGY-GSA-OCSIT-APPS.USERS'
REGISTRY_ADMIN_GROUP='AGY-GSA-OCSIT-APPS.APPADMINS'
REGISTRY_HOSTNAME='http://localhost:3000'
REGISTRY_API_HOST='http://localhost:3000'
REGISTRY_DB_NAME='ringsail_development'
REGISTRY_DB_HOST='localhost'
REGISTRY_DB_PORT='3306'
REGISTRY_DB_USER='root'
REGISTRY_DB_PASS=''
161 changes: 161 additions & 0 deletions wait-for-it.sh
@@ -0,0 +1,161 @@
#!/usr/bin/env bash
# Use this script to test if a given TCP host/port are available

cmdname=$(basename $0)

echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }

usage()
{
cat << USAGE >&2
Usage:
$cmdname host:port [-s] [-t timeout] [-- command args]
-h HOST | --host=HOST Host or IP under test
-p PORT | --port=PORT TCP port under test
Alternatively, you specify the host and port as host:port
-s | --strict Only execute subcommand if the test succeeds
-q | --quiet Don't output any status messages
-t TIMEOUT | --timeout=TIMEOUT
Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
USAGE
exit 1
}

wait_for()
{
if [[ $TIMEOUT -gt 0 ]]; then
echoerr "$cmdname: waiting $TIMEOUT seconds for $HOST:$PORT"
else
echoerr "$cmdname: waiting for $HOST:$PORT without a timeout"
fi
start_ts=$(date +%s)
while :
do
(echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1
result=$?
if [[ $result -eq 0 ]]; then
end_ts=$(date +%s)
echoerr "$cmdname: $HOST:$PORT is available after $((end_ts - start_ts)) seconds"
break
fi
sleep 1
done
return $result
}

wait_for_wrapper()
{
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
if [[ $QUIET -eq 1 ]]; then
timeout $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
else
timeout $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
fi
PID=$!
trap "kill -INT -$PID" INT
wait $PID
RESULT=$?
if [[ $RESULT -ne 0 ]]; then
echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT"
fi
return $RESULT
}

# process arguments
while [[ $# -gt 0 ]]
do
case "$1" in
*:* )
hostport=(${1//:/ })
HOST=${hostport[0]}
PORT=${hostport[1]}
shift 1
;;
--child)
CHILD=1
shift 1
;;
-q | --quiet)
QUIET=1
shift 1
;;
-s | --strict)
STRICT=1
shift 1
;;
-h)
HOST="$2"
if [[ $HOST == "" ]]; then break; fi
shift 2
;;
--host=*)
HOST="${1#*=}"
shift 1
;;
-p)
PORT="$2"
if [[ $PORT == "" ]]; then break; fi
shift 2
;;
--port=*)
PORT="${1#*=}"
shift 1
;;
-t)
TIMEOUT="$2"
if [[ $TIMEOUT == "" ]]; then break; fi
shift 2
;;
--timeout=*)
TIMEOUT="${1#*=}"
shift 1
;;
--)
shift
CLI="$@"
break
;;
--help)
usage
;;
*)
echoerr "Unknown argument: $1"
usage
;;
esac
done

if [[ "$HOST" == "" || "$PORT" == "" ]]; then
echoerr "Error: you need to provide a host and port to test."
usage
fi

TIMEOUT=${TIMEOUT:-15}
STRICT=${STRICT:-0}
CHILD=${CHILD:-0}
QUIET=${QUIET:-0}

if [[ $CHILD -gt 0 ]]; then
wait_for
RESULT=$?
exit $RESULT
else
if [[ $TIMEOUT -gt 0 ]]; then
wait_for_wrapper
RESULT=$?
else
wait_for
RESULT=$?
fi
fi

if [[ $CLI != "" ]]; then
if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then
echoerr "$cmdname: strict mode, refusing to execute subprocess"
exit $RESULT
fi
exec $CLI
else
exit $RESULT
fi

0 comments on commit b912363

Please sign in to comment.