Skip to content

Commit

Permalink
Merge pull request #3 from bcgov/dev
Browse files Browse the repository at this point in the history
Updated test from dev branch
  • Loading branch information
DavidOkulski authored Jan 6, 2025
2 parents 5c0435f + 008e255 commit 2a54c84
Show file tree
Hide file tree
Showing 15 changed files with 276 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ FRONTEND_URL=http://localhost:3000
BACKEND_URL=http://localhost:3000
APP_PORT=3000

REACT_APP_ENV=dev
REACT_APP_SSO_URL=http://localhost:3000
REACT_APP_KILN_PREVIEW_URL=http://localhost:4173/preview
REACT_APP_KILN_URL=http://localhost:4173

POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=form_templates
Expand Down
79 changes: 79 additions & 0 deletions .github/workflows/deployment-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Build and Deploy to DEV

on:
push:
branches:
- dev

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build_and_push:
runs-on: ubuntu-latest

steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
APP_PORT=${{ secrets.APP_PORT }}
outputs:
image_tag: ${{ steps.meta.outputs.tags }}

deploy_dev:
needs: build_and_push
runs-on: ubuntu-latest

steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Install oc CLI
uses: redhat-actions/oc-installer@v1

- name: Authenticate with OpenShift (DEV)
uses: redhat-actions/oc-login@v1
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
namespace: ${{ secrets.OPENSHIFT_DEV_NAMESPACE }}
openshift_token: ${{ secrets.OPENSHIFT_DEV_TOKEN }}
insecure_skip_tls_verify: true

