Skip to content

Commit

Permalink
Merge branch 'main' into DEVX-1608
Browse files Browse the repository at this point in the history
  • Loading branch information
MonicaG authored Nov 26, 2024
2 parents 2880117 + 9a7f4c5 commit 7510f15
Show file tree
Hide file tree
Showing 38 changed files with 7,093 additions and 7,023 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.yarn/install-state.gz
**/dist
**/node_modules
*.local.yaml
*.local.*
coverage
dist-types
examples
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and update gitops repo for pull-request
name: Build and optionally update gitops repo for a pull-request

env:
TARGET_FILE: 'values.pr.yaml'
Expand All @@ -17,39 +17,49 @@ concurrency:
cancel-in-progress: true

jobs:
should-run:
get-build-mode:
runs-on: ubuntu-latest
outputs:
SHOULD_RUN: ${{ steps.should_run.outputs.SHOULD_RUN }}
SHOULD_BUILD: ${{ steps.build_mode.outputs.SHOULD_BUILD }}
SHOULD_BUILD_DEPLOY: ${{ steps.build_mode.outputs.SHOULD_BUILD_DEPLOY }}
steps:
- name: Check if this workflow should run
id: should_run
# Check if this workflow should build and optionally deploy. Deployment cannot happen without a build
- name: Determine if should build and deploy
id: build_mode
run: |
should_run=false
if ${{ contains(github.event.pull_request.labels.*.name, 'preview') && github.event.pull_request.state == 'open' }} ; then
should_run=true
should_build=false
should_build_deploy=false
if ${{ github.event.pull_request.state == 'open' }} ; then
if ${{ contains(github.event.pull_request.labels.*.name, 'build' )}} ; then
should_build=true
fi
if ${{ contains(github.event.pull_request.labels.*.name, 'preview') }}; then
should_build_deploy=true
fi
fi
echo "SHOULD_RUN=$should_run" >> "$GITHUB_OUTPUT"
echo "SHOULD_BUILD=$should_build" >> "$GITHUB_OUTPUT"
echo "SHOULD_BUILD_DEPLOY=$should_build_deploy" >> "$GITHUB_OUTPUT"
call-build-workflow:
needs: should-run
if: needs.should-run.outputs.SHOULD_RUN == 'true'
needs: get-build-mode
if: ${{ (needs.get-build-mode.outputs.SHOULD_BUILD == 'true') || (needs.get-build-mode.outputs.SHOULD_BUILD_DEPLOY == 'true') }}
uses: ./.github/workflows/build.yaml

get-short-sha:
needs: should-run
if: needs.should-run.outputs.SHOULD_RUN == 'true'
needs: get-build-mode
if: needs.get-build-mode.outputs.SHOULD_BUILD_DEPLOY == 'true'
uses: ./.github/workflows/get-short-sha.yaml

get-pr-branch-name:
needs: should-run
if: needs.should-run.outputs.SHOULD_RUN == 'true'
needs: get-build-mode
if: needs.get-build-mode.outputs.SHOULD_BUILD_DEPLOY == 'true'
uses: ./.github/workflows/get-pr-branch-name.yaml

update-gitops-pr-file:
if: needs.should-run.outputs.SHOULD_RUN == 'true'
if: needs.get-build-mode.outputs.SHOULD_BUILD_DEPLOY == 'true'
runs-on: ubuntu-latest
needs: [call-build-workflow, get-short-sha, get-pr-branch-name, should-run]
needs:
[call-build-workflow, get-short-sha, get-pr-branch-name, get-build-mode]

steps:
- name: Setup gitops repo access
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
- '.github/**'
- 'README.md'
- '.husky/**'
- 'catalog-info.yaml'
- '**/*.md'
- 'examples/**'
branches: ['main']

# save resources. Don't take up a queue space doing a duplicate build
Expand Down
32 changes: 11 additions & 21 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
# Builds the docker image.
# Note: This workflow is expected to be called by other workflows and not run on its own

name: Build Image

env:
REGISTRY: ghcr.io
REPOSITORY_NAME: developer-experience/developer-portal
REPOSITORY_NAME: ${{ github.repository_owner }}/developer-experience/developer-portal

on:
workflow_call:
paths-ignore:
- 'catalog-info.yaml'
- '**/*.md'
- 'examples/**'

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Delete unnecessary files
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- name: Checkout
uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/${{ env.REPOSITORY_NAME }}
images: ${{ env.REGISTRY }}/${{ env.REPOSITORY_NAME }}
# Always generate latest tag (https://github.com/docker/metadata-action#latest-tag)
flavor: latest=true
# Sha tag is used in udpate_deploy_file job below
Expand All @@ -43,21 +35,19 @@ jobs:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- # Support for multiplatform build. Using for dev debugging
name: Set up QEMU
uses: docker/setup-qemu-action@v3

- # Support for multiplatform build. Using for dev debugging
name: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build container
uses: docker/build-push-action@v6
env:
CACHE_TAG: buildcache
with:
context: .
file: packages/backend/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ env.CACHE_TAG }}
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ env.CACHE_TAG }},mode=max
8 changes: 6 additions & 2 deletions .github/workflows/delete-gitops-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ jobs:
with:
ssh-key: ${{ secrets.MANIFEST_REPO_DEPLOY_KEY }}
repository: ${{ secrets.MANIFEST_REPO }}
fetch-depth: 0 # get all branches. Needed for deleting gitops branch


- name: Delete branch in gitops
run: |
git push origin --delete ${{ needs.get-pr-branch-name.outputs.BRANCH_NAME }}
if git rev-parse --verify --quiet origin/${{ needs.get-pr-branch-name.outputs.BRANCH_NAME }}; then
git push origin --delete ${{ needs.get-pr-branch-name.outputs.BRANCH_NAME }}
else
echo "Branch ${{ needs.get-pr-branch-name.outputs.BRANCH_NAME }} already does not exist"
fi
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ site
# Local configuration or documentation files
*.local.*

# Except template local file
!app-config.local.template.yaml

# bak up files
*.bak

Expand Down
32 changes: 15 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,38 @@
[![Package Status](https://github.com/bcgov/developer-portal/actions/workflows/update-gitops.yaml/badge.svg)](https://github.com/bcgov/developer-portal/actions/workflows/update-gitops.yaml)
[![CodeQL](https://github.com/bcgov/developer-portal/workflows/CodeQL/badge.svg)](https://github.com/bcgov/developer-portal/actions/workflows/github-code-scanning/codeql)

This is the [developer portal for the Province of British Columbia](https://developer.gov.bc.ca) built using [Backstage](https://backstage.io).
This is the [developer portal for the Province of British Columbia](https://developer.gov.bc.ca) built using [Backstage](https://backstage.io).

## Local Development

### Required Tools
* Node [long-term-support version](https://nodejs.dev/en/about/releases/) (i.e. lts/hydrogen)

- Node [long-term-support version](https://nodejs.dev/en/about/releases/) (i.e. lts/hydrogen)

### Setup
* For development purposes, the in memory SQLite database is sufficient (it is already configured)
* Alternativley, [Postgres](https://www.postgresql.org) can be configured
* Install [Postgres locally](https://www.postgresql.org/download/) or via [docker](https://hub.docker.com/_/postgres)
* Create an `app-config.local.yaml` file in the project's root directory and provide the following configurations:
```yaml
database:
client: pg
connection:
host: ${POSTGRES_HOST}
port: ${POSTGRES_PORT}
user: ${POSTGRES_USER}
password: ${POSTGRES_PASSWORD}
```

- For development purposes, the in memory SQLite database is sufficient (it is already configured)
- Alternativley, [Postgres](https://www.postgresql.org) can be configured
- Install [Postgres locally](https://www.postgresql.org/download/) or via [docker](https://hub.docker.com/_/postgres)
- Create an `app-config.local.yaml` file based off of the [app-config.local.template.yaml](app-config.local.template.yaml) file.

### Running

To run the project, use the following at the project's root directory

```
$ yarn install
$ yarn dev
```
### Dockerfile

### Dockerfile

Note: The dockerfile is based on the [Janus showcase project](https://github.com/janus-idp/backstage-showcase/)

### Deployment

### Deployment
See the [gitops repo](https://github.com/bcgov-c/tenant-gitops-f5ff48).

### More information

See the [Backstage.io documentation](https://backstage.io/docs/getting-started/)
65 changes: 65 additions & 0 deletions app-config.local.template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Use this template to create your own app-config.local.yaml file
# See one of the devs on how to get the values for the env variables

# Uncomment to use POSTGRES. The below config assumes postgres is running locally.
# backend:
# database:
# client: pg
# connection:
# host: localhost
# port: 5432
# password: ${POSTGRES_PASSWORD}
# user: ${POSTGRES_USER}

integrations:
github:
- host: github.com
token: ${GITHUB_TOKEN}

stackoverflow:
baseUrl: https://stackoverflow.developer.gov.bc.ca/api/2.3
apiKey: ${STACK_OVERFLOW_API_KEY}
requestParams:
pagesize: 100
site: stackoverflow

auth:
environment: development
providers:
guest:
userEntityRef: user:default/guest
dangerouslyAllowOutsideDevelopment: true
github:
development:
clientId: ${AUTH_GITHUB_CLIENT_ID}
clientSecret: ${AUTH_GITHUB_CLIENT_SECRET}
signIn:
resolvers:
- resolver: usernameMatchingUserEntityName

techdocs:
builder: 'external'
generator:
runIn: 'local'
publisher:
type: 'awsS3'
awsS3:
bucketName: backstage
bucketRootPath: dev
credentials:
accessKeyId: ${TECHDOCS_S3_ACCESS_KEY_ID}
secretAccessKey: ${TECHDOCS_S3_SECRET_ACCESS_KEY}
endpoint: ${TECHDOCS_S3_ENDPOINT}
region: ca-central-1
s3ForcePathStyle: true

catalog:
locations:
- type: url
target: https://github.com/bcgov/developer-experience-team/blob/main/developer-portal/catalog/catalog-seed-dev.yml
rules:
- allow: [Component]
- type: url
target: https://github.com/bcgov/developer-experience-team/blob/main/developer-portal/catalog/templates-seed-dev.yml
rules:
- allow: [Template]
65 changes: 44 additions & 21 deletions app-config.production.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,51 @@
backend:
# config options: https://node-postgres.com/apis/client
database:
client: pg
connection:
host: ${POSTGRES_HOST}
password: ${POSTGRES_PASSWORD}
port: ${POSTGRES_PORT}
user: ${POSTGRES_USER}
# config options: https://node-postgres.com/apis/client
database:
client: pg
connection:
host: ${POSTGRES_HOST}
password: ${POSTGRES_PASSWORD}
port: ${POSTGRES_PORT}
user: ${POSTGRES_USER}
catalog:
import:
entityFilename: catalog-info.yaml
pullRequestBranchName: backstage-integration
rules:
- allow: [ Component, System, API, Resource, Location ]
locations:
- type: url
target: https://github.com/bcgov/developer-experience-team/blob/main/developer-portal/catalog/catalog-seed-production.yml
rules:
- allow: [ Component ]
import:
entityFilename: catalog-info.yaml
pullRequestBranchName: backstage-integration
rules:
- allow: [Component, System, API, Resource, Location]
locations:
- type: url
target: https://github.com/bcgov/developer-experience-team/blob/main/developer-portal/catalog/catalog-seed-production.yml
rules:
- allow: [Component]
search:
collators:
catalog:
schedule: # same options as in SchedulerServiceTaskScheduleDefinition
# supports cron, ISO duration, "human duration" as used in code
initialDelay: { seconds: 3 }
frequency: { minutes: 10 }
timeout: { minutes: 15 }
filter:
kind: ['API', 'Component', 'Domain', 'Group', 'Resource', 'System', 'User']
kind:
['API', 'Component', 'Domain', 'Group', 'Resource', 'System', 'User']
stackoverflow:
baseUrl: ${STACK_OVERFLOW_URL}
apiKey: ${STACK_OVERFLOW_API_KEY}
baseUrl: ${STACK_OVERFLOW_URL}
apiKey: ${STACK_OVERFLOW_API_KEY}
requestParams:
pagesize: 100
site: stackoverflow

auth:
environment: default
providers:
guest:
userEntityRef: user:default/guest
dangerouslyAllowOutsideDevelopment: true
github:
default:
clientId: ${AUTH_GITHUB_CLIENT_ID}
clientSecret: ${AUTH_GITHUB_CLIENT_SECRET}
signIn:
resolvers:
- resolver: usernameMatchingUserEntityName
10 changes: 10 additions & 0 deletions app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,13 @@ techdocs:
allowedIframeHosts:
- www.youtube.com
- miro.com

catalog:
providers:
githubOrg:
- id: production
githubUrl: 'https://github.com'
orgs: ['bcgov', 'bcgov-public']
schedule:
frequency: { minutes: 60 }
timeout: { minutes: 15 }
2 changes: 1 addition & 1 deletion backstage.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "1.28.4"
"version": "1.32.4"
}
Loading

0 comments on commit 7510f15

Please sign in to comment.