Created
September 25, 2015 15:56
-
-
Save lukemadera/0961776310d8deedfbde to your computer and use it in GitHub Desktop.
jwilder/nginx-proxy using Compose + Swarm + Machine attempt 1
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
#!/bin/bash | |
set -e | |
if [ -z "$DIGITALOCEAN_ACCESS_TOKEN" ]; then | |
echo >&2 "ERROR: You must export DIGITALOCEAN_ACCESS_TOKEN" | |
exit 1 | |
fi | |
docker pull swarm > /dev/null | |
TOKEN="$(docker run swarm create)" | |
echo >&2 "Docker Swarm token: $TOKEN" | |
echo >&2 "Creating Docker Swarm cluster" | |
( | |
set -x | |
docker-machine create -d digitalocean --digitalocean-size "1gb" --swarm --swarm-master --swarm-discovery "token://$TOKEN" swarm-master | |
docker-machine create -d digitalocean --digitalocean-size "1gb" --swarm --swarm-discovery "token://$TOKEN" --engine-label type=app swarm-01 | |
docker-machine create -d digitalocean --digitalocean-size "1gb" --swarm --swarm-discovery "token://$TOKEN" --engine-label type=app swarm-02 | |
docker-machine create -d digitalocean --digitalocean-size "1gb" --swarm --swarm-discovery "token://$TOKEN" --engine-label type=app swarm-03 | |
docker-machine create -d digitalocean --digitalocean-size "1gb" --swarm --swarm-discovery "token://$TOKEN" --engine-label type=proxy swarm-proxy | |
) |
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
#!/bin/bash | |
set -e | |
# get into directory that has the compose.yml file(s) | |
cd /opt/code | |
echo >&2 "Generating app.env:" | |
cat <<EOF | tee app.env >&2 | |
VIRTUAL_HOST=$(docker-machine ip swarm-proxy) | |
constraint:type==app | |
EOF | |
# TODO - SSL | |
#echo >&2 "Generating proxy:" | |
#cat <<EOF | tee proxy.env >&2 | |
#DOCKER_TLS_VERIFY=1 | |
#DOCKER_HOST=tcp://$(docker-machine ip swarm-master):3376 | |
#DOCKER_CERT_PATH=/tmp/docker-certs | |
#constraint:type==proxy | |
#EOF | |
echo >&2 "Generating proxy:" | |
cat <<EOF | tee proxy.env >&2 | |
DOCKER_HOST=tcp://$(docker-machine ip swarm-master):3376 | |
constraint:type==proxy | |
EOF | |
eval "$(docker-machine env --swarm swarm-master)" | |
# TODO - SSL | |
#echo >&2 "Copying TLS config to swarm-proxy" | |
#docker-machine scp -r "$DOCKER_CERT_PATH" swarm-proxy:/tmp/docker-certs | |
echo >&2 "Starting services via Docker Compose" | |
docker-compose -f docker-production-swarm.yml up -d | |
#docker-compose scale proxy=1 app=3 | |
docker-compose -f docker-production-swarm-proxy.yml up -d | |
docker-compose -f docker-production-swarm-proxy.yml scale proxy=1 | |
docker-compose -f docker-production-swarm.yml scale app=3 | |
echo >&2 "Checking running containers" | |
docker ps | |
echo >&2 "Visit http://$(docker-machine ip swarm-proxy) to test" |
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
proxy: | |
image: jwilder/nginx-proxy | |
ports: | |
- "80:3000" | |
# use external file so can generate it from variables | |
env_file: | |
- proxy.env | |
# SSL - TODO | |
#volumes: | |
# - "/tmp/docker-certs:/tmp/docker-certs" |
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
app: | |
# switch this to a pre-built image? just add to dropprice-code? Then could link to mongo again too! | |
#build: . | |
image: lukemadera/dropprice-code | |
ports: | |
- "3000:3000" | |
# use external file so can generate it from variables | |
env_file: | |
- app.env |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment