Skip to content

Commit

Permalink
Merge pull request #8 from xogroup/feature/support_worker_web-7
Browse files Browse the repository at this point in the history
Adds features to support web vs worker deploys
  • Loading branch information
nrodriguez authored Aug 19, 2016
2 parents 4b9f2ab + 7da885f commit 0b3ce20
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 71 deletions.
20 changes: 15 additions & 5 deletions dockerize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def run
program :version, '0.1.0'
program :description, 'A script to add the necessary files to your application in order for it to use docker and deploy easily'

global_option('-t', '--test', 'Runs the dockerizing process into a test folder') { working_dir = "./test" }
global_option('-t', '--test', 'Runs the dockerizing process into a test folder') { working_dir("./test") }

command :this do |c|
c.syntax = 'dockerize this [options]'
Expand All @@ -24,7 +24,6 @@ def run
c.option '--circleci', 'Adds the files for a circle ci supported project'
c.action do |args, options|
# Do something or c.when_called Dockerize::Commands::Dockerize
@working_dir = "../"
copy_files(options)
set_project_info
end
Expand All @@ -39,7 +38,7 @@ def set_project_info
puts "Please enter the information for your application:\n"
app_name = ask("Project Name:")
ecr_host = ask("ECR Host:")
version = ask("Version:")
version = ask("Version: (ie: 1-0-0)")

replace_values(app_name, ecr_host, version)
end
Expand Down Expand Up @@ -70,8 +69,13 @@ def replace(before, after, files)
end

def copy_files(options)
type(choose("Web or Worker?", :web, :worker))
puts "Copying setup files...\n"
FileUtils.cp_r './files/general/.', working_dir

puts "Copying type specific deploy files...\n"
FileUtils.cp_r "./files/#{type}/.", working_dir

options.default.keys.each do |opt|
copy_specific_files(option: opt)
end unless options.default.empty?
Expand All @@ -81,16 +85,22 @@ def copy_specific_files(option: opt)
case option.to_s
when "ruby"
puts "Copying Ruby setup files"
FileUtils.cp_r './files/ruby/scripts/.', "#{working_dir}/scripts"
FileUtils.cp_r './files/ruby/general/scripts/.', "#{working_dir}/scripts"

FileUtils.cp_r "./files/ruby/#{type}/scripts/.", "#{working_dir}/scripts"
when "circleci"
puts "Copying Circle CI setup files"
FileUtils.cp_r './files/circle_ci/.', "#{working_dir}/."
end
end

def working_dir(dir = "./")
def working_dir(dir = "../")
@working_dir ||= dir
end

def type(type = "web")
@type ||= type
end
end

Dockerize.new.run if $0 == __FILE__
38 changes: 1 addition & 37 deletions files/general/scripts/docker/bin/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1 @@
#!/usr/bin/env bash

#Set up the variables needed
VERSION=`cat ./VERSION`
APP_NAME=`cat ./APP_NAME`
APP_ENV=$1 #Environment (qa/prod)
TYPE=$2 #Type (web/worker)
APP_ENV_FULL=`if [ $APP_ENV = prod ]; then echo production; else echo $APP_ENV; fi`
AWS_KEY=`aws configure get aws_access_key_id`
AWS_SECRET=`aws configure get aws_secret_access_key`
AWS_REGION=`aws configure get region`

#Copy the appropriate Dockerrun file to the root
cp ./scripts/docker/$APP_ENV-Dockerrun.aws.json ./Dockerrun.aws.json
git add Dockerrun.aws.json

#Try to use the current eb environment
#If it exists deploy to existing environment
#If not then create a new one (blue/green deployment)
errors=`eb use $APP_ENV-$APP_NAME-$VERSION-$TYPE | grep "ERROR: Environment"`
if [$errors == ""]; then
eb deploy $APP_ENV-$APP_NAME-$VERSION-$TYPE --timeout 30 --staged
else
eb create $APP_ENV-$APP_NAME-$VERSION-$TYPE \
--tags Name=$APP_ENV-$APP_NAME \
--cfg $APP_NAME-$APP_ENV \
-c $APP_ENV-$APP_NAME-$VERSION-$TYPE \
--timeout 15 \
--envvars AWS_ACCESS_KEY_ID=$AWS_KEY,\
AWS_SECRET_ACCESS_KEY=$AWS_SECRET,\
AWS_REGION=$AWS_REGION,\
SECRET_KEY_BASE=$SECRET_KEY_BASE,\
WEB_TYPE=$TYPE,\
RAILS_ENV=$APP_ENV_FULL,\
RAKE_ENV=$APP_ENV_FULL,\
WEB_CONCURRENCY=3
fi
##This will be replaced based on whether it's a web or worker
File renamed without changes.
1 change: 1 addition & 0 deletions files/ruby/general/scripts/docker/bin/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#Will be replaced by the web/worker script for ruby
File renamed without changes.
File renamed without changes.
26 changes: 0 additions & 26 deletions files/ruby/scripts/docker/bin/deploy.sh

