Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
jwilder/nginx-proxy using Compose + Swarm + Machine attempt 1
#!/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
)
#!/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"
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"
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
You can’t perform that action at this time.