Skip to content

Commit f60dc84

Browse files
committed
wip
1 parent f819c8f commit f60dc84

File tree

1 file changed

+245
-16
lines changed

1 file changed

+245
-16
lines changed

README.md

Lines changed: 245 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,253 @@
1-
# OpenShift Clients
1+
<!-- PROJECT SHIELDS -->
22

3-
The OpenShift client `oc` simplifies working with Kubernetes and OpenShift
4-
clusters, offering a number of advantages over `kubectl` such as easy login,
5-
kube config file management, and access to developer tools. The `kubectl`
6-
binary is included alongside for when strict Kubernetes compliance is necessary.
3+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=bcgov_onroutebc&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=bcgov_onroutebc)
4+
[![Merge](https://github.com/bcgov/onroutebc/actions/workflows/merge.yml/badge.svg)](https://github.com/bcgov/onroutebc/actions/workflows/merge.yml)
5+
[![Analysis](https://github.com/bcgov/onroutebc/actions/workflows/analysis.yml/badge.svg)](https://github.com/bcgov/onroutebc/actions/workflows/analysis.yml)
76

8-
To learn more about OpenShift, visit [docs.openshift.com](https://docs.openshift.com)
9-
and select the version of OpenShift you are using.
7+
[![Issues](https://img.shields.io/github/issues/bcgov/onroutebc)](/../../issues)
8+
[![Pull Requests](https://img.shields.io/github/issues-pr/bcgov/onroutebc)](/../../pulls)
9+
[![MIT License](https://img.shields.io/github/license/bcgov/onroutebc.svg)](/LICENSE.md)
10+
[![Lifecycle](https://img.shields.io/badge/Lifecycle-Experimental-339999)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md)
1011

11-
## Installing the tools
12+
# QuickStart: OpenShift, TypeScript and Postgres/PostGIS
1213

13-
After extracting this archive, move the `oc` and `kubectl` binaries
14-
to a location on your PATH such as `/usr/local/bin`. Then run:
14+
The DevOps Quickstart is a fully functional set of pipeline workflows and a starter application stack intended to help Agile DevOps teams hit the ground running. Currently OpenShift is supported with plans for AWS (Amazon Web Services). Pipelines are run using [GitHub Actions](https://github.com/bcgov/onroutebc/actions).
1515

16-
oc login [API_URL]
16+
Features:
17+
* Pull Request-based pipeline
18+
* Sandboxed development deployments
19+
* Gated production deployments
20+
* Container publishing (ghcr.io) and importing (OpenShift)
21+
* Security, vulnerability, infrastructure and container scan tools
22+
* Automatic Dependabot dependency patching with Pull Requests
23+
* Enforced code reviews and pipeline checks
24+
* Templates and setup documentation
25+
* Starter TypeScript application stack
1726

18-
to start a session against an OpenShift cluster. After login, run `oc` and
19-
`oc help` to learn more about how to get started with OpenShift.
27+
# Workflows
2028

21-
## License
29+
## Pull Request Opened
2230

23-
OpenShift is licensed under the Apache Public License 2.0. The source code for this
24-
program is [located on github](https://github.com/openshift/oc).
31+
Runs on pull request submission.
32+
33+
- Provides safe, sandboxed deployment environments
34+
- Build action pushes to GitHub Container Registry (ghcr.io)
35+
- Build triggers select new builds vs reusing builds
36+
- Deployment includes curl checks and optional penetration tests
37+
- Other checks and updates as required
38+
39+
![](common/graphics/pr-open.png)
40+
41+
## Pull Request Closed
42+
43+
Runs on pull request close or merge.
44+
45+
- Cleans up OpenShift objects/artifacts
46+
- Merge promotes successful build images to TEST
47+
48+
![](common/graphics/pr-close.png)
49+
50+
## Merge to Main
51+
52+
Runs on merge to main branch.
53+
54+
- Code scanning and reporting to GitHub Security overview
55+
- Zero-downtime* TEST deployment
56+
- Penetration tests on TEST deployment
57+
- Zero-downtime* PROD deployment
58+
- Labels successful deployment images as PROD
59+
60+
\* excludes database changes
61+
62+
![](common/graphics/merge-main.png)
63+
64+
## Unit Tests
65+
66+
Runs on pull request submission or merge to main.
67+
68+
- Unit tests (should include coverage)
69+
- Optionally, report results to Sonarcloud
70+
71+
![](common/graphics/unit-tests.png)
72+
73+
# Starter Application
74+
75+
The starter stack includes a frontend, backend and postgres database. The frontend and backend are buld with [NestJS](https://docs.nestjs.com). They currently do very little, but provide placeholders for more functional products. See subfolder for source, including Dockerfiles and OpenShift templates.
76+
77+
Features:
78+
* [TypeScript](https://www.typescriptlang.org/) strong-typing for JavaScript
79+
* [NestJS](https://docs.nestjs.com) frontend and backend
80+
* [Postgres](https://www.postgresql.org/) or [PostGIS](https://postgis.net/) database
81+
* [backup-container](https://github.com/BCDevOps/backup-container) provided by BCDevOps
82+
83+
Postgres is default. Switch to PostGIS by copying the appropriate Dockerfile to `./database`:
84+
85+
> cp ./database/postgis/Dockerfile ./database
86+
87+
Test and develop locally with Docker Compose:
88+
89+
> docker-compose up -d
90+
91+
**Example APIs, UIs and Metabase/Oracle Templates**
92+
93+
Templates for APIs, UIs and Metabase/Oracle can be used to kickstart or extend projects. Please visit our collaborators' [NR Architecture Templates](https://github.com/bcgov/nr-arch-templates) repository for more information.
94+
95+
# Getting Started
96+
97+
Initial setup is intended to take four hours or less. This depends greatly on intended complexity, features selected/excluded and outside cooperation.
98+
99+
## Prerequisites
100+
101+
The following are required:
102+
103+
* BC Government IDIR accounts for anyone submitting requests
104+
* GitHub accounts for all participating team members
105+
* [Sign Up is free](https://github.com/signup)
106+
* Membership in the BCGov GitHub organization
107+
* Provide GitHub IDs to [BCGov's Just Ask](https://just-ask.developer.gov.bc.ca/)
108+
* Project namespaces:
109+
* OpenShift - [Register a New Project](https://registry.developer.gov.bc.ca/public-landing)
110+
111+
112+
113+
## GitHub Repository from Template
114+
115+
Create a new repository using this repository as a template.
116+
117+
* Select bcgov/onroutebc under Repository template
118+
* Check Codecov | Code Coverage to grant access
119+
* Jira cannot be unchecked (I try every time!)
120+
121+
![](./common/graphics/template.png)
122+
123+
124+
## GitHub Secrets
125+
126+
Secrets are consumed by workflows. There are multiple kinds. Please expect to secrets to change across Environments, like PR/DEV, TEST and PROD. Even Dependabot has its own set.
127+
128+
### Repository
129+
130+
Repository secrets are available to all workflows, except pull requests triggered by Dependabot.
131+
132+
> Click Settings > Secrets > Actions > New repository secret
133+
134+
### Environment
135+
136+
Environments are groups of secrets that can be gatekept. This includes limting access to certain users or requiring manual approval before a requesting workflow can run.
137+
138+
> Click Settings > Environments > Environment Name / New environment > Add secret
139+
140+
Environements provide a [number of features](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment), including:
141+
142+
* Required reviewers
143+
* Wait timer
144+
* Deployment branches
145+
146+
### Dependabot
147+
148+
Dependabot secrets are used by Dependabot's pull requests. See [.github/dependabot.yml](./.github/dependabot.yml) for an example.
149+
150+
> Click Settings > Secrets > Dependabot > New repository secret
151+
152+
## Secret Values
153+
154+
**GITHUB_TOKEN**
155+
156+
Default token. Replaced every workflow run, available to all workflows.
157+
* Variable: `{{ secrets.GITHUB_TOKEN }}`
158+
159+
**OC_SERVER**
160+
161+
OpenShift server address.
162+
* Variable: `{{ secrets.OC_SERVER }}`
163+
* Value: `https://api.gold.devops.gov.bc.ca:6443` or `https://api.silver.devops.gov.bc.ca:6443`
164+
165+
**OC_NAMESPACE**
166+
167+
OpenShift project/namespace. Provided by your OpenShift platform team.
168+
169+
* Variable: `{{ secrets.OC_NAMESPACE }}`
170+
* Value: format `abc123-dev | test | prod`
171+
172+
**OC_TOKEN**
173+
174+
OpenShift token, different for every project/namespace. This guide assumes your OpenShift platform team has provisioned a pipeline account.
175+
176+
* Variable: `{{ secrets.OC_TOKEN }}`
177+
178+
Locate an OpenShift pipeline token:
179+
180+
1. Login to your OpenShift cluster, e.g.: [Gold](https://console.apps.silver.devops.gov.bc.ca/) or [Silver](https://console.apps.silver.devops.gov.bc.ca/)
181+
2. Select your DEV namespace
182+
3. Click Workloads > Secrets (under Workloads for Administrator view)
183+
4. Select `pipeline-token-...` or a similarly privileged token
184+
5. Under Data, copy `token`
185+
6. Paste into the GitHub Environment Secret `OC_TOKEN` (see above)
186+
187+
**Sonar Tokens**
188+
189+
If SonarCloud is being used each application will have its own token. Single-application repositories typically use `${{ secrets.SONAR_TOKEN }}`, but monoreposities will have multiple, like `${{ secrets.SONAR_TOKEN_BACKEND }}` and `${{ secrets.SONAR_TOKEN_FRONTEND }}`.
190+
191+
BC Government employees can request SonarCloud projects from [bcdevops/devops-requests](https://github.com/BCDevOps/devops-requests) by creating a SonarCloud request/[issue](https://github.com/BCDevOps/devops-requests/issues/new/choose). This template expects a monorepo, so please ask for that and provide component names (e.g. backend, frontend).
192+
193+
194+
## Repository Configuration
195+
196+
### Pull Request Handling
197+
198+
Squash merging is recommended for simplified history and ease of rollback. Cleaning up merged branches is recommended for your DevOps Specialist's fragile sanity.
199+
200+
> Click Settings > General (selected automatically)
201+
202+
Pull Requests:
203+
204+
- `[uncheck] Allow merge commits`
205+
- `[check] Allow squash merging`
206+
- `Default to pull request title`
207+
- `[uncheck] Allow rebase merging`
208+
- `[check] Always suggest updating pull request branches`
209+
- `[uncheck] Allow auto-merge`
210+
- `[check] Automatically delete head branches`
211+
212+
### Packages
213+
214+
Packages are available from your repository (link on right). All should have visibility set to public for the workflows to run successfully.
215+
216+
E.g. https://github.com/bcgov/onroutebc/packages
217+
218+
### Branch Protection
219+
220+
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.
221+
222+
1. Select Settings (gear, top right) -> Branches (under Code and Automation)
223+
2. Click `Add Rule` or edit an existing rule
224+
3. Under `Protect matching branches` specify the following:
225+
* Branch name pattern: `main`
226+
* `[check] Require a pull request before merging`
227+
* `[check] Require approvals` (default = 1)
228+
* `[check] Dismiss stale pull request approvals when new commits are pushed`
229+
* `[check] Require review from Code Owners`
230+
* `[check] Require status checks to pass before merging`
231+
* `[check] Require branches to be up to date before merging`
232+
* `Status checks that are required`:
233+
* Select checks as appropriate, e.g. Build x, Deploy y
234+
* `[check] Require conversation resolution before merging`
235+
* `[check] Include administrators` (optional)
236+
237+
### Adding Team Members
238+
239+
Don't forget to add your team members!
240+
241+
1. Select Settings (gear, top right) -> Collaborators and teams (under Access)
242+
2. Click `Add people` or `Add teams`
243+
3. Use the search box to find people or teams
244+
4. Choose a role (read, triage, write, maintain, admin)
245+
5. Click Add
246+
247+
# Feedback
248+
249+
Please contribute your ideas! [Issues] and [pull requests] are appreciated.
250+
251+
# Acknowledgements
252+
253+
This Action is provided courtesty of the Forestry Suite of Applications, part of the Government of British Columbia.

0 commit comments

Comments
 (0)