Skip to content

Instantly share code, notes, and snippets.

@neilellis
Last active August 29, 2015 14:19
Show Gist options
  • Save neilellis/212b24ec704f302a3dad to your computer and use it in GitHub Desktop.
Save neilellis/212b24ec704f302a3dad to your computer and use it in GitHub Desktop.
Basic Circle.yml files for Tutum
machine:
services:
- docker
dependencies:
cache_directories:
- "~/docker"
override:
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS tutum.co
- if [[ -e ~/docker/image.tar ]]; then docker load -i ~/docker/image.tar; fi
- docker build -t your-docker-app .
- if [[ ! -e ~/docker/image.tar ]]; then mkdir -p ~/docker; docker save your-docker-app > ~/docker/image.tar; fi
test:
override:
- "cont=$(docker run -d -p 8080:80 your-docker-app); sleep 5 ; docker logs $cont;"
- curl --retry 3 --retry-delay 5 -v http://localhost:8080/
deployment:
all:
branch: [master,dev]
commands:
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS tutum.co
- "docker tag -f your-docker-app tutum.co/your-tutum-account/your-docker-app:${CIRCLE_BRANCH}"
- docker push tutum.co/your-tutum-account/your-docker-app:${CIRCLE_BRANCH}
#The following is optional, it's what I use in general for the staging process
staging:
branch: staging
commands:
- git config --global user.email "hello@myname.me"
- git config --global user.name "My Name"
- git reset HEAD --hard
- git clean -fd
- git checkout master
- git pull
- git merge staging -m "Auto merge"
- echo ${CIRCLE_SHA1} > public/_build_sha1.txt
- echo ${CIRCLE_BUILD_NUM} > public/_build_num.txt
- git add public/_build_num.txt
- git add public/_build_sha1.txt
- git commit -a -m "Promotion from staging for build ${CIRCLE_BUILD_NUM} (commit ${CIRCLE_SHA1})"
- "git tag ${CIRCLE_BUILD_NUM} || :"
- git push --tags
- git push origin master
machine:
services:
- docker
dependencies:
cache_directories:
- "~/docker"
override:
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS tutum.co
- docker build -t your-docker-app .
test:
override:
- "cont=$(docker run -d -p 8080:80 your-docker-app); sleep 5 ; docker logs $cont;"
- curl --retry 3 --retry-delay 5 -v http://localhost:8080/
deployment:
all:
branch: [master,dev]
commands:
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS tutum.co
- "docker tag -f your-docker-app tutum.co/your-tutum-account/your-docker-app:${CIRCLE_BRANCH}"
- docker push tutum.co/your-tutum-account/your-docker-app:${CIRCLE_BRANCH}
#The following is optional, it's what I use in general for the staging process
staging:
branch: staging
commands:
- git config --global user.email "hello@myname.me"
- git config --global user.name "My Name"
- git reset HEAD --hard
- git clean -fd
- git checkout master
- git pull
- git merge staging -m "Auto merge"
- echo ${CIRCLE_SHA1} > public/_build_sha1.txt
- echo ${CIRCLE_BUILD_NUM} > public/_build_num.txt
- git add public/_build_num.txt
- git add public/_build_sha1.txt
- git commit -a -m "Promotion from staging for build ${CIRCLE_BUILD_NUM} (commit ${CIRCLE_SHA1})"
- "git tag ${CIRCLE_BUILD_NUM} || :"
- git push --tags
- git push origin master
machine:
services:
- docker
dependencies:
cache_directories:
- "~/docker"
override:
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS tutum.co
- docker build -t your-docker-app .
#Flattening takes place here, could be anywhere but convenient to place here
test:
override:
- "cont=$(docker run -d -p 8080:80 your-docker-app); sleep 5 ; docker logs $cont; docker export $cont | docker import - your-docker-app"
- curl --retry 3 --retry-delay 5 -v http://localhost:8080/
deployment:
all:
branch: [master,dev]
commands:
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS tutum.co
- "docker tag -f your-docker-app tutum.co/your-tutum-account/your-docker-app:${CIRCLE_BRANCH}"
- docker push tutum.co/your-tutum-account/your-docker-app:${CIRCLE_BRANCH}
#The following is optional, it's what I use in general for the staging process
staging:
branch: staging
commands:
- git config --global user.email "hello@myname.me"
- git config --global user.name "My Name"
- git reset HEAD --hard
- git clean -fd
- git checkout master
- git pull
- git merge staging -m "Auto merge"
- echo ${CIRCLE_SHA1} > public/_build_sha1.txt
- echo ${CIRCLE_BUILD_NUM} > public/_build_num.txt
- git add public/_build_num.txt
- git add public/_build_sha1.txt
- git commit -a -m "Promotion from staging for build ${CIRCLE_BUILD_NUM} (commit ${CIRCLE_SHA1})"
- "git tag ${CIRCLE_BUILD_NUM} || :"
- git push --tags
- git push origin master
@neilellis
Copy link
Author

You'll need to set the environment variables in CircleCI's project settings for :

DOCKER_EMAIL
DOCKER_USER
DOCKER_PASS

These should be your Tutum credentials.

Note the 'staging' part is optional, but useful if you want to protect 'master' from dodgy builds etc.

I've included a variation with image caching if the image or it's parent image take a long time to build.

Also an example using image flattening; beware of this as it strips all metadata from the image - including ENV values and ONBUILD etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment