Skip to content

Commit

Permalink
Merge pull request #140 from stakater/doc-pipeline
Browse files Browse the repository at this point in the history
fixes and added github ssh secret document
  • Loading branch information
AsfaMumtaz authored Aug 23, 2023
2 parents 2a81a4f + 030d22f commit 6f61cab
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Creating a Pipeline Using Pipeline as Code

Now that we have added our first application using Stakater Opinionated GitOps Structure, we can continue by adding a pipeline to our application.

In modern software development practices, pipelines play a crucial role in automating and streamlining the process of building, testing, and deploying applications. This tutorial will guide you through creating a pipeline using pipeline-as-code concepts. We'll focus on GitHub as the provider and assume that you have a SAAP set up with pipeline-as-code capabilities.

Now that we have completed all the prerequisites to run this `pipelineRun`, we can continue by adding a pipeline to our application using `pipeline-as-code` approach.

## Objectives

- Configure SSH keys and secret for the pipeline.
- Create a Tekton PipelineRun using a `.tekton/main.yaml` file from a code repository.
- Define parameters, workspaces, and tasks within the PipelineRun for building and deploying your application.

## Key Results

- Successfully generate and configure an SSH secret to provide secure access to your code repository.
- Successfully create and execute the Tekton PipelineRun using the defined `.tekton/main.yaml` file, enabling automated CI/CD processes for your application.

## Tutorial

### Create PipelineRun Resource

Let's walk you through creating a Tekton `PipelineRun` using a `Pipeline-as-Code` approach. Create a `.tekton` folder and place it in the `pipelineRun` for your source code repository as `main.yaml`. This enables you to define and manage your pipelines along with your application code, promoting better code-pipeline integration and version control.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Secret and Repository CRD Definition

The `Secret` holds sensitive data, such as your GitHub access token and webhook secret. By storing these secrets separately from your source code, you ensure that sensitive information is kept secure and not exposed in your repository.
# Repository CRD Definition

The `Repository CRD` helps you define the structure of your CI/CD pipeline. By referencing authentication secrets in the CRD, you ensure that your pipeline has the necessary access rights to interact with GitHub.

Expand All @@ -22,6 +20,8 @@ In this tutorial, you'll create secrets containing your GitHub access credential

### Create a Secret on SAAP

The `Secret` holds sensitive data, such as your GitHub access token and webhook secret. By storing these secrets separately from your source code, you ensure that sensitive information is kept secure and not exposed in your repository.

1. To create a secret first log in to SAAP using `oc` CLI.

1. Paste this command and replace `your-namespace` with your namespace, `provider.token` value with your PAT, and `webhook.secret` value with your webhook secret.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Securely Storing SSH Keys for Tekton PipelineRun

When working with Tekton Pipelines and storing your pipeline definition in a `.tekton` folder within your source code repository, it's important to keep sensitive authentication information, such as SSH keys, secure and separate from the public codebase. In this tutorial, you will learn how to securely store SSH keys using Secrets to access your code repository within your Tekton PipelineRun.

## Objectives

- Generate SSH keys to securely access your code repository.
- Add your public key as a deploy key in your GitHub repository.
- Store the private SSH key in Secret to be used by your Tekton PipelineRun.

## Key Results

- Successfully generate a pair of SSH keys for repository access.
- Set up the public SSH key as a deploy key in your GitHub repository.
- Create a Secret containing the private SSH key for Tekton PipelineRun.

## Tutorial

1. Let's create SSH keys to access the repository.

For SSH Access:

- [`Generate SSH Key Pair`](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key)

1. Add your `public-key` into the `Deploy key` section of your repository:

- [`Add Deploy Key to your Repository`](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/managing-deploy-keys#deploy-keys)

> Note: A deploy key is specific to a single repository and cannot be used for multiple repositories.*
After adding the `Deploy keys` in your repository, now is the time to add the secret.

1. Copy the below `secret` yaml.

```yaml
apiVersion: v1
kind: Secret
metadata:
name: nordmart-ssh-creds # Name of Secret
namespace: <your-namespace> # Place your namespace where you want to run the pipeline
stringData:
type: git
sshPrivateKey: | # Paste your private key here as it is, the sshPrivateKey value will be base64 encoded in the secret. You do not need to manually encode the value before creating the secret.
-----BEGIN OPENSSH PRIVATE KEY-----
...
-----END OPENSSH PRIVATE KEY-----
```
1. Log in to SAAP, go to Administrator > Workloads > Secrets. Create a secret with yaml.
![secret with yaml](images/secret-yaml.png)
1. Paste the `secret yaml`, add your `private key`, and your `namespace` then hit `Create`.

![create ssh secret](images/create-ssh-secret.png)

Now look at the `nordmart-ssh-creds` secret yaml, the private key will be encoded to `base64`.

![ssh secret](images/nordmart-ssh.png)

> Note: We will be using this secret in our `pipelineRun`.

Cool! Let's move on to the next tutorial and create a pipeline.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ nav:
- Outer Loop:
- for-developers/tutorials/outer-loop/access-cluster/access-the-cluster.md
- for-developers/tutorials/outer-loop/add-build-environment/add-environment.md
- for-developers/tutorials/outer-loop/github-access/github-access.md
- for-developers/tutorials/outer-loop/github-pat/github-pat.md
- for-developers/tutorials/outer-loop/webhook-setup/webhook-setup.md
- for-developers/tutorials/outer-loop/secret-and-repo-crd/secret-and-repo-crd.md
- for-developers/tutorials/outer-loop/create-repo-crd/create-repo-crd.md
- for-developers/tutorials/outer-loop/github-ssh/github-ssh.md
- for-developers/tutorials/outer-loop/add-ci-pipeline/add-ci-pipeline.md
- for-developers/tutorials/outer-loop/promote-application/promote-app.md
- How-to guides:
Expand Down

0 comments on commit 6f61cab

Please sign in to comment.