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

ci: backend #108

Merged
merged 27 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ba21a65
Workflow builds
DerekRoberts Sep 28, 2023
09b9e14
Dockerfile
DerekRoberts Sep 28, 2023
423a423
OpenShift template
DerekRoberts Sep 28, 2023
4127f82
PR description
DerekRoberts Sep 29, 2023
d02d530
Workflow deploys
DerekRoberts Sep 29, 2023
210edea
Workflows, including merge.yml
DerekRoberts Sep 29, 2023
5ae47c6
Remove db ref from backend/opeshift.deploy.yml
DerekRoberts Oct 3, 2023
6cb68e0
Cleanup references and names
DerekRoberts Oct 3, 2023
ad7aa88
Test just backend deploy
DerekRoberts Oct 3, 2023
9d15df5
Test just backend
DerekRoberts Oct 3, 2023
dcae8aa
+backend/.dockerignore
DerekRoberts Oct 4, 2023
497d2fc
Fix backend/Dockerfile
DerekRoberts Oct 4, 2023
b6df7bc
docker-compose.yml + backend-native
DerekRoberts Oct 4, 2023
5c41c72
Compose tweaks
DerekRoberts Oct 4, 2023
56c2971
Ports
DerekRoberts Oct 4, 2023
a214bf3
Deploy fix
DerekRoberts Oct 4, 2023
3a88ed4
Restore workflows
DerekRoberts Oct 4, 2023
784db6f
Compatibility mode
DerekRoberts Oct 4, 2023
a46cd6a
Verification path
DerekRoberts Oct 4, 2023
e33f153
Backend tests in workflows
DerekRoberts Oct 4, 2023
7d021bd
.github/workflows/unit-tests.yml -> .github/workflows/analysis.yml
DerekRoberts Oct 4, 2023
f31bdb5
.github/workflows/merge-main.yml -> .github/workflows/merge.yml
DerekRoberts Oct 4, 2023
7c9303a
Merge workflow
DerekRoberts Oct 4, 2023
9ebcb3f
Comment out backend tests
DerekRoberts Oct 4, 2023
17fa839
Try march=x86-64-v2
DerekRoberts Oct 4, 2023
8d8d14d
Fix DC VITE_USER_POOLS_ID
DerekRoberts Oct 4, 2023
312f2fc
Enable backend tests (w/ fails)
DerekRoberts Oct 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,40 +1,21 @@
name: Unit Tests and Analysis
name: Analysis

on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
types: [opened, reopened, synchronize, ready_for_review]
push:
branches:
- main
branches: [main]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
# Note: uncomment code below once a backend is written
tests:
name: Unit Tests
frontend:
name: Frontend Tests
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
runs-on: ubuntu-22.04
strategy:
matrix:
# dir: [backend, frontend]
dir: [frontend]
include:
# - dir: backend
# sonar_projectKey: nr-silva-backend
# token: SONAR_TOKEN_BACKEND
# triggers: ('backend/')
- dir: frontend
sonar_projectKey: nr-silva-frontend
token: SONAR_TOKEN_FRONTEND
triggers: ('frontend/')
steps:
- uses: bcgov-nr/[email protected]
with:
Expand All @@ -47,13 +28,34 @@ jobs:
-Dsonar.exclusions=**/coverage/**,**/node_modules/**,**/*spec.ts
-Dsonar.organization=bcgov-sonarcloud
-Dsonar.project.monorepo.enabled=true
-Dsonar.projectKey=${{ matrix.sonar_projectKey }}
-Dsonar.projectKey=nr-silva-frontend
-Dsonar.sources=src
-Dsonar.tests.inclusions=**/*spec.ts
-Dsonar.javascript.lcov.reportPaths=./coverage/lcov.info
sonar_token: ${{ secrets[matrix.token] }}
sonar_token: ${{ secrets.SONAR_TOKEN_FRONTEND }}
# Only use triggers for PRs
triggers: ${{ github.event_name == 'pull_request' && matrix.triggers || '' }}
triggers: ${{ github.event_name == 'pull_request' && '("frontend/")' || '' }}

backend:
name: Backend Tests
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
runs-on: ubuntu-22.04
steps:
- uses: bcgov-nr/[email protected]
with:
commands: mvn clean package
dir: backend
java-cache: maven
java-distribution: temurin
java-version: 17
sonar_args: >
-Dsonar.exclusions=**/coverage/**,**/node_modules/**,**/*spec.ts
-Dsonar.organization=bcgov-sonarcloud
-Dsonar.project.monorepo.enabled=true
-Dsonar.projectKey=nr-silva-backend
-Dsonar.sources=src
sonar_token: ${{ secrets.SONAR_TOKEN_BACKEND }}
triggers: ${{ github.event_name == 'pull_request' && '("backend/")' || '' }}

