This is a step-by-step guide to deploying a project hosted on GitLab.com to Google Cloud, using Auto Deploy.
We made a minimal [Ruby application](https://gitlab.com/gitlab-examples/minimal-ruby-app) to use as an example for this guide. It contains several files that we need to make auto deploy possible.
We made a minimal [Ruby application](https://gitlab.com/gitlab-examples/minimal-ruby-app) to use as an example for this guide. It contains two files:
*`server.rb` - our application. It will start an HTTP server on port 5000 and render “Hello, world!”
*`Dockerfile` - to build our app into a container image. It will use a ruby base image and run `server.rb`
These are the absolute minimal requirement to have your application automatically build and deploy to Google Container Engine every time you push to the repository.
### Fork sample project on GitLab.com
Let’s start by forking our sample application. Go to [the project page](https://gitlab.com/gitlab-examples/minimal-ruby-app) and press the `Fork` button. In few minutes you should have a project under your namespace with all the necessary files.
Let’s start by forking our sample application. Go to [the project page](https://gitlab.com/gitlab-examples/minimal-ruby-app) and press the `Fork` button. Soon you should have a project under your namespace with the necessary files.
### Setup your own cluster on Google Container Engine
We assume you already have account for https://console.cloud.google.com. If not - you need to create one.
If you do not already have a Google Cloud account, create one at https://console.cloud.google.com.
Visit the [`Container Engine`](https://console.cloud.google.com/kubernetes/list) tab and create a new cluster. You can change the name and leave the rest of the default settings. Once you have your cluster running, you need to connect to the cluster by following Google interface.
Visit the [`Container Engine`](https://console.cloud.google.com/kubernetes/list) tab and create a new cluster. You can change the name and leave the rest of the default settings. Once you have your cluster running, you need to connect to the cluster by following the Google interface.
### Connect to Kubernetes cluster
...
...
@@ -26,9 +24,10 @@ On OSX, install [homebrew](https://brew.sh):
Connect to the cluster and open Kubernetes Dashboard
Now go back to the Google interface, find your cluster, and follow the instructions under `Connect to the cluster` and open the Kubernetes Dashboard. It will look something like `gcloud container clusters get-credentials ruby-autodeploy \ --zone europe-west2-c --project api-project-XXXXXXX` and then `kubectl proxy`.
![connect to cluster](img/guide_connect_cluster.png)
...
...
@@ -38,11 +37,11 @@ Once you have the Kubernetes Dashboard interface running, you should visit `Secr
![connect to cluster](img/guide_secret.png)
You need to copy-paste these the ca.crt and token into your project on GitLab.com in the Kubernetes integration page under project `Settings` > `Integrations` > `Project services` > `Kubernetes`. Don't actually copy the namespace though. Each project should have a unique namespace, and by leaving it blank, GitLab will create one for you.
You need to copy-paste the ca.crt and token into your project on GitLab.com in the Kubernetes integration page under project `Settings` > `Integrations` > `Project services` > `Kubernetes`. Don't actually copy the namespace though. Each project should have a unique namespace, and by leaving it blank, GitLab will create one for you.
![connect to cluster](img/guide_integration.png)
For API URL setting you should use the `Endpoint` IP from your cluster page on Google Cloud Platform. That will ensure GitLab.com can deploy containers to your cluster at Google Container Engine.
For API URL, you should use the `Endpoint` IP from your cluster page on Google Cloud Platform.
### Expose application to the world
...
...
@@ -74,15 +73,14 @@ Use `nslookup minimal-ruby-app-staging.<yourdomain>` to confirm that domain is a
### Setup Auto Deploy
Visit home page of your GitLab.com project and press "Setup Auto Deploy" button.
Visit the home page of your GitLab.com project and press "Set up Auto Deploy" button.
![auto deploy button](img/auto_deploy_btn.png)
You will be redirected to the New file page where you can apply one of the Auto Deploy templates. Select "Kubernetes" to apply the template, then in the file, replace "domain.example.com" with your domain name and any other adjustments you feel comfortable with.
You will be redirected to new file page where you can apply one of the several Auto Deploy templates. Select "Kubernetes", replace "domain.example.com" with your domain name and any other adjustments you feel comfortable with.
Once submitted, your changes should create a new pipeline with several jobs. If you made only domain changes it will be 3 jobs: build, staging and production. The build job will create a docker image with your new change and push it to the GitLab Container Registry. Staging job will deploy this image on your cluster. Once the deploy job succeeds you should be able to see your application by visiting the Kubernetes dashboard. Select the namespace of your project, which will look like `ruby-autodeploy-23`, but with a unique ID for your project, and your app will be listed as “staging” under the Deployment tab.
Change the target branch to `master`, and submit your changes. This should create a new pipeline with several jobs. If you made only the domain name change, the pipeline will have 3 jobs: `build`, `staging` and `production`. The `build` job will create a docker image with your new change and push it to the GitLab Container Registry. The `staging` job will deploy this image on your cluster. Once the deploy job succeeds you should be able to see your application by visiting the Kubernetes dashboard. Select the namespace of your project, which will look like `ruby-autodeploy-23`, but with a unique ID for your project, and your app will be listed as “staging” under the Deployment tab.
Once its ready - just visit http://minimal-ruby-app-staging.yourdomain.com to see “Hello, world!”