Skip to content

Instantly share code, notes, and snippets.

@haggen
Last active November 3, 2017 07:53
Show Gist options
  • Save haggen/feaa1f72bb6b282740ad to your computer and use it in GitHub Desktop.
Save haggen/feaa1f72bb6b282740ad to your computer and use it in GitHub Desktop.
Guide: from development to production using docker.

Guide: from development
to production using docker.

Development

You'll need:

  • docker
  • docker-machine
  • docker-compose
  • git
  • pow
  • dotenv.sh
  • deploy.sh

Setup

Within your project you must have:

  • a development.yml and production.yml for docker-compose
  • optionally a Dockerfile
  • a .env file with the variables needed for the application and other services
  • a bin/start script for customized application startup

Choose a custom port with 5 digits to be assigned to your application. Remember to write it to your .env file.

Grab the IP for the docker-machine and setup a local development name with pow:

# ~/.pow/my-application

http://192.168.99.100:55001/

Use Git to version your project. The last commit hash will be used as version tag for the application.

#!/usr/bin/env bash
# Production's username@hostname
remote=
# Application's name and path
name=
path=
version=$(git rev-parse HEAD)
version=${version:0:5}
archive=$version.tar.gz
git archive --format tar.gz -o $archive HEAD
scp $archive $remote:$path
ssh $remote <<SSH
cd $path
tar -xzf $archive
[ -f Dockerfile ] && docker build --tag $name:$version .
docker-compose down -f production.yml
docker-compose up -f production.yml
SSH
#!/bin/sh
if [ -s .env ]; then
source .env
export $(cut -d= -f1 .env)
fi
exec "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment