Skip to main content

CI/CD with CircleCI - Heroku deploy

Note
In this post, we'll deploy a Flask app to Heroku. Any commit to Github, the CircleCI will be triggered and test will be performed. If the test finished successfully, the CircleCI will deploy our app to Heroku.




Signup by authorizing Github
First, sign up for CircleCI.

CircleCI-Top-Menu.png

SignUp.png
We can login to CircleCI platform via Github by allowing access to the repo.
AuthorizeCirceCIGithub.png
At the click on "Authorize application", we'll have welcome screen with a list of our Github repositories:
WelcomeToCircleCI.png



Installing and running locally
We'll use the following source in GitHub: circleci-heroku.
Here are the steps to install and run the test:
  1. Clone the repo and cd circleci-heroku.
  2. Setup virtualenv : virtualenv venv and then source venv/bin/activate.
  3. Run pip install -r requirements.txt (preferably inside a virtualenv) to install the dependencies.
  4. To run the "hello" app locally:
  5. (venv) k@laptop:~/TEST/circleci-heroku$ python hello/hello_app.py
     * Running on http://127.0.0.1:5000/
    

    HelloWorld.png
  6. Run nosetests to run the unit test.
  7. (venv) k@laptop:~/TEST/circleci-heroku$ nosetests
    .
    ----------------------------------------------------------------------
    Ran 1 test in 1.206s
    
    OK
    




Continuous Integration and Continuous Deployment with Python
Basic CircleCI configuration is available from here.
But in this tutorial, we'll use Python Flask, so the reference is available from Continuous Integration and Continuous Deployment with Python.
CircleCI works well for Python projects. CircleCI runs automatic inference on each build to determine dependencies and test commands. If CircleCI doesn't infer all of our settings, we can also add custom configuration to a circle.yml file checked into our repo's root directory, which is our case.
When CircleCI detects Python, CircleCI automatically uses virtualenv to create an isolated Python environment. It also automatically installs our dependencies using either pip when it finds a requirements.txt, or distutils when we find a setup.py file.
CircleCI has pre-installed more than a dozen databases and queues, including PostgreSQL and MySQL. If needed, we can manually set up our test database from our circle.yml.




Heroku Setup
If Heroku is not installed, let's do it:
$ sudo apt-get install software-properties-common 
$ sudo add-apt-repository "deb https://cli-assets.heroku.com/branches/stable/apt ./"
$ curl -L https://cli-assets.heroku.com/apt/release.key | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install heroku

To verify our CLI installation use the heroku --version command:
$ heroku --version
heroku-cli/5.6.28-2643c0a (linux-amd64) go1.7.5

Get Heroku API key:
$ heroku auth:token
Enter your Heroku credentials.
Email: pygoogle@aol.com
Password (typing will be hidden): 
Logged in as pygoogle@aol.com
ea408fd3-7681-6g47-19c4-61282704700g

And SSH key:
$ heroku keys:add
Found an SSH public key at /home/k/.ssh/id_rsa.pub
? Would you like to upload it to Heroku? Yes
Uploading /home/k/.ssh/id_rsa.pub SSH key... done

We must supply or confirm some authentication settings before Heroku deployment. CircleCI divides this setup work into three steps.
  1. API key
  2. SSH key
  3. App name

We need to input the API key into the account settings on CircleCI:
Account-Settings-Heroku-API-Key.png
Also, we may want to set the registered person as the Heroku deploy user and to associate a Heroku SSH key with the deploy user's account.
Heroku-SSH-Key.png

One more thing: we need to create a new project in Heroku. The project name should be in circle.yml:
Heroku-project-name.png




Testing
Click "Add Projects" on the Welcome screen:
AddProjects.png

BuildProject.png
CircleCI automatically runs test commands when certain files are detected:
  1. tox when tox.ini is found
  2. nosetest when unittest.py is found
  3. manage.py test when manage.py contains a testing section
  4. setup.py test when setup.py contains a testing section


CircleCI-Build.png



Deployed app on Heroku
We can get the url for the deployed app:
app-url.png
Here is the app that's been deployed after a successful testing:
Heroku-Deployed-App.png

Comments

  1. This specific article, we shall use a new Flask software for you to Heroku. Just about any spend on Github, your CircleCI are going to Heroku Vs Aws be activated along with examination are going to be executed. If your examination concluded properly, your CircleCI will certainly use each of our software for you to Heroku.

    ReplyDelete

Post a Comment

Popular posts from this blog

Merge AVHDX Hyper-V Checkpoints

When you create a snapshot of a virtual machine in Microsoft Hyper-V, a new file is created with the  .avhdx  file extension. The name of the file begins with the name of its parent VHDX file, but it also has a GUID following that, uniquely representing that checkpoint (sometimes called snapshots). You can see an example of this in the Windows Explorer screenshot below. Creating lots of snapshots will result in many  .avhdx  files, which can quickly become unmanageable. Consequently, you might want to merge these files together. If you want to merge the  .avhdx  file with its parent  .vhdx  file, it’s quite easy to accomplish. PowerShell Method Windows 10 includes support for a  Merge-VHD  PowerShell command, which is incredibly easy to use. In fact, you don’t even need to be running PowerShell “as Administrator” in order to merge VHDX files that you have access to. All you need to do is call  Merge-VHD  with the  -Path  parameter, pointing to the  .avhdx  file, and the  -Des

Openstack manila phần 4: Native GlusterFS Driver

Tiếp tục loạt bài về Openstack Manila hôm nay tôi sẽ cấu hình backend sử dụng GlusterFS Yêu cầu phiên bản GlusterFS >= 3.6. Với glusterfs nếu cluster của bạn không hỗ trợ snapshot thì trên manila cũng sẽ mất đi tính năng này. Để cấu hình snapshot ta sẽ cấu hình Thin Provision theo bài hướng dẫn link Với bài lab của mình có 2 node và chạy kiểu replicate. Mình sẽ tạo các thinly provisioned và tạo volume trên đó. Mô hình cài đặt Cài đặt glusterfs-v3.7 add-apt-repository ppa:gluster/glusterfs-3.7 -y apt-get update apt-get install glusterfs-server -y Tham khảo script tạo thin LV và gluster volume Script tạo thinly provisioned chạy trên 2 node apt-get install xfsprogs -y pvcreate /dev/sdb vgcreate myVG /dev/sdb lvcreate -L 8G -T myVG/thinpool for ((i = 1;i<= 5; i++ )) do mkdir -p /manila/manila-"$i" for (( j = 1; j<= 5; j++)) do lvcreate -V "${i}"Gb -T myVG/thinpool -n vol-"$i"-"$j" mkfs.xfs /dev/my

Zabbix, AWS and Auto Registration

One of the things I love the most with AWS is  auto-scaling . You choose an AMI, set some parameters and AWS will spin instances up and down whenever a threshold is breached. But with all these instances spinning up and down there are some unknowns. For example, what is the IP address of the new instance? Its host name? This can be critical when other components of your infrastructure are dependent on knowing these parameters. I had this problem when I started to use  Zabbix  as the monitoring system. At first it seemed like a complicated one, but Zabbix has a wonderful feature called  Auto Registration  which can be used exactly for this situation. I will try to show how to configure auto registration both on the client (EC2 instance running Ubuntu 14.04) and on the Zabbix server (Zabbix Server 2.4.2). Zabbix-agent Installation and Configuration Let’s start with installing zabbix-agent on the Ubuntu client: 1 2 $ sudo apt-get update $ sudo apt-get install -y zab