Skip to content

Commit

Permalink
Merge pull request #25 from stakater/add-application-onboarding
Browse files Browse the repository at this point in the history
update and verify application onboarding docs SA-1824
  • Loading branch information
karl-johan-grahn authored May 11, 2023
2 parents c3af734 + b8b2673 commit 680d9af
Showing 1 changed file with 94 additions and 57 deletions.
151 changes: 94 additions & 57 deletions content/for-delivery-engineers/gitops/application-onboarding.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ This guide covers the step-by-step guide to onboard a new project/application/mi

Changes required in application repository:

1. Add Dockerfile to application repository and push it to nexus
1. Add Helm Chart to application repository and push it to nexus
1. Push Docker Image to Nexus Docker.
1. Push Helm Chart to Nexus Helm
1. Add Dockerfile to application repository.
1. Push Docker Image to Nexus Docker Repository.
1. Add Helm Chart to application repository.
1. Push Helm Chart to Nexus Helm Repository.

Changes required in `gitops config repository`:

1. Add dev environment in `apps-gitops-config` repository for application
1. Add application to the dev environment and sync ArgoCD Application
1. View Application in Cluster
1. Add an environment in `apps-gitops-config` repository for application.
1. Add application helm chart to the dev environment and sync ArgoCD Application.
1. View Application in Cluster.

Replace angle brackets with following values in below templates:

Expand All @@ -23,9 +23,42 @@ Replace angle brackets with following values in below templates:
- `<gitops-repo>`: URL of your GitOps repo
- `<nexus-repo>`: URL of nexus repository

