

Deploying application onto GCE using codeship
source link: https://blog.knoldus.com/deploying-application-onto-gce-using-codeship/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Deploying application onto GCE using codeship
Reading Time: 3 minutes
Codeship Basic uses fast, performant VMs with preinstalled technology stacks to make it super easy and fast to get started running a CI/CD pipeline.
We already deploy the application on GCE by creating a VM instance. If you have no idea about that you can refer it from here. I personally experienced that whenever new version of the application occurs or any new feature added to the application, I had to deploy it again. Such as the need to follow
- ssh to vm
- git pull
- create docker image
- and the finally deploy
I personlly hate this method. I wanted everyone steps has to be automated. Whenever the commit is pushed to github ,I want first to test the code and if test pass then deploy.
The solution for above problem is codeship basic pipeline. Follow the below to steps to create the CI-CD pipeline to deploy on GCE(Google Compute Engine)
1. Connect to source code provider
When you signup to Codeship, connect your Github or Bitbucket account.
When it comes time to configure your project. You will see
2. Configure Test
Select the technology you want , it will automatically create the test command. Otherwise select “I want to create my own custom commands”
sbt test
For now all I have here is sbt test which runs my unit test cases.
Click save, go to dashboard and follow the on-boarding steps to push your project.
Do a git push to your master branch and let codeship do it’s magic. If all works well you’ll see this.
If your test cases failed you get “failure” in red at place of success. See the logs and fix it before going to production.
Now uptil now we set the CI.
Now the question is how i deploy to the google compute engine ?
3. Create the vm on GCP.
If you are not aware about how to create CLICK HERE. Setup the enviroment on VM you need to run the application. As i m running my scala application using container ,I setup the following things on VM
- Scala
- Docker
You have to setup the enviroment as per your requirement.
4. Preparing GCE to accept the codeship deployment.
After creating vm . SSH into your machine.
ssh username@ip
Now , go to your home directory and create a folder called MyApp. (mkdir MyApp) or you can give meaningfull name as you want.
Then, go back to Codeship, go to project settings and click on general.
Copy Codeship’s public ssh key from here. This will let Codeship deploy to your server easily.
Then back in your terminal, You need to add the CodeShip public SSH key for your project to the ~/.ssh/authorized_keys file on your server.
nano ~/.ssh/authorized_keys
4. Deploy
Go to project setting , Select deploy -> script ->
rsync -avz ~/clone/ [email protected]:MyApp
ssh [email protected] 'cd codeship-rest &&
sudo docker build -t codeship-rest:0.1 . &&
sudo docker stop knolx-rest &&
sudo docker rm knolx-rest &&
sudo docker run --name knolx-rest --env-file env.list -d --restart always --network host codeship-rest:0.1'
Click on “Save Changes”. Onec you push commit to master branch your pipeline get automatically trigger.
First, rsync -av copies all the files from the clone directory which Codeship creates on every push, into your MyApp folder that we previous created on your host GCE system.
Next we run some commands over ssh. The commands are we run basically cd into the MyApp directory, build the docker image, stop all previously running docker instances and remove them and then run the docker app on localhost.
(Note: Here i already created a dockerfile which is present on my git repo, so if you need to run application using docker container you need to fisrt create Dockerfile and push to your github repo)
5 . Build Trigger
In build trigger you can select which branch you need to build, which branches you don’t want to build or need to build all branches.
Also select when you want to build
- Build on commit, merge, and tags
- Build only on PR events
6. Environment
If you need to export some environment variables , you can specify the in the environment section.
Recommend
-
49
Reading Time: 6 minutes In this post I wanted to cover the why and some of the how of shipping apps to a Kubernetes cluster fromCodeship. I
-
10
Deploying the Hand Detector onto Jetson TX2 Sep 25, 2018 Quick link: jkjung-avt/tf_trt_models In previous posts, I’ve shared how to apply TF-TRT to optimi...
-
7
Reading Time: 5 minutes What is CodeShip ? CodeShip is a hosted continuous delivery service that focuses on speed, simplicity and reliability. It is a fast and secure hosted CI service that scales as per user’s needs. CodeShip wa...
-
13
Welcome to back in my another article. You will see all about the integration of WordPress, MySQL, Helm etc, in this article. So let's get started without delay. Pre-requisite To perform this scenario you will need me...
-
9
Deploying a Python Flask Example Application Using...
-
13
技术之前,先读诗书:焦土已经三月火,残花犹发万年枝。 如何在GCE访问GKE中的TCP服务
-
24
技术之前,先读诗书:五月畲田收火米,三更津吏报潮鸡。 1 Introduction We always need to create the GCE(Google Compute Engine) if we use GCP. There are many ways t...
-
1
New regions supported in GCE Written by Lovisa Johansson 2019-05-20 Support has been added for some new r...
-
8
Deploying a Flask Application Using Heroku In this video course, you’ll create a Python Flask example application and deploy it using
-
6
Deploying an ASP.NET Core Web Application using the Document Editor with Docker A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an applicati...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK