{{$app := .AppName | kebabcase}}
# Microservice Application on Google Kubernetes Engine Usage

## Prerequisites

* You must have [Docker](https://docs.docker.com/install/) for your platform
* You must have [docker-compose](https://docs.docker.com/compose/install/) installed

### Google-specific steps

Follow the instructions in the [gcp/README.md](https://github.com/xebialabs/blueprints/blob/master/gcp/README.md) on how to:

* Download and install the Google SDK
* Log in to gcloud
* Configure permissions for running this blueprint

> **Note:** Make sure the `account.json` file you downloaded is placed inside the `terraform-microservice-ecommerce` folder that is created by the blueprint

### Environment variables

If you intend to use the Jenkins CI/CD pipeline to generate your own Docker images, you will need to set the following environment variables before running `docker-compose up` in the same terminal session:

```plain
export GITHUB_USER=<your GitHub user name>
export GITHUB_TOKEN=<your GitHub access token, needed only if you are using a private repository, this variable can be skipped for public repositories>
export DOCKER_USER=<your Docker user name>
export DOCKER_PASS=<your Docker password>
```

{{if eq .GenerateDockerComposeSetup false}}
> **Note:** If you do not have XL Release and XL Deploy instances already running, you can re-run this blueprint and choose to generate a Docker configuration setup.
{{end}}

### Docker repository configuration

1. Replace the occurrences of `xebialabsunsupported`  in the following files with your own DockerHub ID:

    * `kubernetes/notification/notification-deployment.yml`
    * `kubernetes/store/store-deployment.yml`
    * `kubernetes/invoice/invoice-deployment.yml`

2. Commit all changes and push this cloned repository to your GitHub account so that Jenkins can checkout `https://github.com/${GITHUB_USER}/e-commerce-microservice.git`.

## Start the XL Platform
{{if eq .GenerateDockerComposeSetup true}}
Follow the instructions in `xebialabs/USAGE-docker-compose.md`.
{{else}}
Make sure your existing XL Platform is up and running and accessible.
{{end}}

### XL CLI

Watch the log output for `docker_xl-cli_1`. Its job is to connect XL Release to XL Deploy. It must exit with code `0`. If not, open a new terminal in the same directory and run:

```plain
docker-compose up -d xl-cli
```

## Deploy the blueprint to the XL Platform

To deploy this blueprint to the XebiaLabs DevOps Platform, open up a terminal in the `e-commerce-microservice` folder where you generated the configuration. Then run:

```plain
xl apply -f xebialabs.yaml
```

## Deploy to GCP

Go to XL Release and click on `{{$app}}` under the 'Design' tab.

### Provision the CI/CD pipeline

1. Click 'New Release' under `{{$app}}-ci-cd`.
    1. Give the Release a name.
    2. Click 'Create'.
    3. Click 'Start Release'.
    4. When step: 'Apply RBAC authentication' is reached follow the steps below:
        1. Get the cluster name
             ```plain
                gcloud container clusters list
             ```
            The name will what your provided in the blueprint set up under cluster name with -cluster appended to it
        2. Get the authentication details
             ```plain
                gcloud container clusters get-credentials [cluster_name from 1] --zone [location from 1]
             ```
        3. Switch kube context
             ```shell script
                 kubectl config set-context [cluster_name from 1]     
             ```
        4. Deploy manifest.yaml
             ```shell script
                 kubectl apply -f manifest.yaml
             ```
        5. Click the 3 dots on 'Apply RBAC authentication in XL Release'
        6. Click assign to me
        7. Click on 'Apply RBAC authentication'
        8. Click complete
## Undeploy from GCP

Go to XL Release and click on `{{$app}}` under the 'Design' tab.

### Deprovision the CI/CD pipeline

1. Click 'New Release' under `{{$app}}-destroy`.
    1. Give the Release a name.
    2. Click 'Create'.
    3. Click 'Start Release'.

## Extras

* You can find a detailed tutorial for this blueprint [here](https://docs.xebialabs.com/v.9.0/xl-release/how-to/deploy-to-aws-using-blueprints)

