bcgov / quickstart-openshift

QuickStart template targeted for OpenShift.
https://quickstart-openshift-test-frontend.apps.silver.devops.gov.bc.ca/
Apache License 2.0
30 stars 5 forks source link
actions api codeql crunchy docker flyway javascript nodejs openshift openshift-templates openshift-v4 owasp-zap podman postgis postgresql qsos sonarcloud trivy typescript workflows

MIT License Lifecycle

Merge Analysis Scheduled

Frontend (JavaScript/TypeScript)

Bugs Code Smells Coverage Duplicated Lines Maintainability Rating Reliability Rating Security Rating Technical Debt Vulnerabilities

Backend (JavaScript/TypeScript)

Bugs Code Smells Coverage Duplicated Lines Maintainability Rating Reliability Rating Security Rating Technical Debt Vulnerabilities

QuickStart for OpenShift

Pull Request-Based Workflows with Sample Stack

The is a fully functional set of GitHub Actions workflows and a starter application stack intended to help Agile teams hit the ground running.

Features:

Setup

Initial setup is intended to take an hour or less. This depends greatly on intended complexity, features selected/excluded and outside cooperation.

Prerequisites

The following are required:

Using this Template

Create a new repository using this repository as a template.

Secrets and Variables

Variables and secrets are consumed by workflows. Environments provide their own values, overriding default sets.

Secrets are hidden from logs and outputs, while variables are visible. Using secrets exclusively can make troubeshooting more difficult.

Note: Dependabot, which we don't recommend as highly as Renovate, requires its own set of variables.

Secrets Values

Click Settings > Secrets and Variables > Actions > Secrets > New repository secret

OC_TOKEN

OpenShift token, different for every project/namespace. This guide assumes your OpenShift platform team has provisioned a pipeline account.

Locate an OpenShift pipeline token:

  1. Login to your OpenShift cluster, e.g.: Gold or Silver
  2. Select your DEV namespace
  3. Click Workloads > Secrets (under Workloads for Administrator view)
  4. Select pipeline-token-... or a similarly privileged token
  5. Under Data, copy token
  6. Paste into the GitHub Secret OC_TOKEN

OC_NAMESPACE

OpenShift project/namespace. Provided by your OpenShift platform team.

SONAR_TOKEN(s)

If SonarCloud is being used each application will have its own token. Single-application repositories typically use ${{ secrets.SONAR_TOKEN }}, while monorepos use similar names.

E.g.:

BC Government employees can request SonarCloud projects by creating an issue with BCDevOps. Please make sure to request a monorepo with component names (e.g. backend, frontend), which may not be explained in their directions.

Variable Values

Click Settings > Secrets and Variables > Actions > Variables > New repository variable

OC_SERVER

OpenShift server address.

MS_TEAMS_WEBHOOK_URI

Environments

Environments are groups of secrets and variables that can be gatekept. This includes limting access to certain users or requiring manual approval before a requesting workflow can run. Environment values override any default values.

For pull requests and development surrounding lower-level, sandboxed environments it is best not to use an environment at all. Higher level environments, like TEST and PROD, will override those values as necessary.

Click Settings > Environments > New environment

Environments provide a number of features, including:

Updating Dependencies

Dependabot and Mend Renovate can both provide dependency updates using pull requests. Dependabot is simpler to configure, while Renovate is much more configurable and lighter on resources.

Renovate

A config file (renovate.json) is included with this template. It can source config from our renovate repository. Renovate can be self-hosted or run using the GitHub App managed at the organization level. For BC Government the OCIO controls this application, so please opt in with them using a GitHub issue.

To opt-in:

Dependabot

Dependabot is no longer recommended as an alternative to Renovate for generating security, vulnerability and dependency pull requests. It can still be used to generate warnings under the GitHub Security tab, which is only viewable by repository administrators.

Repository Configuration

Pull Request Handling

Squash merging is recommended for simplified history and ease of rollback. Cleaning up merged branches is recommended for your DevOps Specialist's fragile sanity.

Click Settings > General (selected automatically)

Pull Requests:

Packages

Packages are available from your repository (link on right). All should have visibility set to public for the workflows to run successfully.

E.g. https://github.com/bcgov/quickstart-openshift/packages

Branch Protection Rules

This is required to prevent direct pushes and merges to the default branch. These steps must be run after one full pull request pipeline has been run to populate the required status checks.

  1. Select Settings (gear, top right) > Rules > Rulesets (under Code and Automation)
  2. Click New ruleset > New branch ruleset
  3. Setup Ruleset:
    • Ruleset Name: main
    • Enforcement status: Active
    • Bypass list:
      • Click + Add bypass
      • Check [x] Repository admin
      • Click Add selected
    • Target branches:
      • Click Add target
      • Select Add default branch
    • Branch protections:
      • [x] Restrict deletions
      • [x] Require linear history
      • [x] Require a pull request before merging
        • Additional settings:
          • Require approvals: 1 (or more!)
          • [x] Require conversation resolution before merging
      • [x] Require status checks to pass
        • [x] Require branches to be up to date before merging
        • Required checks: These will be populated after a full pull request pipeline run!
          • Click +Add checks
          • This is our default set, yours may differ:
            • Analysis Results
            • PR Results
            • Validate Results
    • [x] Block force pushes
    • [x] Require code scanning results
      • Click + Add tool
      • This is our default set, yours may differ:
        • CodeQL
        • Trivy
    • Click Create

Status checks example

Required tools and alerts example

Adding Team Members

Don't forget to add your team members!

  1. Select Settings (gear, top right) *> Collaborators and teams (under Access)
  2. Click Add people or Add teams
  3. Use the search box to find people or teams
  4. Choose a role (read, triage, write, maintain, admin)
  5. Click Add

Workflows

Pull Request

Runs on pull request submission.

Validation

Runs on pull request submission.

Analysis

Runs on pull request submission or merge to the default branch.

Pull Request Closed

Runs on pull request close or merge.

Merge

Runs on merge to main branch.

* excludes database changes

Scheduled

Runs on scheduled job (cronjob) or workflow dispatch.

DEMO Routing

There is a long-lived custom route available to be assigned to specific Pull Request deployments. Add the label demo to that pull request or run the DEMO Route workflow.

Typical route: https://<REPO_NAME>-demo.apps.silver.devops.gov.bc.ca

PR Label

Please note that the label must be manually created using GitHub's web interface.

Workflow

App Stack

Starter

The starter stack includes a frontend (React, MUI, Vite, Caddy), backend (Nest/Node) and postgres or postgis database. See subfolder for source, including Dockerfiles and OpenShift templates. Alternative backends are available.

Features:

Postgis is default. Switch to Postgres by removing the image names in crunchy helm chart values

Crunchy

Crunchy is the default choice for HA postgres/postgis DB in BCGov. provided chart is to get up and going fast, it is upto teams to fine tune resource allocation and patroni parameters of crunchy DB to get the best out of database.

Alternative Backends

The sample Java, Python and Go backends repository has been archived, but we have lots of other great examples of active projects you can learn from!

SchemaSpy

The database documentation is created and deployed to GitHub pages. See here.

After a full workflow run and merge can been run, please do the following:

  1. Select Settings (gear, top right) *> Pages (under Code and automation)
  2. Click Branch or Add teams
  3. Select gh-pages
  4. Click Save

img.png

Resources

This repository is provided by NRIDS Architecture and Forestry Digital Services, courtesy of the Government of British Columbia.

Contributing

Please contribute your ideas! Issues and Pull Requests are appreciated.