Giter Club home page Giter Club logo

quickstart-openshift's Introduction

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:

  • Pull Request-based pipeline
  • Sandboxed development environments
  • Gateable production deployments
  • Container publishing (ghcr.io) and importing (OpenShift)
  • Security, vulnerability, infrastructure, and container scan tools
  • Automatic dependency patching available from bcgov/renovate-config
  • Enforced code reviews and workflow jobs (pass|fail)
  • Helm Package Manager for atomic deployments
  • Prometheus Metrics export from Backend/Frontend
  • Resource Tuning with Horizontal Pod Autoscaler (TEST/PROD only)
  • Affinity and anti-affinity for Scheduling on different worker nodes
  • Rolling updates with zero downtime in PROD
  • Database Migrations with Flyway
  • Pod disruption budgets for high availability
  • Self-healing through with probes/checks (startup, readiness, liveness)
  • Sample application stack:

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:

  • BC Government IDIR accounts for anyone submitting requests
  • GitHub accounts for all participating team members
  • Membership in the BCGov GitHub organization
  • OpenShift project namespaces:

Using this Template

Create a new repository using this repository as a template.

  • Verify bcgov/quickstart-openshift is selected under Repository 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.

  • Consume: {{ secrets.OC_TOKEN }}

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.

  • Consume: {{ secrets.OC_NAMESPACE }}
  • Value: format abc123-dev | test | prod

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.:

  • ${{ secrets.SONAR_TOKEN_BACKEND }}
  • ${{ secrets.SONAR_TOKEN_FRONTEND }}

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.

  • Consume: {{ vars.OC_SERVER }}
  • Value: https://api.gold.devops.gov.bc.ca:6443 or https://api.silver.devops.gov.bc.ca:6443

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:

  • Required reviewers
  • Wait timer
  • Deployment branches

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:

  • [uncheck] Allow merge commits
  • [check] Allow squash merging
    • Default to pull request title
  • [uncheck] Allow rebase merging
  • [check] Always suggest updating pull request branches
  • [uncheck] Allow auto-merge
  • [check] Automatically delete head branches

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

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.

  1. Select Settings (gear, top right) *> Branches (under Code and Automation)
  2. Click Add Rule or edit an existing rule
  3. Under Protect matching branches specify the following:
    • Branch name pattern: main
    • [check] Require a pull request before merging
      • [check] Require approvals (default = 1)
      • [check] Dismiss stale pull request approvals when new commits are pushed
      • [check] Require review from Code Owners
    • [check] Require status checks to pass before merging
      • [check] Require branches to be up to date before merging
      • Status checks that are required:
        • Select checks as appropriate, e.g. Build x, Deploy y
        • Recommended:
          • Analysis Results
          • PR Results
          • Validate Results
      • Select at least one status check to enforce branch protection
    • [check] Require conversation resolution before merging
    • [check] Include administrators (optional)

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.

  • Provides safe, sandboxed deployment environments
  • Build action pushes to GitHub Container Registry (ghcr.io)
  • Build triggers select new builds vs reusing builds
  • Deploy only when changes are made
  • Deployment includes curl checks and optional penetration tests
  • Run tests (e2e, load, integration) when changes are made
  • Other checks and updates as required

Validation

Runs on pull request submission.

  • Enforces conventional commits in PR title
  • Adds greetings/directions to PR descriptions

Analysis

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

  • Unit tests (should include coverage)
  • CodeQL/GitHub security reporting (now handled as GitHub default!)
  • Trivy password, vulnerability and security scanning

Pull Request Closed

Runs on pull request close or merge.

  • Cleans up OpenShift objects/artifacts
  • Merge retags successful build images as latest

Merge

Runs on merge to main branch.

  • Code scanning and reporting to GitHub Security overview
  • Zero-downtime* TEST deployment
  • Penetration tests on TEST deployment (optional)
  • Zero-downtime* PROD deployment
  • Labels successful deployment images as PROD

* excludes database changes

Scheduled

Runs on scheduled job (cronjob) or workflow dispatch.

  • PR environment purge
  • Generate SchemaSpy documentation
  • Tests (e2e, load, integration) on TEST deployment

App Stack

Starter

The starter stack includes a (React, MUI, Vite, Caddy) frontend, Pluggable backend(Nest/Node, Quarkus/Java On Native, FastAPI/Python, Fiber/Golang) and postgres database. See subfolder for source, including Dockerfiles and OpenShift templates.

Features:

Postgres is default. Switch to PostGIS by copying the appropriate Dockerfile to ./database:

cp ./database/postgis/Dockerfile ./database

Pluggable Backends

This quickstart works with more than just JavaScript. Please check out our pluggable backends repository. Flyway-based database migrations for each are included.

Supported languages:

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.

quickstart-openshift's People

Contributors

ahbarnz-g avatar bcgov-devops avatar cberg-aot avatar dependabot[bot] avatar derekroberts avatar explorertolu avatar mamartinezmejia avatar mcatherine1994 avatar mishraomp avatar paulushcgcj avatar renovate[bot] avatar repo-mountie[bot] avatar rmcampos avatar shivanganii avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

quickstart-openshift's Issues

Implement Helm Charts

These should be easier to use than OpenShift templates. Investigate.

Benefit: Helm could facilitate easier deployments. It could be used as a package manager for install and uninstall and as a release manager for upgrade and rollbacks amongst other values. It could improve on OpenShift templates.

ZAP Full Scan Report

View the following link to download the report.
RunnerID:1725737243

Badges

Required by bcgov, enforced by Dependabot nags.

Docker build caching

To save time on builds, especially when making small changes to existing PRs.

ZAP Full Scan Report

ZAP Full Scan Report

View the following link to download the report.
RunnerID:1722029109

Basic Dev Deployment Pipeline

GitHub Actions
PR-based
Use oc for deployments and builds (at least initially)
Do not use TOOLs namespace
NodeJs (possibly TypeScript)

ZAP Full Scan Report

PR linting

Lint all PR code. E.g. eslint, tslint, etc.

Templatize the template!

Pull everything pracitical out. Plan for secret storage. Load into pipelines and .yml (templates).

ZAP Full Scan Report

Linting

Likely eslint. tslint has been rolled into it. Basic setup, some (arbitrary) decision making.

ZAP Full Scan Report

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.