- name: Deploy with Helm
run: |
helm upgrade --install template-repository ./helm \
--namespace ${{ secrets.OPENSHIFT_DEV_NAMESPACE }} \
--set app.image.repository=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} \
--set app.image.tag=${{ needs.build_and_push.outputs.image_tag }} \
--set postgresql.image.repository=postgres \
--set postgresql.image.tag=13
- name: Trigger OpenShift Rollout
run: |
oc rollout restart deployment/template-repository-app -n ${{ secrets.OPENSHIFT_DEV_NAMESPACE }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ cd template-respository

## Configuration

Copy and rename `.env.example` file to `.env` both in the root and in /app/client:
Copy and rename `.env.example` file to `.env` both in the root:

```
Copy-Item .env.example .env
```

Update variables in `.env` files with your credentials and congifurations.
Update variables in `.env` file with your credentials and congifurations.

## Docker Deployment

Expand Down
8 changes: 6 additions & 2 deletions app/client/src/App.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
body,
html {
font-family: var(--typography-font-families-bc-sans, "Arial", sans-serif);
}

.App {
text-align: left;
transition: background-color 0.3s, color 0.3s;
transition: background-color 0.3s, color 0.3s;
background-color: #ffffff;
color: #000000;
}


.bcds-header {
justify-content: normal !important;
}
Expand Down
2 changes: 2 additions & 0 deletions app/client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Login from "./pages/Login";
import FormList from "./pages/FormList";
import NotAuthorized from "./pages/NotAuthorized";
import { useSSO } from "@bcgov/citz-imb-sso-react";
import "@bcgov/bc-sans/css/BC_Sans.css";
import "./App.css"

const App = () => {
const { isAuthenticated, hasRoles } = useSSO();
Expand Down
3 changes: 0 additions & 3 deletions app/client/src/pages/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ const Login = () => {
if (isAuthenticated) {
return <Navigate to="/forms" replace />;
}
console.log("REACT_APP_SSO_URL:", process.env.REACT_APP_SSO_URL);
console.log("Type of URL:", typeof process.env.REACT_APP_SSO_URL);
console.log("Value of URL:", process.env.REACT_APP_SSO_URL);

return (
<div className="App">
Expand Down
4 changes: 1 addition & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ services:
- db
volumes:
- .:/usr/src/app
environment:
- NODE_ENV=production
restart: always
command: >
sh -c "npx knex migrate:latest && node index.js"
Expand All @@ -24,7 +22,7 @@ services:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
ports:
- "5434:5432"
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data

Expand Down
9 changes: 4 additions & 5 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
FROM node:16
FROM node:18

WORKDIR /usr/app

# Express App
#Express app
COPY ./app/src/package*.json ./src/
RUN npm install --prefix ./src

COPY ./app/src ./src

# React App
#React app
WORKDIR /usr/app/client

COPY ./app/client/package*.json ./package.json
COPY ./app/client/package-lock.json ./package-lock.json
RUN npm install

COPY ./app/client/ .
RUN npm run build

RUN npm run build

WORKDIR /usr/app/src

Expand All @@ -26,4 +26,3 @@ ENV APP_PORT=${APP_PORT}
EXPOSE ${APP_PORT}

CMD ["sh", "-c", "npx knex migrate:latest && node index.js"]

30 changes: 30 additions & 0 deletions dockerfile-local
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM node:18

WORKDIR /usr/app

COPY ./.env ./.env

# Express App
COPY ./app/src/package*.json ./src/
RUN npm install --prefix ./src

COPY ./app/src ./src

# React App
WORKDIR /usr/app/client

COPY ./app/client/package*.json ./package.json
COPY ./app/client/package-lock.json ./package-lock.json
RUN npm install

COPY ./app/client/ .

RUN cp ../.env .env && npm run build

WORKDIR /usr/app/src

ARG APP_PORT
ENV APP_PORT=${APP_PORT}
EXPOSE ${APP_PORT}

CMD ["sh", "-c", "npx knex migrate:latest && node index.js"]
6 changes: 6 additions & 0 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: template-repository
description: Unified Helm chart for Template Repository and PostgreSQL
type: application
version: 0.1.0
appVersion: "1.0"
33 changes: 33 additions & 0 deletions helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-app
labels:
app: {{ .Release.Name }}-app
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ .Release.Name }}-app
template:
metadata:
labels:
app: {{ .Release.Name }}-app
spec:
containers:
- name: app
image: "{{ .Values.app.repository }}:{{ .Values.app.tag }}"
ports:
- containerPort: {{ .Values.env.APP_PORT }}
envFrom:
- configMapRef:
name: {{ .Values.configMapName }}
- secretRef:
name: {{ .Values.secretName }}
resources:
requests:
memory: {{ .Values.resources.requests.memory }}
cpu: {{ .Values.resources.requests.cpu }}
limits:
memory: {{ .Values.resources.limits.memory }}
cpu: {{ .Values.resources.limits.cpu }}
30 changes: 30 additions & 0 deletions helm/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}-postgresql
labels:
app: {{ .Release.Name }}-postgresql
spec:
clusterIP: None
ports:
- name: postgres
port: {{ .Values.service.postgresPort }}
targetPort: {{ .Values.service.postgresPort }}
selector:
app: {{ .Release.Name }}-postgresql
---
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}-app
labels:
app: {{ .Release.Name }}-app
spec:
type: {{ .Values.service.type }}
ports:
- name: app
port: {{ .Values.service.appPort }}
targetPort: {{ .Values.service.appPort }}
selector:
app: {{ .Release.Name }}-app
37 changes: 37 additions & 0 deletions helm/templates/statefulset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ .Release.Name }}-postgresql
labels:
app: {{ .Release.Name }}
spec:
replicas: 1
serviceName: {{ .Release.Name }}-postgresql
selector:
matchLabels:
app: {{ .Release.Name }}-postgresql
template:
metadata:
labels:
app: {{ .Release.Name }}-postgresql
spec:
containers:
- name: postgresql
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
ports:
- containerPort: {{ .Values.service.postgresPort }}
env:
- name: POSTGRES_USER
value: {{ .Values.postgresql.username }}
- name: POSTGRES_PASSWORD
value: {{ .Values.postgresql.password }}
- name: POSTGRES_DB
value: {{ .Values.postgresql.database }}
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: {{ .Values.postgresql.primary.persistence.accessModes }}
resources:
requests:
storage: {{ .Values.postgresql.primary.persistence.size }}
41 changes: 41 additions & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
replicaCount: 1

image:
repository: postgres
tag: "13"
pullPolicy: IfNotPresent

configMapName: template-repo-config
secretName: template-repo-app-secrets

env:
APP_PORT: 3000
REACT_APP_ENV: dev

app:
repository: ghcr.io/bcgov/template-repository
tag: dev

resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "250m"

postgresql:
enabled: true
username: postgres
password: postgres
database: form_templates
primary:
persistence:
enabled: true
size: 512Mi
accessModes:
- ReadWriteOnce
service:
type: ClusterIP
postgresPort: 5432
appPort: 3000
Binary file added output.yaml
Binary file not shown.

0 comments on commit 2a54c84

Please sign in to comment.