Skip to content

Instantly share code, notes, and snippets.

@mlabouardy
Created October 21, 2017 19:53
Show Gist options
  • Save mlabouardy/bb4f8b467f6b3bc6a2ab229e15ff8fb8 to your computer and use it in GitHub Desktop.
Save mlabouardy/bb4f8b467f6b3bc6a2ab229e15ff8fb8 to your computer and use it in GitHub Desktop.
Setup CI/CD with Heroku, Docker & CircleCI
version: 2
jobs:
build:
docker:
- image: python:3.5
environment:
MYSQL_HOST: 127.0.0.1
MYSQL_DB: mydb
MYSQL_USER: root
MYSQL_PASSWORD: root
- image: mysql:5.6
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: mydb
steps:
- checkout
- restore_cache:
key: deps1-{{ .Branch }}-{{ checksum "requirements.txt" }}
- run:
name: Install dependencies
command: |
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
- save_cache:
key: deps1-{{ .Branch }}-{{ checksum "requirements.txt" }}
paths:
- "venv"
- run:
name: Install dockerize
command: wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
environment:
DOCKERIZE_VERSION: v0.3.0
- run:
name: Wait for MySQL
command: dockerize -wait tcp://localhost:3306 -timeout 1m
- run:
name: Run unit tests
command: |
python3 -m venv venv
. venv/bin/activate
python app/tests.py
- setup_remote_docker
- run:
name: Install Docker client
command: |
set -x
VER="17.03.0-ce"
curl -L -o /tmp/docker-$VER.tgz https://get.docker.com/builds/Linux/x86_64/docker-$VER.tgz
tar -xz -C /tmp -f /tmp/docker-$VER.tgz
mv /tmp/docker/* /usr/bin
- run:
name: Build Docker image
command: docker build -t mlabouardy/movies-store:$CIRCLE_SHA1 .
- run:
name: Push to DockerHub
command: |
docker login -u$DOCKERHUB_LOGIN -p$DOCKERHUB_PASSWORD
docker push mlabouardy/movies-store:$CIRCLE_SHA1
- run:
name: Setup Heroku
command: |
chmod +x .circleci/setup-heroku.sh
.circleci/setup-heroku.sh
- run:
name: Deploy to Heroku
command: |
cd app/
git push heroku master
@vforv
Copy link

vforv commented Apr 7, 2018

I this case it will not push docker image to heroku it will just run app directly on host?

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