This file was deleted.

3 changes: 0 additions & 3 deletions files/ruby/scripts/setup/generate_secret_key.rb

This file was deleted.

65 changes: 65 additions & 0 deletions files/ruby/web/scripts/docker/bin/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

raw_environment_name=$1
raw_environment_type=$2
AWS_ACCESS_KEY_ID=`aws configure get aws_access_key_id`
AWS_SECRET_ACCESS_KEY=`aws configure get aws_secret_access_key`
AWS_REGION=`aws configure get region`

function qualified_environment_name {
echo $raw_environment_name-$(app_name)-$(app_version)-$raw_environment_type | sed 's/_/-/g' | sed 's/\./-/g'
}

function qualified_rails_environment_name {
if [ $raw_environment_name == prod ]; then echo production; else echo $raw_environment_name; fi
}

function secret_key_base {
echo $(base64 /dev/urandom | head -c 60)
}

function app_version {
cat ./VERSION
}

function app_name {
cat ./APP_NAME
}

function is_existing_environment {
errors=$(eb use $(qualified_environment_name) | grep "ERROR: Environment")
if [$errors == ""]; then return 0; else return 1; fi
}

function qualified_instance_type {
if [ $raw_environment_name == 'prod' ]; then echo 't2.medium'; else echo 't2.micro'; fi
}

#Copy the appropriate Dockerrun file to the root
cp ./scripts/docker/$raw_environment_name-Dockerrun.aws.json ./Dockerrun.aws.json
git add Dockerrun.aws.json

#Try to use the current eb environment
#If it exists deploy to existing environment
#If not then create a new one (blue/green deployment)
if is_existing_environment; then
echo "Deploy"
eb deploy $(qualified_environment_name) --timeout 30 --staged
else
echo "Create"
eb create $(qualified_environment_name) \
-c $(qualified_environment_name)
-t web \
-i $(qualified_instance_type) \
--tags Name=$(app_name),Team='Your Team Here',Application='$(app_name)',Environment=$(qualified_rails_environment_name),Role='Web' \
--envvars AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY,AWS_REGION=$AWS_REGION,SECRET_KEY_BASE=$(secret_key_base),RAILS_ENV=$(qualified_rails_environment_name),RACK_ENV=$(qualified_rails_environment_name) \
--vpc.id 'vpc-12344' \
--vpc.dbsubnets 'subnet-12345' \
--vpc.ec2subnets 'subnet-12345 \
--vpc.elbpublic \
--vpc.publicip \
--vpc.securitygroups 'sg-1235' \
-k 'ec2-key-here' \
-ip 'some_instance_profile' \
--timeout 15
fi
64 changes: 64 additions & 0 deletions files/ruby/worker/scripts/docker/bin/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash

raw_environment_name=$1
raw_environment_type=$2
AWS_ACCESS_KEY_ID=`aws configure get aws_access_key_id`
AWS_SECRET_ACCESS_KEY=`aws configure get aws_secret_access_key`
AWS_REGION=`aws configure get region`

function qualified_environment_name {
echo $raw_environment_name-$(app_name)-$(app_version)-$raw_environment_type | sed 's/_/-/g' | sed 's/\./-/g'
}

function qualified_rails_environment_name {
if [ $raw_environment_name == prod ]; then echo production; else echo $raw_environment_name; fi
}

function secret_key_base {
echo $(base64 /dev/urandom | head -c 60)
}

function app_version {
cat ./VERSION
}

function app_name {
cat ./APP_NAME
}

function is_existing_environment {
errors=$(eb use $(qualified_environment_name) | grep "ERROR: Environment")
if [$errors == ""]; then return 0; else return 1; fi
}

function qualified_instance_type {
if [ $raw_environment_name == 'prod' ]; then echo 't2.medium'; else echo 't2.micro'; fi
}

#Copy the appropriate Dockerrun file to the root
cp ./scripts/docker/$raw_environment_name-Dockerrun.aws.json ./Dockerrun.aws.json
git add Dockerrun.aws.json

