Skip to content

Commit

Permalink
changes to deploy to openshift for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
mishraomp committed Jul 29, 2024
1 parent 23da26f commit 1b21709
Show file tree
Hide file tree
Showing 18 changed files with 472 additions and 10 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/on-pr.yml → .github/workflows/merge.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: Deploy to GitHub Pages On PR

on:
# Trigger the workflow every time you push to the `main` branch
# Using a different branch name? Replace `main` with your branch’s name
pull_request:
branches: [ main ]
push:
branches:
- main

# Allow this job to clone the repo and create a page deployment
permissions:
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/pr-close.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: PR Closed

on:
pull_request:
types: [closed]

concurrency:
# PR open and close use the same group, allowing only one at a time
group: ${{ github.event.number }}
cancel-in-progress: true

jobs:
cleanup:
name: Cleanup and Images
uses: bcgov/quickstart-openshift-helpers/.github/workflows/[email protected]
secrets:
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_token: ${{ secrets.OC_TOKEN }}
with:
cleanup: helm
packages: air-quality-statements
37 changes: 37 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Deploy to OpenShift On PR

on:
# Trigger the workflow every time you push to the `main` branch
# Using a different branch name? Replace `main` with your branch’s name
pull_request:
branches: [ main ]


jobs:
# https://github.com/bcgov-nr/action-builder-ghcr
builds:
name: Builds
runs-on: ubuntu-22.04
strategy:
matrix:
package: [air-quality-statements]
timeout-minutes: 10
steps:
- uses: bcgov-nr/[email protected]
with:
package: ${{ matrix.package }}
tag: ${{ github.event.number }}
tag_fallback: latest
triggers: ('${{ matrix.package }}/')

# https://github.com/bcgov/quickstart-openshift-helpers
deploys:
name: Deploys
needs: [builds]
uses: bcgov/quickstart-openshift-helpers/.github/workflows/[email protected]
secrets:
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_token: ${{ secrets.OC_TOKEN }}
oc_server: ${{ vars.OC_SERVER }}
with:
environment: dev
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# Gitignore template for Astro projects
# Ignore content collection generated files
.astro
dist/** */
node_modules/** */
dist
node_modules
.idea
air-quality-statements/.astro
air-quality-statements/dist
air-quality-statements/node_modules
air-quality-statements/.idea

40 changes: 40 additions & 0 deletions air-quality-statements/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
auto_https off
admin 0.0.0.0:3002
servers {
metrics
}
}
:3000 {
log {
output stdout
format console {
time_format iso8601
level_format color
}
level info
}
encode gzip

handle {
root * /app/dist
try_files {path} {path}/ /index.html
file_server
}
header {
X-Frame-Options "SAMEORIGIN"
X-XSS-Protection "1;mode=block"
Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate"
X-Content-Type-Options "nosniff"
Strict-Transport-Security "max-age=31536000"
Content-Security-Policy https://raw.githubusercontent.com/bcgov/* "default-src 'self' *.devops.gov.bc.ca data:; script-src 'self' 'unsafe-eval' https://www2.gov.bc.ca ;style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://use.fontawesome.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: https://fonts.googleapis.com http://www.w3.org"
Referrer-Policy "same-origin"
Feature-Policy "fullscreen 'self'; camera 'none'; microphone 'none'"
}
}

:3001 {
handle /health {
respond "OK"
}
}
23 changes: 23 additions & 0 deletions air-quality-statements/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Build static files
FROM node:alpine AS build

WORKDIR /app
COPY . .
RUN npm i --ignore-scripts && \
npm run build

# Caddy
FROM caddy:2.7-alpine

# Copy static files and config
COPY --from=build /app/build /app/dist
COPY Caddyfile /etc/caddy/Caddyfile

# Packages and caddy format
RUN apk add --no-cache ca-certificates && \
caddy fmt --overwrite /etc/caddy/Caddyfile

# Port, health check and non-root user
EXPOSE 3000 3001
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost/:3001/health
USER 1001
6 changes: 4 additions & 2 deletions air-quality-statements/src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import "@bcgov/bc-sans/css/BC_Sans.css";
import Header from "../components/Header";
import Footer from "../components/Footer";
import Search from "astro-pagefind/components/Search";
import { ViewTransitions } from 'astro:transitions';
const { title } = Astro.props;
---

<html lang="en">
<html lang="en" transition:animate="fade">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" href="/favicon.ico" />
<title>{title}</title>

</head>
<style>
body {
Expand All @@ -26,7 +28,7 @@ const { title } = Astro.props;
}
</style>
<body>
<Header titleElement="h3" title="Air Quality Statements" ><Search id="search" className="pagefind-ui" uiOptions={{ showImages: false }} /></Header>
<Header titleElement="h3" title="Air Quality Statements" > <ViewTransitions /><Search id="search" className="pagefind-ui" uiOptions={{ showImages: false }} /></Header>
<main id="main-content" style="min-height: 35vh;">
<article>
<slot /> <!-- your content is injected here -->
Expand Down
1 change: 0 additions & 1 deletion air-quality-statements/src/pages/2024-07-25/index.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
import Layout from '../../layouts/Layout.astro';
---
Expand Down
1 change: 1 addition & 0 deletions air-quality-statements/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
import Layout from '../layouts/Layout.astro';
//import Tree from '../components/Tree';
const baseURL = import.meta.env.BASE_URL;
---

Expand Down
4 changes: 3 additions & 1 deletion air-quality-statements/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"extends": "astro/tsconfigs/base",
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react"
"jsxImportSource": "react",
"strictNullChecks": true,
"allowJs": true

}
}
28 changes: 28 additions & 0 deletions charts/app/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: v2
name: nr-aq-avisories
description: A Helm chart for Kubernetes deployment.
icon: https://www.nicepng.com/png/detail/521-5211827_bc-icon-british-columbia-government-logo.png

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
maintainers:
- name: Om Mishra
email: [email protected]
46 changes: 46 additions & 0 deletions charts/app/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s" .Release.Name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "name.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "labels" -}}
helm.sh/chart: {{ include "name.chart" . }}
{{ include "selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "selectorLabels" -}}
app.kubernetes.io/name: {{ include "fullname" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
42 changes: 42 additions & 0 deletions charts/app/templates/frontend/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "frontend.name" -}}
{{- printf "frontend" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "frontend.fullname" -}}
{{- $componentName := include "frontend.name" . }}
{{- if .Values.frontend.fullnameOverride }}
{{- .Values.frontend.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $componentName | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}


{{/*
Common labels
*/}}
{{- define "frontend.labels" -}}
{{ include "frontend.selectorLabels" . }}
{{- if .Values.global.tag }}
app.kubernetes.io/image-version: {{ .Values.global.tag | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/short-name: {{ include "frontend.name" . }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "frontend.selectorLabels" -}}
app.kubernetes.io/name: {{ include "frontend.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

Loading

0 comments on commit 1b21709

Please sign in to comment.