generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d72758
commit 79a8a2f
Showing
8 changed files
with
257 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
name: "♻️ Deploy to PoC Namespace" | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: [main] | ||
push: | ||
branches: [main] | ||
env: | ||
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }} | ||
KUBE_NAMESPACE: ${{ secrets.POC_KUBE_NAMESPACE }} | ||
KUBE_CERT: ${{ secrets.POC_KUBE_CERT }} | ||
KUBE_TOKEN: ${{ secrets.POC_KUBE_TOKEN }} | ||
|
||
IMAGE_TAG: ${{ github.sha }} | ||
ECR_REGISTRY: ${{ vars.DEVELOPMENT_ECR_REGISTRY }} | ||
ECR_REPOSITORY: ${{ vars.DEVELOPMENT_ECR_REPOSITORY }} | ||
|
||
POSTGRES_USER: ${{secrets.POC_POSTGRES_USER}} | ||
POSTGRES_PASSWORD: ${{secrets.POC_POSTGRES_PASSWORD}} | ||
POSTGRES_DB: ${{secrets.POC_POSTGRES_DB}} | ||
POSTGRES_HOST: ${{secrets.POC_POSTGRES_HOST}} | ||
POSTGRES_PORT: ${{secrets.POC_POSTGRES_PORT}} | ||
|
||
jobs: | ||
build-push: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
contents: read | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
role-to-assume: ${{ secrets.DEVELOPMENT_ECR_ROLE_TO_ASSUME }} | ||
aws-region: ${{ vars.DEVELOPMENT_ECR_REGION }} | ||
|
||
- uses: aws-actions/amazon-ecr-login@v2 | ||
id: login-ecr | ||
- run: | | ||
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
deploy-to-dev: | ||
needs: build-push | ||
runs-on: ubuntu-latest | ||
container: alpine/k8s:1.23.17 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Authenticate to the cluster | ||
run: | | ||
echo "${KUBE_CERT}" > ca.crt | ||
kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER} | ||
kubectl config set-credentials deploy-user --token=${KUBE_TOKEN} | ||
kubectl config set-context ${KUBE_CLUSTER} --cluster=${KUBE_CLUSTER} --user=deploy-user --namespace=${KUBE_NAMESPACE} | ||
kubectl config get-contexts | ||
kubectl config use-context ${KUBE_CLUSTER} | ||
- name: Deploy helm chart to PoC | ||
run: | | ||
helm upgrade kpi-dashboard \ | ||
helm/kpi-dashboard \ | ||
--install \ | ||
--force \ | ||
--wait \ | ||
--timeout 10m \ | ||
--namespace ${KUBE_NAMESPACE} \ | ||
--values=helm/kpi-dashboard/values-poc.yaml \ | ||
--set app.deployment.env.POSTGRES_USER=${POSTGRES_USER} \ | ||
--set app.deployment.env.POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \ | ||
--set app.deployment.env.POSTGRES_DB=${POSTGRES_DB} \ | ||
--set app.deployment.env.POSTGRES_HOST=${POSTGRES_HOST} \ | ||
--set app.deployment.env.POSTGRES_PORT=${POSTGRES_PORT} \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
apiVersion: v2 | ||
name: kpi-dashboard | ||
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: "1.16.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{{/* | ||
Expand the name of the chart. | ||
*/}} | ||
{{- define "kpi-dashboard.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 "kpi-dashboard.fullname" -}} | ||
{{- if .Values.fullnameOverride }} | ||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} | ||
{{- else }} | ||
{{- $name := default .Chart.Name .Values.nameOverride }} | ||
{{- if contains $name .Release.Name }} | ||
{{- .Release.Name | trunc 63 | trimSuffix "-" }} | ||
{{- else }} | ||
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create chart name and version as used by the chart label. | ||
*/}} | ||
{{- define "kpi-dashboard.chart" -}} | ||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
|
||
{{/* | ||
Common labels | ||
*/}} | ||
{{- define "kpi-dashboard.labels" -}} | ||
helm.sh/chart: {{ include "kpi-dashboard.chart" . }} | ||
{{ include "kpi-dashboard.selectorLabels" . }} | ||
{{- if .Chart.AppVersion }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} | ||
{{- end }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
{{- end }} | ||
|
||
{{/* | ||
Selector labels | ||
*/}} | ||
{{- define "kpi-dashboard.selectorLabels" -}} | ||
app.kubernetes.io/name: {{ include "kpi-dashboard.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: { { include "kpi-dashboard.fullname" . } } | ||
labels: { { - include "kpi-dashboard.labels" . | nindent 4 } } | ||
spec: | ||
replicas: { { .Values.app.deployment.replicaCount } } | ||
selector: | ||
matchLabels: { { - include "kpi-dashboard.selectorLabels" . | nindent 6 } } | ||
template: | ||
metadata: | ||
labels: { { - include "kpi-dashboard.selectorLabels" . | nindent 8 } } | ||
spec: | ||
# serviceAccountName created by the Cloud Platform environment | ||
serviceAccountName: cd-serviceaccount | ||
containers: | ||
- name: { { .Chart.Name } } | ||
image: "{{ .Values.app.deployment.image.repository }}:{{ .Values.app.deployment.image.tag | default .Chart.AppVersion }}" | ||
imagePullPolicy: IfNotPresent | ||
env: | ||
- name: POSTGRES_USER | ||
value: { { .Values.app.deployment.env.POSTGRES_USER | quote } } | ||
- name: POSTGRES_PASSWORD | ||
value: | ||
{ { .Values.app.deployment.env.POSTGRES_PASSWORD | quote } } | ||
- name: POSTGRES_DB | ||
value: { { .Values.app.deployment.env.POSTGRES_DB | quote } } | ||
- name: POSTGRES_HOST | ||
value: { { .Values.app.deployment.env.POSTGRES_HOST | quote } } | ||
- name: POSTGRES_PORT | ||
value: { { .Values.app.deployment.env.POSTGRES_PORT | quote } } | ||
|
||
ports: | ||
- name: http | ||
containerPort: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{{- $fullName := include "kpi-dashboard.fullname" . -}} | ||
--- | ||
apiVersion: networking.k8s.io/v1 | ||
kind: Ingress | ||
metadata: | ||
name: {{ $fullName }} | ||
labels: | ||
{{- include "kpi-dashboard.labels" . | nindent 4 }} | ||
annotations: | ||
external-dns.alpha.kubernetes.io/set-identifier: {{ $fullName }}-{{ $fullName }}-green | ||
external-dns.alpha.kubernetes.io/aws-weight: "100" | ||
cloud-platform.justice.gov.uk/ignore-external-dns-weight: "true" | ||
spec: | ||
ingressClassName: "default" | ||
tls: | ||
- hosts: | ||
- {{ .Values.app.ingress.host }} | ||
rules: | ||
- host: {{ .Values.app.ingress.host }} | ||
http: | ||
paths: | ||
- path: / | ||
pathType: ImplementationSpecific | ||
backend: | ||
service: | ||
name: {{ $fullName }} | ||
port: | ||
number: 80 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: { { include "kpi-dashboard.fullname" . } } | ||
labels: { { - include "kpi-dashboard.labels" . | nindent 4 } } | ||
spec: | ||
ports: | ||
- port: 80 | ||
targetPort: 4567 | ||
name: https | ||
selector: { { - include "kpi-dashboard.selectorLabels" . | nindent 4 } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
app: | ||
ingress: | ||
host: "kpi-dashboard-poc.cloud-platform.service.justice.gov.uk" | ||
|
||
deployment: | ||
replicaCount: 1 | ||
env: | ||
LOGGING_LEVEL: INFO |