Technical Articles
How to deploy web application automatically using CircleCI ?
【Introduction】
In this blog, I will explain about the way of automatic deployment with circleCI.
After you finish reading the blog, then you can know circleCI setting method.
You don’t need to type some kind of cf commands as you deploy your application for SAP Cloud Platform.
【IT Architecture】
I will show IT Architecture outline below.
You know GitHub is a platform for version control using Git.Also, CircleCI is a continuous integration tool.You attempt to build and deploy automatically with using them.
【Topic/table of Content】
- Create user account for GitHub
- Create user account for CircleCI
- Configure CircleCI and describe jobs
- Run CircleCI jobs
【Environment】
You need to prepare Cloud Foundry environments.
Cloud Environment :Cloud Foundry environment.
PC/Service :1 PC (※ In my case, I used WindowsPC)
【Version】
WindowsPC Edition :Windows 10 Enterprise 2016 LTSB
CPU :Intel(R)Core(TM)i5-7300U CPU @ 2.60GHz 2.71GHz
Memory(RAM) :8.00GB
【1. Create user account for GitHub】
First, you create user account for GitHub.
After that, you prepare your repository and application.
- Open GitHub official site
・「https://github.com/」 - Create your account for GitHub
- Push new button on the right side screen
- Name your repository name
- Select repository type.(※ public repository or private repository)
- Create new repository
- Clone or download the repository you created
- Checkout the git repository on your laptop PC
- Commit and push your source codes
Create 「app.js」const http = require('http'); var express = require('express') var request = require("request") var app = express() app.get('/', function (req, res) { res.json({ ret: "Hello" }) }) var server = app.listen(process.env.PORT || 9000, function () { console.log('Listening on port %d', server.address().port) })
Create 「manifest.yml」
--- applications: - name: app_sample host: appsample memory: 512M env: destinations: > [ { "name":"app_sample", "url":"https://appsample.cfapps.eu10.hana.ondemand.com/", "forwardAuthToken": true } ]
This app.js is simple and easy web application.
【2. Create user account for CircleCI】
Second, you create user account for CircleCI and setup GitHub project.
- Open circleCI official site
・「https://circleci.com/」 - Select GitHub account
- Setup project
After setup project, you can choose to add a config file manually or automatically.
【3. Configure CircleCI and describe jobs】
Next step, you create config.yml and move it to circleci folder.
You describe jobs definition in the config.yml file.
- Create circleCI folder
- Create a config.yml file
- Describe circiCI jobs on your 「config.yml」
version: 2.1 orbs: cloudfoundry: circleci/cloudfoundry@0.1.73 workflows: "Sample App": jobs: - build1 jobs: build1: docker: - image: circleci/node:10.15.3 steps: - checkout - run: name: Sample App command: | curl -v -L -o cf-cli_amd64.deb 'https://cli.run.pivotal.io/stable?release=debian64&source=github' sudo dpkg -i cf-cli_amd64.deb npm config set @sap:registry https://npm.sap.com -yes npm install @sap/xssec echo Y | sudo npm install -g -y @angular/cli cf login -a https://api.cf.eu10.hana.ondemand.com -u [Your email] -p [Your password] -o [Your space] -s dev cf push
【4. Run CircleCI jobs】
Finally, you run circleci jobs after you commit and push source code.
- Commit your source codes
- Push your source codes
- Run circleCI job
- Access your application on SAP Cloud Platform
Commit command is a trigger for circleCI jobs. After committing, you may need to wait several minutes.
After a few minutes, you can see web application on the SAP Cloud Platform.
【Summary】
To sum up, you can automatically deploy your application to SAP Cloud Platform without typing any cf commands.
Your development process become efficiently to save build and deployment time.
【Reference】
・「Deploying Flask + Python web application and Linking Node web application」
https://blogs.sap.com/2019/07/21/deploying-flask-python-web-application-on-sap-cloud-platform/