# https://github.com/marketplace/actions/aqua-security-trivy
trivy:
Expand Down
48 changes: 30 additions & 18 deletions .github/workflows/merge-main.yml → .github/workflows/merge.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: Merge to Main
name: Merge

on:
workflow_run:
workflows: [ "Pull Request Closed" ]
types:
- completed
types: [completed]
workflow_dispatch:

concurrency:
Expand Down Expand Up @@ -41,49 +40,62 @@ jobs:
runs-on: ubuntu-22.04
permissions:
issues: write
strategy:
matrix:
name: [backend, frontend]
include:
- name: backend
- name: frontend
parameters:
-p VITE_USER_POOLS_ID=${{ vars.VITE_USER_POOLS_ID }}
-p VITE_USER_POOLS_WEB_CLIENT_ID=${{ vars.VITE_USER_POOLS_WEB_CLIENT_ID }}
steps:
- uses: bcgov-nr/[email protected]
with:
file: frontend/openshift.deploy.yml
file: ${{ matrix.name }}/openshift.deploy.yml
oc_namespace: ${{ vars.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
overwrite: true
parameters:
-p ZONE=test -p PROMOTE=${{ github.repository }}/frontend:test
-p ZONE=test -p PROMOTE=${{ github.repository }}/${{ matrix.name }}:test
-p NAME=${{ github.event.repository.name }}
-p VITE_USER_POOLS_ID=${{ vars.VITE_USER_POOLS_ID }}
-p VITE_USER_POOLS_WEB_CLIENT_ID=${{ vars.VITE_USER_POOLS_WEB_CLIENT_ID }}
${{ matrix.parameters }}
penetration_test: true
penetration_test_artifact: frontend
penetration_test_issue: frontend
penetration_test_artifact: ${{ matrix.name }}
penetration_test_issue: ${{ matrix.name }}
penetration_test_token: ${{ secrets.GITHUB_SECRET }}

deploys-prod:
name: PROD Deployments
needs:
- deploys-test
needs: [deploys-test]
environment: prod
runs-on: ubuntu-22.04
strategy:
matrix:
name: [backend, frontend]
include:
- name: backend
paratemeters:
-p VITE_USER_POOLS_ID=${{ vars.VITE_USER_POOLS_ID }}
-p VITE_USER_POOLS_WEB_CLIENT_ID=${{ vars.VITE_USER_POOLS_WEB_CLIENT_ID }}
-p VITE_REDIRECT_SIGN_OUT="${{ vars.VITE_REDIRECT_SIGN_OUT }}"
- name: frontend
steps:
- uses: bcgov-nr/[email protected]
with:
file: frontend/openshift.deploy.yml
file: ${{ matrix.name }}/openshift.deploy.yml
oc_namespace: ${{ vars.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
overwrite: true
parameters:
-p ZONE=prod -p PROMOTE=${{ github.repository }}/frontend:test
-p ZONE=prod -p PROMOTE=${{ github.repository }}/${{ matrix.name }}:test
-p NAME=${{ github.event.repository.name }}
-p VITE_USER_POOLS_ID=${{ vars.VITE_USER_POOLS_ID }}
-p VITE_USER_POOLS_WEB_CLIENT_ID=${{ vars.VITE_USER_POOLS_WEB_CLIENT_ID }}
-p VITE_REDIRECT_SIGN_OUT="${{ vars.VITE_REDIRECT_SIGN_OUT }}"

image-promotions:
name: Promote images to PROD
needs:
- deploys-prod
needs: [deploys-prod]
runs-on: ubuntu-22.04
permissions:
packages: write
Expand Down
43 changes: 32 additions & 11 deletions .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ name: Pull Request

on:
pull_request:
branches:
- main
branches: [main]

concurrency:
# PR open and close use the same group, allowing only one at a time
Expand Down Expand Up @@ -32,6 +31,7 @@ jobs:
Thanks for the PR!

Any successful deployments (not always required) will be available below.
[Backend](https://${{ env.PREFIX }}-backend.${{ env.DOMAIN }})
[Frontend](https://${{ env.PREFIX }}-frontend.${{ env.DOMAIN }})

Once merged, code will be promoted and handed off to following workflow run.
Expand All @@ -43,34 +43,55 @@ jobs:
runs-on: ubuntu-22.04
permissions:
packages: write
strategy:
matrix:
name: [backend, frontend]
include:
- name: backend
triggers: ('backend/')
- name: frontend
triggers: ('frontend/')
steps:
- uses: actions/checkout@v4
- uses: bcgov-nr/[email protected]
with:
package: frontend
package: ${{ matrix.name }}
tag: ${{ github.event.number }}
tag_fallback: test
token: ${{ secrets.GITHUB_TOKEN }}
triggers: ('frontend/')
triggers: ${{ matrix.triggers }}

deploys:
name: Deploys
if: "!github.event.pull_request.head.repo.fork"
needs:
- builds
needs: [builds]
runs-on: ubuntu-22.04
strategy:
matrix:
name: [backend, frontend]
include:
- name: backend
file: backend/openshift.deploy.yml
triggers: ('backend/' 'frontend/')
verification_path: /actuator/health
- name: frontend
file: frontend/openshift.deploy.yml
triggers: ('backend/' 'frontend/')
parameters:
-p VITE_USER_POOLS_ID=${{ vars.VITE_USER_POOLS_ID }}
-p VITE_USER_POOLS_WEB_CLIENT_ID=${{ vars.VITE_USER_POOLS_WEB_CLIENT_ID }}
steps:
- uses: bcgov-nr/[email protected]
with:
file: frontend/openshift.deploy.yml
file: ${{ matrix.name }}/openshift.deploy.yml
oc_namespace: ${{ vars.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
overwrite: true
parameters:
-p ZONE=${{ github.event.number }} -p NAME=${{ github.event.repository.name }}
-p PROMOTE=${{ github.repository }}/frontend:${{ github.event.number }}
-p VITE_USER_POOLS_ID=${{ vars.VITE_USER_POOLS_ID }}
-p VITE_USER_POOLS_WEB_CLIENT_ID=${{ vars.VITE_USER_POOLS_WEB_CLIENT_ID }}
-p PROMOTE=${{ github.repository }}/${{ matrix.name }}:${{ github.event.number }}
-p MIN_REPLICAS=1 -p MAX_REPLICAS=2
triggers: ('frontend/')
${{ matrix.parameters }}
triggers: ${{ matrix.triggers }}
verification_path: ${{ matrix.verification_path }}
6 changes: 6 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.env
Dockerfile
*.yml
*.yaml
*.md
**/target/
21 changes: 21 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Quarkus Images
# https://github.com/quarkusio/quarkus-images

# "Provides the native-image executable. Used by the Maven and Gradle plugin from Quarkus to build linux64 executables"
FROM quay.io/quarkus/ubi-quarkus-graalvmce-builder-image:jdk-21 AS build

# Image defaults to /project; copy controlled by .dockerignore
COPY --chown=quarkus:quarkus . ./
RUN ./mvnw package -Pnative -DskipTests

# "A base image to run Quarkus native application using UBI Micro"
FROM quay.io/quarkus/quarkus-micro-image:2.0

# Port and health check
EXPOSE 8080
HEALTHCHECK --interval=300s --timeout=3s CMD curl -f http://localhost:8080

# Startup
COPY --chown=1001:root --from=build /project/target/results /app
USER 1001
CMD ["/app", "-Dquarkus.http.host=0.0.0.0"]
Loading
Loading