> **Page index:** https://km.oslo.systems/llms.txt lists every page on this site, with a link to its Markdown version.

# Set up CI/CD for `dev`

> [!NOTE]
>
> **Reference implementation**
>
> See the [`pirates-app-hello-world`](<https://github.com/oslokommune/pirates-app-hello-world>) repository for a working example built by following this guide.

Set up branch rulesets, and manual deployment approval for your application repository.

## Step 1: Protect your default branch

Your repository automatically inherits a set of branch rulesets from the GitHub organization when you add a specific custom property to it. These rulesets add a set of required guardrails to your repository. These are **required** to protect your default branch (typically `main`).

1. In your repository, go to **Settings \> Custom properties** and set `gp-repository-type` to `app`.
2. After setting the custom property, verify that **Settings \> Rulesets** have at least 1 ruleset inherited from the organization.

## Step 2: Add configuration files

### Step 2.1: Add `.gp.cicd.json`

Download [.gp.cicd.json](<https://github.com/oslokommune/golden-path-templates/blob/main/templates/gh-cicd-app/.gp.cicd.json>) to the repository root:

hello-world/

```
gh api repos/oslokommune/golden-path-templates/contents/templates/gh-cicd-app/.gp.cicd.dev-only.json \
  --jq '.content' | base64 -d > .gp.cicd.json
```

Update the values referenced in the table below. You can find them in `common-config.yml` in your IaC repository's `dev` environment directory, such as `repo-iac/environments/dev/common-config.yml`.

| Field | Description | Example |
| --- | --- | --- |
| `<team-name>` | Your team name | `pirates` |
| `<repo-iac>` | Infrastructure-as-code repository name | `pirates-iac` |
| `<dev-aws-account-id>` | AWS account ID for `dev` | `123456789012` |
| `<dev-environment-name>` | Name of your `dev` AWS environment | `pirates-dev` |
| `<dev-iac-directory>` | The directory containing IaC for your `dev` environment | `stacks/dev` |
| `<aws-region>` | Your AWS region | `eu-west-1` |

### Step 2.2: Add CODEOWNERS

Add a `CODEOWNERS` file to define who owns the repository and approves PRs:

hello-world/.github/CODEOWNERS

```
* @oslokommune/<github-team-name>
```

| Field | Description | Example |
| --- | --- | --- |
| `<github-team-name>` | The name of your [GitHub team](<https://github.com/orgs/oslokommune/teams>) | `utviklerflyt` |

### Step 2.3: Add Renovate configuration

Download [renovate.json5](<https://github.com/oslokommune/golden-path-templates/blob/main/templates/gh-cicd-app/renovate.json5>) to the repository root:

hello-world/

```
gh api repos/oslokommune/golden-path-templates/contents/templates/gh-cicd-app/renovate.json5 \
  --jq '.content' | base64 -d > renovate.json5
```

> [!NOTE]
>
> **What is Renovate?**
>
> Renovate automatically creates pull requests to keep your dependencies up to date. Think of it as a better Dependabot. Learn more in the [Renovate reference documentation](<https://km.oslo.systems/terraform-automation/renovate/index.md>).

## Step 3: Add and configure workflow

### Step 3.1: Download workflow

Download the [reference workflow](<https://github.com/oslokommune/pirates-apps/blob/main/.github/workflows/too-tikki_deployment.yml>) and address the few `TODO` comments:

hello-world/

```
gh api repos/oslokommune/pirates-apps/contents/.github/workflows/too-tikki_deployment.yml \
  --jq '.content' | base64 -d > .github/workflows/hello-world_deployment.yml
```

The main adaptation is in the `build-and-upload-artifact` job, where you customize the build and test steps to match your application.

### Step 3.2: Disable production deployment

This guide only sets up deployment to `dev`. Comment out everything below these lines:

```
  ################################################################################
  # Job: Deploy to prod
  ################################################################################
```

## Step 4: Create a pull request

Push the branch and create a pull request.

Verify that the build job succeeds and that no deployment occurs.

## Step 5: Merge and deploy

Merge the pull request.

## Step 6: Verify

When merging, the CI/CD workflow should deploy your app to your `dev` environment.

## Next steps

To delete parts of what you created, see the [guide for deleting environments](<https://km.oslo.systems/terraform/delete/delete-environment/index.md>). You can also [delete a remote state bucket](<https://km.oslo.systems/terraform/delete/delete-remote-state-bucket/index.md>).

### Before you go to production

The team that owns the application needs to do a risk assessment analysis (ROS) before going to production. [Read more on how to do that at the risk assessment reference page.](<https://km.oslo.systems/aws-account/risk-assessment-ros/index.md>)

To make the CI/CD workflow deploy your app to production, see [Set up CI/CD for `prod`](<https://km.oslo.systems/application/container/set-up-cicd-for-prod/index.md>).