In this section, we will use [`stakater-nordmart-review-ui`](https://github.com/stakater-lab/stakater-nordmart-review-ui) application as an example and add it to our GitOps structure we made in the previous section.

## Prerequisites

- `tenant` for application must be defined via `infra-gitops-config` [See GitOps Onboarding](gitops-onboarding.md)
- `tenant` for application should be onboarded onto `apps-gitops-config` [See GitOps Onboarding](gitops-onboarding.md)
- [helm](https://helm.sh/docs/intro/install/)
- [git](https://git-scm.com/downloads)
- [oc](https://docs.openshift.com/container-platform/4.11/cli_reference/openshift_cli/getting-started-cli.html)
- [buildah](https://github.com/containers/buildah/blob/main/install.md)

## Docker Image and Helm Chart Repository hosted by Nexus

> Ask admin for Docker and Helm Registry Credentials for pushing container images and helm chart respectively.
Navigate to the cluster Forecastle, search `nexus` using the search bar on top menu and copy the nexus url.

- `nexus-docker-reg-url`: Remove `https://` from the start and add `-docker` in URL after `nexus`. This URL points to Docker Registry referred as `nexus-docker-reg-url` in this tutorial for example `nexus-docker-stakater-nexus.apps.clustername.random123string.kubeapp.cloud`.

- `nexus-helm-reg-url` : Remove `https://` from the start, add `-helm` in URL after `nexus` and append `/repository/helm-charts/`. This URL points to Helm Registry referred as `nexus-helm-reg-url` in this tutorial for example `nexus-helm-stakater-nexus.apps.clustername.random123string.kubeapp.cloud/repository/helm-charts/`

![nexus-Forecastle](./images/nexus-forecastle.png)

### Login to Docker Registry

Run following command to log into the registry.

```sh
buildah login <nexus-docker-reg-url>
```

Specify admin provided username and password to login.

## 1. Add **Dockerfile** to application repository

We need a **Dockerfile** for our application present inside our code repo. Navigate to [`RedHat image registry`](https://catalog.redhat.com/software/containers/search) and find a suitable image for the application.
We need a **Dockerfile** for our application present inside our code repo to build a container image. Navigate to [`RedHat image registry`](https://catalog.redhat.com/software/containers/search) and find a suitable base image for the application.

Below is a Dockerfile for a ReactJS application for product reviews. Visit for more info: <https://github.com/stakater-lab/stakater-nordmart-review-ui>

Expand Down Expand Up @@ -55,13 +88,37 @@ CMD ["node", "server.js"]
> Create [multi-stage builds](https://docs.docker.com/build/building/multi-stage/), use multiple `FROM` statements. Each `FROM` instruction can use a different base, and each of them begins a new stage of the build. You can selectively copy artifacts from one stage to another, leaving behind everything you don’t want in the final image. The end result is the same tiny production image as before, with a significant reduction in complexity. You don’t need to create any intermediate images, and you don’t need to extract any artifacts to your local system at all.
Look into the following dockerizing guides for a start.

| Framework/Language | Reference |
|--------------------|-------------------------------------------------------------|
| NodeJS | <https://nodejs.org/en/docs/guides/nodejs-docker-webapp/> |
| Django | <https://blog.logrocket.com/dockerizing-django-app/> |
| General | <https://www.redhat.com/sysadmin/containerizing-applications> |

## 2. Add Helm Chart to application repository
## 2. Push Docker Image to Nexus

Lets clone the [`stakater-nordmart-review-ui`](https://github.com/stakater-lab/stakater-nordmart-review-ui) application.

```bash
git clone https://github.com/stakater-lab/stakater-nordmart-review-ui
cd stakater-nordmart-review-ui
```

Replace the placeholders and Run the following command inside application folder.

```sh
# Buldah Bud Info : https://manpages.ubuntu.com/manpages/impish/man1/buildah-bud.1.html
buildah bud --format=docker --tls-verify=false --no-cache -f ./Dockerfile -t <nexus-docker-reg-url>/<tenant-name>/<app-name>:1.0.0 .
```

Lets push the image to nexus docker repo. Make sure to get credentials from Stakater Admin.

```sh
# Buildah push Info https://manpages.ubuntu.com/manpages/impish/man1/buildah-push.1.html
buildah push <nexus-docker-reg-url>/<tenant-name>/stakater-nordmart-review:1.0.0 docker://<nexus-docker-reg-url>/<tenant-name>/stakater-nordmart-review:1.0.0
```

## 3. Add Helm Chart to application repository

In application repo add Helm Chart in ***deploy*** folder at the root of your repository. To configure Helm chart add following 2 files in ***deploy*** folder.

Expand All @@ -70,15 +127,16 @@ In application repo add Helm Chart in ***deploy*** folder at the root of your re
> More Info : Stakater Application Chart <https://github.com/stakater/application>
```yaml
apiVersion: v2
name: <application>
description: A Helm chart for Kubernetes
dependencies:
- name: application
version: 1.2.10
repository: https://stakater.github.io/stakater-charts
type: application
version: 1.0.0
apiVersion: v2
# Replace Chart Name with App Name.
name: stakater-nordmart-review-ui
description: A Helm chart for Kubernetes
dependencies:
- name: application
version: 2.1.13
repository: https://stakater.github.io/stakater-charts
type: application
version: 1.0.0
```
2. The values.yaml contains all the application specific **kubenetes resources** (deployments, configmaps, namespaces, secrets, services, route, podautoscalers, RBAC) for the particular environment. Configure Helm values as per application needs.
Expand All @@ -91,22 +149,16 @@ In application repo add Helm Chart in ***deploy*** folder at the root of your re
# application name should be short so limit of 63 characters in route can be fulfilled.
# Default route name formed is <application-name>-<namespace>.<base-domain> .
# Config Maps have <application> prefixed
applicationName: <application>

# Replace applicationName with App Name
applicationName: stakater-nordmart-review-ui

deployment:
# nexus-docker-config-forked is deployed in all tenant namespaces for pulling images
imagePullSecrets: nexus-docker-config-forked
additionalLabels:
mylabel: mylabelvalue
envFrom:
<application>-dbconfig:
type: configmap
nameSuffix: dbconfig
configMap:
enabled: true
files:
dbconfig:
DB_NAME: "my-application-db"
MONGO_HOST: "my-db-host"
image:
repository: <nexus-docker-reg-url>/<tenant-name>/stakater-nordmart-review-ui
tag: 1.0.0
route:
enabled: true
port:
Expand All @@ -118,16 +170,21 @@ If your application contains dependency charts run the following command in depl
```sh
# Download helm dependencies in Chart.yaml
cd deploy/
# command info : helm dependency --help
helm dependency build
```

![helm-dependency-build](./images/helm-dependency-build.png)

4. Run the following command to see the Kubernetes manifests are being generated successfully and validate whether they match your required configuration.
4. Run the following command to see the Kubernetes manifests are being generated successfully and validate whether they match your required configuration. This simple helm chart generates deployment, service and route resources.

> View Application Chart Usage [here](https://github.com/stakater/application)

```sh
# Generates the chart against values file provided
# and write the output to application-output.yaml
# command info : helm template --help
helm template . > application-output.yaml
```

Expand All @@ -139,26 +196,6 @@ References to Explore:
- [`stakater-nordmart-review-ui`](https://github.com/stakater-lab/stakater-nordmart-review-ui/deploy)
- [All configurations available via Application Chart Values](https://github.com/stakater/application/blob/master/application/values.yaml)

## 3. Push Docker Image to Nexus

Navigate to the cluster Forecastle and get the Nexus URL. Get and copy the nexus url.

![nexus-Forecastle](./images/nexus-forecastle.png)

Replace the placeholders and Run the following command inside application folder.

```sh
# Buldah Bud Info : https://manpages.ubuntu.com/manpages/impish/man1/buildah-bud.1.html
buildah bud --format=docker --tls-verify=false --no-cache -f ./Dockerfile -t <nexus-repo-url>/<app-name>:1.0.0 .
```

Lets push the image to nexus docker repo. Make sure to get credentials from Stakater Admin.

```sh
# Buildah push Info https://manpages.ubuntu.com/manpages/impish/man1/buildah-push.1.html
buildah push --tls-verify=false --digestfile ./image-digest <nexus-repo-url>/stakater-nordmart-review:snapshot-pr-350-68b5d049 docker://<nexus-repo-url>/
```

## 4. Push Helm Chart to Nexus

After successfully pushing the image to Nexus. We need to package our helm chart and push to Nexus Helm Repo.
Expand All @@ -170,16 +207,16 @@ helm package .
# output : successfully packaged chart and saved it to: /Desktop/Tasks/stakater/stakater-nordmart-review-ui/deploy/stakater-nordmart-review-ui-1.0.0.tgz
```

Now lets upload the chart to Nexus Helm Repo using curl.
This command packages a chart into a versioned chart archive file.

```sh
# heml
curl -u "<helm_user>":"<helm_password>" <nexus-repo-url>/repository/helm-charts --upload-file "stakater-nordmart-review-ui-1.0.0.tgz"
curl -u "<helm_user>":"<helm_password>" <nexus-helm-reg-url> --upload-file "stakater-nordmart-review-ui-1.0.0.tgz"
```

## 5. Add application chart to `apps-gitops-config`

Navigate to `apps-gitops-config` repository and add a helm chart in path `<tenant-name>/<app-name>/dev`.
Navigate to `apps-gitops-config` repository and add a helm chart in path `gabbar/stakater-nordmart-review/dev` i.e. `<tenant-name>/<app-name>/dev`.

![app-in-dev-env](./images/app-in-dev-env.png)

Expand All @@ -191,15 +228,15 @@ description: A Helm chart for Kubernetes
dependencies:
- name: <chart-name-in-deploy-folder>
version: "1.0.0"
repository: <nexus-repo>/repository/helm-charts/
repository: <nexus-helm-reg-url>/repository/helm-charts/
version: 1.0.0
-----------------------------------------
# <tenant-name>/<app-name>/dev/values.yaml
<dependency-name>:
application:
deployment:
image:
repository: <nexus-repo>/<chart-name-in-deploy-folder>
repository: <nexus-docker-reg-url>/stakater-nordmart-review-ui
tag: 1.0.0
```

Expand Down

0 comments on commit 680d9af

Please sign in to comment.