Last active
December 13, 2016 10:48
-
-
Save ryandotsmith/6287748 to your computer and use it in GitHub Desktop.
EC2 Docker Setup
This file contains hidden or 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
FROM ubuntu | |
MAINTAINER "Bobby Wilson" | |
RUN apt-get update | |
RUN apt-get install curl -y | |
RUN cd /usr/local; curl -O http://nodejs.org/dist/v0.10.16/node-v0.10.16-linux-x64.tar.gz | |
RUN cd /usr/local; tar xzf node-v0.10.16-linux-x64.tar.gz | |
ENV PATH /usr/local/bin:/usr/sbin:/bin:/usr/local/node-v0.10.16-linux-x64/bin | |
ADD . /app | |
EXPOSE 8000:8000 | |
ENV PORT 8000 | |
CMD ["node", "/app/index.js"] |
This file contains hidden or 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
description "Run ADF Setup" | |
start on started docker | |
task | |
respawn limit 15 5 | |
chdir /home/ubuntu | |
exec ./setup.sh 2>&1 >> /var/log/adf.log |
This file contains hidden or 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
# Abort our setup if anything goes wrong. | |
set -e | |
# Our upstart script redirects all output of this script to /var/log/adf.log | |
# We can debug the output looking for when the script started. | |
echo "at=start-setup time=`date`" | |
# We are making use of EC2's user data feature. When you provision a new | |
# EC2 instance, you can supply arbitrary text as the user data. In the case | |
# our setup script, we are assuming that the data in the user data store is | |
# valid bash. Specifically we are expecting that it contain variable declerations | |
# for $RELEASE_URL and $APP | |
curl http://169.254.169.254/latest/user-data -o user-data | |
export $(cat user-data) | |
# We are using ADF-CONFIG(1) to download the app's environment variables | |
# from our DynamoDB config table. ADF-CONFIG(1) relies on IAM roles to | |
# access DynamoDB. | |
./adf-config -l -a $APP > env | |
# Download the code via RELEASE\_URL –which is supplied by user-data. We | |
# expect the tar ball to include a single directory in which the app's | |
# code and Dockerfile are located. | |
rm -rf build | |
mkdir build | |
curl -L $RELEASE_URL | tar xvz -C build | |
BUILD_VERSION=$(ls build) | |
#Even though our upstart script calls this setup program after the docker | |
# service is started, it still can be possible for the docker service to | |
# not be fully operational. This step handle that race condition. | |
until docker version; do; echo 'waiting for docker'; sleep 1; done | |
# Build the app based on the Dockerfile. | |
docker build -t "$USER/$BUILD_VERSION" "build/$BUILD_VERSION" 2>&1 | |
# We now use docker to run the container. We are doing a little hack here | |
# to get our environment variables into the conatiner. We can't specify | |
# our environment variables in the Dockerfile since the file is in version | |
# control. (No secrets in the source!) So, we take the result of | |
# ADF-CONFIG(1), massage it into the -e flags that the docker run command | |
# expects. | |
docker run $(cat env | awk '{print "-e " $1}' | tr -s '\n' ' ') -d "$USER/$BUILD_VERSION" 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment