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 and Your Name committed Nov 3, 2023
1 parent 5b86ea1 commit 48f9645
Show file tree
Hide file tree
Showing 23 changed files with 829 additions and 142 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 }}
4 changes: 2 additions & 2 deletions charts/tfrs-apps/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ 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
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: "1.16.0"
appVersion: "3.0.0"
2 changes: 1 addition & 1 deletion charts/tfrs-apps/charts/tfrs-backend/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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
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
Expand Down
80 changes: 6 additions & 74 deletions charts/tfrs-apps/charts/tfrs-backend/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ The selector lables:
.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.
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 "-" }}
Expand All @@ -28,8 +31,7 @@ Expand the name of the chart.
{{/*
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.
The .Release.Name is the first parameter of command helm install tfrs-backend
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 }}
Expand Down Expand Up @@ -60,76 +62,6 @@ Selector labels
*/}}
{{- define "tfrs-backend.selectorLabels" -}}
app.kubernetes.io/name: {{ include "tfrs-backend.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Define the deploymentconfig name
*/}}
{{- define "tfrs-backend.deploymentconfigName" -}}
{{- include "tfrs-backend.fullname" . }}
{{- end }}

{{/*
Define the deploymentconfig name
*/}}
{{- define "tfrs-backend.imagestreamName" -}}
{{- include "tfrs-backend.fullname" . }}
{{- end }}

{{/*
Define the service name
*/}}
{{- define "tfrs-backend.serviceName" -}}
{{- include "tfrs-backend.fullname" . }}
{{- end }}


{{/*
Define the backend route name
*/}}
{{- define "tfrs-backend.routeName" -}}
{{- include "tfrs-backend.fullname" . }}
{{- end }}

{{/*
Define the backend admin route name, used by task queue
*/}}
{{- define "tfrs-backend.adminRouteName" -}}
tfrs-backend-admin{{ .Values.suffix }}
{{- end }}

{{/*
Define the backend static route name, used by task queue
*/}}
{{- define "tfrs-backend.staticRouteName" -}}
tfrs-backend-static{{ .Values.suffix }}
{{- end }}

{{/*
Define the djangoSecretKey
*/}}
{{- define "tfrs-backend.djangoSecretKey" -}}
{{- randAlphaNum 50 | nospace | b64enc }}
app.kubernetes.io/instance: {{ include "tfrs-backend.fullname" . }}
{{- end }}

{{/*
Define the djangoSaltKey
*/}}
{{- define "tfrs-backend.djangoSaltKey" -}}
{{- randAlphaNum 50 | nospace | b64enc }}
{{- end }}

{{/*
Define the django-secret name
*/}}
{{- define "tfrs-backend.django-secret" -}}
tfrs-django-secret
{{- end }}

{{/*
Define the django-salt name
*/}}
{{- define "tfrs-backend.django-salt" -}}
tfrs-django-salt
{{- end }}
Loading

0 comments on commit 48f9645

Please sign in to comment.