mayurborkar / Docker_CircleCi_Demo

It is Integration of Circle Ci & Docker Hub For CI and CD Pipeline Using Heroku

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create A File "Dockerfile" With Below Content

FROM python:3.7
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT [ "python" ]
CMD [ "main.py" ]

Create A "Procfile" With Following Content

web: gunicorn main:app

Create A File ".circleci\config.yml" With Following Content

version: 2.1
orbs:
  heroku: circleci/heroku@1.0.1
jobs:
  build-and-test:
    executor: heroku/default
    docker:
      - image: circleci/python:3.6.2-stretch-browsers
        auth:
          username: mydockerhub-user
          password: $DOCKERHUB_PASSWORD  # context / project UI env-var reference
    steps:
      - checkout
      - restore_cache:
          key: deps1-{{ .Branch }}-{{ checksum "requirements.txt" }}
      - run:
          name: Install Python deps in a venv
          command: |
            echo 'export TAG=0.1.${CIRCLE_BUILD_NUM}' >> $BASH_ENV
            echo 'export IMAGE_NAME=python-circleci-docker' >> $BASH_ENV
            python3 -m venv venv
            . venv/bin/activate
            pip install --upgrade pip
            pip install -r requirements.txt
      - save_cache:
          key: deps1-{{ .Branch }}-{{ checksum "requirements.txt" }}
          paths:
            - "venv"
      - run:
          command: |
            . venv/bin/activate
            python -m pytest -v tests/test_script.py
      - store_artifacts:
          path: test-reports/
          destination: tr1
      - store_test_results:
          path: test-reports/
      - setup_remote_docker:
          version: 19.03.13
      - run:
          name: Build and push Docker image
          command: |
            docker build -t $DOCKERHUB_USER/$IMAGE_NAME:$TAG .
            docker login -u $DOCKERHUB_USER -p $DOCKER_HUB_PASSWORD_USER docker.io
            docker push $DOCKERHUB_USER/$IMAGE_NAME:$TAG
  deploy:
    executor: heroku/default
    steps:
      - checkout
      - run:
          name: Storing previous commit
          command: |
            git rev-parse HEAD > ./commit.txt
      - heroku/install
      - setup_remote_docker:
          version: 18.06.0-ce
      - run:
          name: Pushing to heroku registry
          command: |
            heroku container:login
            #heroku ps:scale web=1 -a $HEROKU_APP_NAME
            heroku container:push web -a $HEROKU_APP_NAME
            heroku container:release web -a $HEROKU_APP_NAME

workflows:
  build-test-deploy:
    jobs:
      - build-and-test
      - deploy:
          requires:
            - build-and-test
          filters:
            branches:
              only:
                - main

Initialize Git Repository

git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/mayurborkar/Docker_CircleCi_Demo.git
git push -u origin main

Create A Account At Circle ci

Circle CI

Set Up Your Project

Setup project

Select Project Setting In CircleCI And Set Below Environment Variable

DOCKERHUB_USER

DOCKER_HUB_PASSWORD_USER

HEROKU_API_KEY

HEROKU_APP_NAME

HEROKU_EMAIL_ADDRESS

DOCKER_IMAGE_NAME

About

It is Integration of Circle Ci & Docker Hub For CI and CD Pipeline Using Heroku


Languages

Language:Python 91.9%Language:Dockerfile 8.1%