Skip to content

Commit

Permalink
Build frontend and backend for Jan pipeline (#2421)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuanfandevops authored Jul 6, 2023
1 parent f62d278 commit bb2d57c
Show file tree
Hide file tree
Showing 25 changed files with 1,156 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/branch-build-template.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

name: PR Build Template
name: Branch Build Template

on:
workflow_call:
Expand Down
107 changes: 107 additions & 0 deletions .github/workflows/branch-deploy-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Branch Deploy Template

on:
workflow_call:
inputs:
branch-name: # sample value: release-2.9.0 or main-release-jan-2024
required: true
type: string
# suffix is in format of -dev, -test, -dev-jan, test-jan, -dev-1923, dev-jan-1923
suffix:
required: true
type: string
# env-name is in format of dev, test
env-name:
required: true
type: string
# database-service-host-name sample tfrs-spilo, tfrs-spilo-jan, tfrs-spilo-dev-1988
database-service-host-name:
required: true
type: string
secrets:
tools-namespace:
required: true
namespace:
required: true
openshift-server:
required: true
openshift-token:
required: true

jobs:

deploy:

name: Deploy tfrs
runs-on: ubuntu-latest
timeout-minutes: 60

steps:

- name: Check out repository
uses: actions/checkout@v3
with:
ref: ${{ inputs.branch-name }}

- name: Log in to Openshift
uses: redhat-actions/oc-login@v1.2
with:
openshift_server_url: ${{ secrets.openshift-server }}
openshift_token: ${{ secrets.openshift-token }}
insecure_skip_tls_verify: true
namespace: ${{ secrets.tools-namespace }}

- name: Tag Images from tools
run: |
oc tag ${{ secrets.tools-namespace }}/tfrs-frontend:build-${{ inputs.branch-name }} ${{ secrets.namespace }}/tfrs-frontend:${{ inputs.env-name }}-${{ inputs.branch-name }}
oc tag ${{ secrets.tools-namespace }}/tfrs-backend:build-${{ inputs.branch-name }} ${{ secrets.namespace }}/tfrs-backend:${{ inputs.env-name }}-${{ inputs.branch-name }}
- name: Deploy tfrs-frontend
shell: bash {0}
run: |
cd charts/tfrs-apps/charts/tfrs-frontend
helm status -n ${{ secrets.namespace }} tfrs-frontend${{ inputs.suffix }}
if [ $? -eq 0 ]; then
echo "tfrs-frontend${{ inputs.suffix }} release exists already"
helm upgrade \
--set frontendImageTagName=${{ inputs.env-name }}-${{ inputs.branch-name }} \
--set suffix=${{ inputs.suffix }} \
--set namespace=${{ secrets.namespace }} \
--set envName=${{ inputs.env-Name }} \
-n ${{ secrets.namespace }} -f ./values${{ inputs.suffix }}.yaml tfrs-frontend${{ inputs.suffix }} .
else
echo "tfrs-frontend${{ inputs.suffix }} release does not exist"
helm install \
--set frontendImageTagName=${{ inputs.env-name }}-${{ inputs.branch-name }} \
--set suffix=${{ inputs.suffix }} \
--set namespace=${{ secrets.namespace }} \
--set envName=${{ inputs.env-Name }} \
-n ${{ secrets.namespace }} -f ./values${{ inputs.suffix }}.yaml tfrs-frontend${{ inputs.suffix }} .
fi
- name: Deploy tfrs-backend
shell: bash {0}
run: |
cd charts/tfrs-apps/charts/tfrs-backend
helm status -n ${{ secrets.namespace }} tfrs-backend${{ inputs.suffix }}
if [ $? -eq 0 ]; then
echo "tfrs-backend${{ inputs.suffix }} release exists already"
helm upgrade \
--set backendImageTagName=${{ inputs.env-name }}-${{ inputs.branch-name }} \
--set suffix=${{ inputs.suffix }} \
--set namespace=${{ secrets.namespace }} \
--set envName=${{ inputs.env-Name }} \
--set databaseServiceHostName=${{ inputs.database-service-host-name }} \
-n ${{ secrets.namespace }} -f ./values${{ inputs.suffix }}.yaml tfrs-backend${{ inputs.suffix }} .
else
echo "tfrs-backend${{ inputs.suffix }} release does not exist"
helm install \
--set backendImageTagName=${{ inputs.env-name }}-${{ inputs.branch-name }} \
--set suffix=${{ inputs.suffix }} \
--set namespace=${{ secrets.namespace }} \
--set envName=${{ inputs.env-Name }} \
--set databaseServiceHostName=${{ inputs.database-service-host-name }} \
-n ${{ secrets.namespace }} -f ./values${{ inputs.suffix }}.yaml tfrs-backend${{ inputs.suffix }} .
fi
57 changes: 24 additions & 33 deletions .github/workflows/dev-jan-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ name: TFRS Dev Jan 2024 Release

on:
push:
branches: [ jan-pipelin ]
# paths:
# - frontend/**
# - backend/**
# workflow_dispatch:
branches: [ main-release-jan-2024 ]
paths:
- frontend/**
- backend/**
- security-scan/**
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -65,7 +66,8 @@ jobs:
LOG_LEVEL: WARN

build:
# needs: [unit-test, lint]
name: Build
needs: [unit-test, lint]
uses: ./.github/workflows/branch-build-template.yaml
with:
branch-name: ${{ github.ref_name }}
Expand All @@ -74,30 +76,19 @@ jobs:
openshift-server: ${{ secrets.OPENSHIFT_SERVER }}
openshift-token: ${{ secrets.OPENSHIFT_TOKEN }}

# deploy-on-dev:

# name: Deploy TFRS on Dev
# runs-on: ubuntu-latest
# timeout-minutes: 240
# needs: build

# steps:

# ## it will checkout to /home/runner/work/itvr/itvr
# - name: Check out repository
# uses: actions/checkout@v3

# - name: Log in to Openshift
# ##uses: redhat-actions/oc-login@v1
# uses: smlgbl/oc-login@main
# with:
# openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
# openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
# insecure_skip_tls_verify: true
# namespace: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-tools

# - name: Run deploy
# run: |
# cd .pipeline
# npm install
# npm run deploy -- --pr=${{ env.PR_NUMBER }} --env=dev
# The suffix is -dev-jan, the deployment names are tfrs-backend-dev-jan, tfrs-frontend-dev-jan and etc..
# The image tags are tfrs-backend:dev-main-release-jan-2024, tfrs-frontend:dev-main-release-jan-2024 and etc..
deploy-on-dev:
name: Deploy on Dev
needs: build
uses: ./.github/workflows/branch-deploy-template.yaml
with:
branch-name: ${{ github.ref_name }}
suffix: -dev-jan
env-name: dev
database-service-host-name: tfrs-spilo-jan
secrets:
tools-namespace: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-tools
namespace: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-dev
openshift-server: ${{ secrets.OPENSHIFT_SERVER }}
openshift-token: ${{ secrets.OPENSHIFT_TOKEN }}
23 changes: 23 additions & 0 deletions charts/tfrs-apps/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions charts/tfrs-apps/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: tfrs-apps
description: A Helm chart for Kubernetes

# 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: 1.0.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: "3.0.0"
23 changes: 23 additions & 0 deletions charts/tfrs-apps/charts/tfrs-backend/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions charts/tfrs-apps/charts/tfrs-backend/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: tfrs-backend
description: A Helm chart for Kubernetes

# 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: "3.0.0"
67 changes: 67 additions & 0 deletions charts/tfrs-apps/charts/tfrs-backend/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{{/*
The labels for all components:
labels:
helm.sh/chart: tfrs-backend-1.0.0
app.kubernetes.io/name: tfrs-backend
app.kubernetes.io/instance: tfrs-backend-dev or tfrs-backend-dev-jan
app.kubernetes.io/version: "3.0.0"
app.kubernetes.io/managed-by: Helm
The selector lables:
selector:
app.kubernetes.io/name: tfrs-backend
app.kubernetes.io/instance: tfrs-backend-dev-1977
.Release.Name comes from command helm install
example: helm install tfrs-backend-dev ... or helm install tfrs-backend-dev-jan ...
.Chart.Name come from the name attribute in Chart.yaml
*/}}

{{/*
Expand the name of the chart. If nameOverride is empty, use .Chart.Name.
Typically no need to assign value to nameOverride,
*/}}
{{- define "tfrs-backend.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).
The .Release.Name is the first parameter of command helm install tfrs-backend-dev or tfrs-backend-dev-jan
*/}}
{{- define "tfrs-backend.fullname" -}}
{{- .Release.Name }}
{{- end }}

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

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

{{/*
Selector labels
*/}}
{{- define "tfrs-backend.selectorLabels" -}}
app.kubernetes.io/name: {{ include "tfrs-backend.name" . }}
app.kubernetes.io/instance: {{ include "tfrs-backend.fullname" . }}
{{- end }}

Loading

0 comments on commit bb2d57c

Please sign in to comment.