Created
November 8, 2014 06:56
-
-
Save ianblenke/92648de57cb7d38fd1e8 to your computer and use it in GitHub Desktop.
Create a rails app and run it along with a mysql container using fig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -ex | |
# Source the boot2docker environment variables | |
eval $(boot2docker shellinit 2>/dev/null) | |
# Use a rails container to create a new rails project in the current directory called figgypudding | |
docker run -it --rm -v $(pwd):/app rails:latest bash -c 'rails new figgypudding; cp -a /figgypudding /app' | |
cd figgypudding | |
# Create the Dockerfile used to build the figgypudding_web:latest image used by the figgypudding_web_1 container | |
cat <<EOD > Dockerfile | |
FROM rails:onbuild | |
ENV HOME /usr/src/app | |
EOD | |
# This is the Fig orchestration configuration | |
cat <<EOF > fig.yml | |
mysql: | |
environment: | |
MYSQL_ROOT_PASSWORD: supersecret | |
MYSQL_DATABASE: figgydata | |
MYSQL_USER: figgyuser | |
MYSQL_PASSWORD: password | |
ports: | |
- "3306:3306" | |
image: mysql:latest | |
figgypudding: | |
environment: | |
RAILS_ENV: development | |
DATABASE_URL: mysql2://figgyuser:password@172.17.42.1:3306/figgydata | |
links: | |
- mysql | |
ports: | |
- "3000:3000" | |
build: . | |
command: bash -xc 'bundle exec rake db:migrate && bundle exec rails server' | |
EOF | |
# Rails defaults to sqlite, convert it to use mysql | |
sed -i -e 's/sqlite3/mysql2/' Gemfile | |
# Update the Gemfile.lock using the rails container we referenced earlier | |
docker run --rm -v $(pwd):/usr/src/app -w /usr/src/app rails:latest bundle update | |
# Use the fig command from my fig-docker container to fire up the Fig formation | |
docker run -v $(pwd):/app -v $DOCKER_CERT_PATH:/certs -e DOCKER_CERT_PATH=/certs -e DOCKER_HOST=$DOCKER_HOST -e DOCKER_TLS_VERIFY=$DOCKER_TLS_VERIFY -ti --rm ianblenke/fig-docker fig up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment