Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): builds #12

Merged
merged 16 commits into from
Oct 11, 2024
Merged
73 changes: 73 additions & 0 deletions .github/workflows/.deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: .Deploys

on:
workflow_call:
inputs:
environment:
description: GitHub environment; e.g. PR number (omit), TEST or PROD
required: false
type: string
tag:
description: Image tag; e.g. PR number or latest
default: ${{ github.event.number }}
required: false
type: string
target:
description: Deployment target; e.g. PR number (omit), test or prod
default: ${{ github.event.number }}
required: false
type: string

jobs:
database:
name: Database
environment: ${{ inputs.environment }}
runs-on: ubuntu-22.04
steps:
- name: Deploy Database
uses: bcgov-nr/[email protected]
with:
oc_namespace: ${{ vars.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
file: database/openshift.deploy.yml
overwrite: false
parameters:
-p TAG=${{ inputs.tag }} -p TARGET=${{ inputs.target }}

backend:
name: Backend
needs: [database]
environment: ${{ inputs.environment }}
runs-on: ubuntu-22.04
steps:
- name: Deploy Backend
uses: bcgov-nr/[email protected]
with:
oc_namespace: ${{ vars.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
file: backend/openshift.deploy.yml
overwrite: true
parameters:
-p TAG=${{ inputs.tag }} -p TARGET=${{ inputs.target }}
verification_path: /api/health
verification_retry_attempts: "5"
verification_retry_seconds: "15"

frontend:
name: Frontend
needs: [backend]
environment: ${{ inputs.environment }}
runs-on: ubuntu-22.04
steps:
- name: Deploy Frontend
uses: bcgov-nr/[email protected]
with:
oc_namespace: ${{ vars.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
file: frontend/openshift.deploy.yml
overwrite: true
parameters:
-p TAG=${{ inputs.tag }} -p TARGET=${{ inputs.target }}
86 changes: 43 additions & 43 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,48 @@ concurrency:
cancel-in-progress: true

jobs:
tests:
name: Tests
if: ${{ ! github.event.pull_request.draft }}
runs-on: ubuntu-22.04
timeout-minutes: 5
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
strategy:
matrix:
dir: [backend, frontend]
include:
- dir: backend
token: SONAR_TOKEN_BACKEND
- dir: frontend
token: SONAR_TOKEN_FRONTEND
steps:
- uses: bcgov-nr/[email protected]
with:
commands: |
npm ci
npm run test:cov
dir: ${{ matrix.dir }}
node_version: "22"
sonar_args: >
-Dsonar.exclusions=**/coverage/**,**/node_modules/**,**/*spec.ts
-Dsonar.organization=bcgov-sonarcloud
-Dsonar.projectKey=quickstart-openshift_${{ matrix.dir }}
-Dsonar.sources=src
-Dsonar.tests.inclusions=**/*spec.ts
-Dsonar.javascript.lcov.reportPaths=./coverage/lcov.info
sonar_token: ${{ secrets[matrix.token] }}
triggers: ('${{ matrix.dir }}/')
# tests:
# name: Tests
# if: ${{ ! github.event.pull_request.draft }}
# runs-on: ubuntu-22.04
# timeout-minutes: 5
# services:
# postgres:
# image: postgres
# env:
# POSTGRES_PASSWORD: postgres
# options: >-
# --health-cmd pg_isready
# --health-interval 10s
# --health-timeout 5s
# --health-retries 5
# ports:
# - 5432:5432
# strategy:
# matrix:
# dir: [backend, frontend]
# include:
# - dir: backend
# token: SONAR_TOKEN_BACKEND
# - dir: frontend
# token: SONAR_TOKEN_FRONTEND
# steps:
# - uses: bcgov-nr/[email protected]
# with:
# commands: |
# npm ci
# npm run test:cov
# dir: ${{ matrix.dir }}
# node_version: "22"
# sonar_args: >
# -Dsonar.exclusions=**/coverage/**,**/node_modules/**,**/*spec.ts
# -Dsonar.organization=bcgov-sonarcloud
# -Dsonar.projectKey=quickstart-openshift_${{ matrix.dir }}
# -Dsonar.sources=src
# -Dsonar.tests.inclusions=**/*spec.ts
# -Dsonar.javascript.lcov.reportPaths=./coverage/lcov.info
# sonar_token: ${{ secrets[matrix.token] }}
# triggers: ('${{ matrix.dir }}/')

# https://github.com/marketplace/actions/aqua-security-trivy
trivy:
Expand All @@ -82,7 +82,7 @@ jobs:

results:
name: Analysis Results
needs: [tests, trivy]
# needs: [tests, trivy]
if: always()
runs-on: ubuntu-22.04
steps:
Expand Down
80 changes: 40 additions & 40 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,44 @@ jobs:
uses: bcgov-nr/[email protected]

# https://github.com/bcgov/quickstart-openshift-helpers
deploy-test:
name: Deploy (test)
uses: bcgov/quickstart-openshift-helpers/.github/workflows/[email protected]
secrets:
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_token: ${{ secrets.OC_TOKEN }}
with:
environment: test
# deploy-test:
# name: Deploy (test)
# uses: bcgov/quickstart-openshift-helpers/.github/workflows/[email protected]
# secrets:
# oc_namespace: ${{ secrets.OC_NAMESPACE }}
# oc_token: ${{ secrets.OC_TOKEN }}
# with:
# environment: test

deploy-prod:
name: Deploy (prod)
needs: [deploy-test, vars]
uses: bcgov/quickstart-openshift-helpers/.github/workflows/[email protected]
secrets:
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_token: ${{ secrets.OC_TOKEN }}
with:
environment: prod
params:
--set backend.deploymentStrategy=RollingUpdate
--set frontend.deploymentStrategy=RollingUpdate
--set global.autoscaling=true
--set frontend.pdb.enabled=true
--set backend.pdb.enabled=true
promote:
name: Promote Images
needs: [deploy-prod, vars]
runs-on: ubuntu-22.04
permissions:
packages: write
strategy:
matrix:
package: [migrations, backend, frontend]
timeout-minutes: 1
steps:
- uses: shrink/actions-docker-registry-tag@v4
with:
registry: ghcr.io
repository: ${{ github.repository }}/${{ matrix.package }}
target: ${{ needs.vars.outputs.pr }}
tags: prod
# deploy-prod:
# name: Deploy (prod)
# needs: [deploy-test, vars]
# uses: bcgov/quickstart-openshift-helpers/.github/workflows/[email protected]
# secrets:
# oc_namespace: ${{ secrets.OC_NAMESPACE }}
# oc_token: ${{ secrets.OC_TOKEN }}
# with:
# environment: prod
# params:
# --set backend.deploymentStrategy=RollingUpdate
# --set frontend.deploymentStrategy=RollingUpdate
# --set global.autoscaling=true
# --set frontend.pdb.enabled=true
# --set backend.pdb.enabled=true
# promote:
# name: Promote Images
# needs: [deploy-prod, vars]
# runs-on: ubuntu-22.04
# permissions:
# packages: write
# strategy:
# matrix:
# package: [migrations, backend, frontend]
# timeout-minutes: 1
# steps:
# - uses: shrink/actions-docker-registry-tag@v4
# with:
# registry: ghcr.io
# repository: ${{ github.repository }}/${{ matrix.package }}
# target: ${{ needs.vars.outputs.pr }}
# tags: prod
34 changes: 13 additions & 21 deletions .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
package: [backend, frontend, migrations]
timeout-minutes: 10
package: [database, backend, frontend]
timeout-minutes: 20
steps:
- uses: bcgov-nr/[email protected]
with:
Expand All @@ -28,31 +28,23 @@ jobs:

# https://github.com/bcgov/quickstart-openshift-helpers
deploys:
name: Deploys
name: Deploy
needs: [builds]
uses: bcgov/quickstart-openshift-helpers/.github/workflows/[email protected]
secrets:
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_token: ${{ secrets.OC_TOKEN }}
with:
triggers: ('backend/' 'frontend/' 'migrations/')
params:
--set global.secrets.persist=false
secrets: inherit
uses: ./.github/workflows/.deploy.yml

tests:
name: Tests
if: needs.deploys.outputs.triggered == 'true'
needs: [deploys]
uses: ./.github/workflows/.tests.yml
with:
target: ${{ github.event.number }}
# tests:
# name: Tests
# if: needs.deploys.outputs.triggered == 'true'
# needs: [deploys]
# uses: ./.github/workflows/.tests.yml
# with:
# target: ${{ github.event.number }}

results:
name: PR Results
needs: [builds, deploys, tests]
needs: [builds, deploys]
if: always()
runs-on: ubuntu-22.04
steps:
- if: contains(needs.*.result, 'failure')
run: echo "At least one job has failed." && exit 1
- run: echo "Success!"
2 changes: 1 addition & 1 deletion backend/openshift.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Template
parameters:
- name: APP
description: Application name
value: nr-sustainment-capstone-2024
value: nr-nmp
- name: COMPONENT
description: Component name
value: backend
Expand Down
2 changes: 1 addition & 1 deletion database/openshift.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Template
parameters:
- name: APP
description: Application name
value: nr-sustainment-capstone-2024
value: nr-nmp
- name: COMPONENT
description: Component name
value: database
Expand Down
23 changes: 19 additions & 4 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
# Base image for the container
FROM node:20.17.0

# Set environment variables
ENV npm_config_cache=/app/.npm
ENV APP_USER=1011540000

# Create user and group
RUN groupadd --gid ${APP_USER} appGroup && \
useradd --uid ${APP_USER} --gid appGroup --home /app ${APP_USER}

# Copy files, install dependencies and build
# Switch to the new user
USER ${APP_USER}

# Set the working directory
WORKDIR /app/

# Copy package.json and package-lock.json first to leverage Docker cache
COPY --chown=${APP_USER} package.json package-lock.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application code
COPY --chown=${APP_USER} . ./
RUN npm i && \
npm run build

# Run in production mode, `npm run dev` for dev mode
# Ensure TypeScript is installed and compile the project
RUN npm run build

# Expose the port that the app runs on
EXPOSE 5173

# Run the application in production mode
CMD ["npm", "run", "serve", "--no-update-notifier", "--max-old-space-size=50"]
4 changes: 2 additions & 2 deletions frontend/openshift.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Template
parameters:
- name: APP
description: Application name
value: nr-sustainment-capstone-2024
value: nr-nmp
- name: COMPONENT
description: Component name
value: frontend
Expand Down Expand Up @@ -101,7 +101,7 @@ objects:
app: ${APP}-${TARGET}
name: ${APP}-${TARGET}-${COMPONENT}
spec:
host: better-berries-${TARGET}.apps.silver.devops.gov.bc.ca
host: nr-nmp-${TARGET}.apps.silver.devops.gov.bc.ca
port:
targetPort: http-5173
to:
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import App from './App';
import MainPage from './Views/MainPage/MainPage.tsx';
import ExportPage from './Views/Export/ExportPage.tsx';

// Test for openshift
// Test
const router = createBrowserRouter([
{
path: '/',
Expand Down
Loading