#Try to use the current eb environment
#If it exists deploy to existing environment
#If not then create a new one (blue/green deployment)
if is_existing_environment; then
echo "Deploy"
eb deploy $(qualified_environment_name) --timeout 30 --staged
else
echo "Create"
eb create $(qualified_environment_name) \
-t worker \
-i $(qualified_instance_type) \
--tags Name=$(app_name),Team='Your Team Here',Application='$(app_name)',Environment=$(qualified_rails_environment_name),Role='Web' \
--envvars AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY,AWS_REGION=$AWS_REGION,SECRET_KEY_BASE=$(secret_key_base),RAILS_ENV=$(qualified_rails_environment_name),RACK_ENV=$(qualified_rails_environment_name) \
--vpc.id 'vpc-12344' \
--vpc.dbsubnets 'subnet-12345' \
--vpc.ec2subnets 'subnet-12345 \
--vpc.elbpublic \
--vpc.publicip \
--vpc.securitygroups 'sg-1235' \
-k 'ec2-key-here' \
-ip 'some_instance_profile' \
--timeout 15
fi
57 changes: 57 additions & 0 deletions files/web/scripts/docker/bin/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash

raw_environment_name=$1
raw_environment_type=$2
AWS_ACCESS_KEY_ID=`aws configure get aws_access_key_id`
AWS_SECRET_ACCESS_KEY=`aws configure get aws_secret_access_key`
AWS_REGION=`aws configure get region`

function qualified_environment_name {
echo $raw_environment_name-$(app_name)-$(app_version)-$raw_environment_type | sed 's/_/-/g' | sed 's/\./-/g'
}

function app_version {
cat ./VERSION
}

function app_name {
cat ./APP_NAME
}

function is_existing_environment {
errors=$(eb use $(qualified_environment_name) | grep "ERROR: Environment")
if [$errors == ""]; then return 0; else return 1; fi
}

function qualified_instance_type {
if [ $raw_environment_name == 'prod' ]; then echo 't2.medium'; else echo 't2.micro'; fi
}

#Copy the appropriate Dockerrun file to the root
cp ./scripts/docker/$raw_environment_name-Dockerrun.aws.json ./Dockerrun.aws.json
git add Dockerrun.aws.json

#Try to use the current eb environment
#If it exists deploy to existing environment
#If not then create a new one (blue/green deployment)
if is_existing_environment; then
echo "Deploy"
eb deploy $(qualified_environment_name) --timeout 30 --staged
else
echo "Create"
eb create $(qualified_environment_name) \
-c $(qualified_environment_name)
-t web \
-i $(qualified_instance_type) \
--tags Name=$(app_name),Team='Your Team Here',Application='$(app_name)',Environment=$(qualified_environment_name),Role='Web' \
--envvars AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY,AWS_REGION=$AWS_REGION \
--vpc.id 'vpc-12344' \
--vpc.dbsubnets 'subnet-12345' \
--vpc.ec2subnets 'subnet-12345 \
--vpc.elbpublic \
--vpc.publicip \
--vpc.securitygroups 'sg-1235' \
-k 'ec2-key-here' \
-ip 'some_instance_profile' \
--timeout 15
fi
56 changes: 56 additions & 0 deletions files/worker/scripts/docker/bin/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

raw_environment_name=$1
raw_environment_type=$2
AWS_ACCESS_KEY_ID=`aws configure get aws_access_key_id`
AWS_SECRET_ACCESS_KEY=`aws configure get aws_secret_access_key`
AWS_REGION=`aws configure get region`

function qualified_environment_name {
echo $raw_environment_name-$(app_name)-$(app_version)-$raw_environment_type | sed 's/_/-/g' | sed 's/\./-/g'
}

function app_version {
cat ./VERSION
}

function app_name {
cat ./APP_NAME
}

function is_existing_environment {
errors=$(eb use $(qualified_environment_name) | grep "ERROR: Environment")
if [$errors == ""]; then return 0; else return 1; fi
}

function qualified_instance_type {
if [ $raw_environment_name == 'prod' ]; then echo 't2.medium'; else echo 't2.micro'; fi
}

#Copy the appropriate Dockerrun file to the root
cp ./scripts/docker/$raw_environment_name-Dockerrun.aws.json ./Dockerrun.aws.json
git add Dockerrun.aws.json

#Try to use the current eb environment
#If it exists deploy to existing environment
#If not then create a new one (blue/green deployment)
if is_existing_environment; then
echo "Deploy"
eb deploy $(qualified_environment_name) --timeout 30 --staged
else
echo "Create"
eb create $(qualified_environment_name) \
-t worker \
-i $(qualified_instance_type) \
--tags Name=$(app_name),Team='Your Team Here',Application='$(app_name)',Environment=$(qualified_environment_name),Role='Web' \
--envvars AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY,AWS_REGION=$AWS_REGION \
--vpc.id 'vpc-12344' \
--vpc.dbsubnets 'subnet-12345' \
--vpc.ec2subnets 'subnet-12345 \
--vpc.elbpublic \
--vpc.publicip \
--vpc.securitygroups 'sg-1235' \
-k 'ec2-key-here' \
-ip 'some_instance_profile' \
--timeout 15
fi

0 comments on commit 0b3ce20

Please sign in to comment.