Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TA-3042 redis service and db #265

Merged
merged 107 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
612de84
Dockerfile and script to create image to populate redis db with tests…
solomonahmed Jan 28, 2025
243eb05
add changed circleci config to build docker image to setup redis
solomonahmed Jan 28, 2025
486edbf
use default docker version to avoid circleci version errors
solomonahmed Jan 28, 2025
17f471b
make ref to the scripts.rb file relative to the base dir
solomonahmed Jan 28, 2025
f4b17b1
slight mod to make use of circleci convenience image and other minor …
solomonahmed Jan 28, 2025
82bdf6d
cater for the COMMIT_SHA env var and align the aws tag and push steps…
solomonahmed Jan 28, 2025
7044d30
remove name: as causing an error
solomonahmed Jan 28, 2025
751e37b
remove commit_sha from the Dockerfile and build_args as we will use K…
solomonahmed Jan 28, 2025
d59ad34
redis db and service
solomonahmed Jan 28, 2025
ae371db
tag redis-setup with string to distinguish
solomonahmed Jan 28, 2025
b01a5e9
mods to helm file and k8s yaml files to setup redis-db,service, and s…
solomonahmed Jan 28, 2025
5436d43
slight mod to yaml files to get values from Helm
solomonahmed Jan 28, 2025
52ea86c
helm and k8 mods to pass in and set placeholders
solomonahmed Jan 28, 2025
54590a0
centralised security context values and mod to redis yaml files
solomonahmed Jan 28, 2025
48df13e
tag redis-setup using checksum and fix minor formatting problem in yaml
solomonahmed Jan 28, 2025
be52332
correct dir path to setup.rb
solomonahmed Jan 28, 2025
0e8a706
if the image already exists set an env var and skip the next steps
solomonahmed Jan 28, 2025
07b503c
refactored config file to remove duplication and repetition
solomonahmed Jan 28, 2025
def1754
use skip_build approach rather than failing intentionally
solomonahmed Jan 28, 2025
11ea658
add source command to ensure env vars set are available in subsequent…
solomonahmed Jan 28, 2025
c981da7
persist env vars
solomonahmed Jan 28, 2025
cdf6255
transfer env var betweens jobs
solomonahmed Jan 28, 2025
cb4beb4
only checkout once, in subsequent steps use attach workspace
solomonahmed Jan 28, 2025
9aa3e22
revert
solomonahmed Jan 28, 2025
a3d39e6
more mods to use helm placeholders and align yaml files
solomonahmed Jan 29, 2025
74daa02
correct yaml issues
solomonahmed Jan 29, 2025
77a8998
formatting issues addressed
solomonahmed Jan 29, 2025
6bb58f9
test helm by rendering template
solomonahmed Jan 29, 2025
ce728f4
ensure placeholders are empty if taking values from helm install --se…
solomonahmed Jan 29, 2025
3b35e13
add debug to trouble shoot the issue
solomonahmed Jan 29, 2025
11f98dc
change image and minor corrections
solomonahmed Jan 29, 2025
5d4c4b8
remove helm template check
solomonahmed Jan 29, 2025
1e34898
attach workspace and source bash_env file in deploy job
solomonahmed Jan 29, 2025
09db38a
enclosed some values with double quotes as a precaution
solomonahmed Jan 29, 2025
d50cfd7
remove serviceAccountName from deployment.spec
solomonahmed Jan 29, 2025
89f92b9
add security settings
solomonahmed Jan 29, 2025
ca46336
.
solomonahmed Jan 29, 2025
9222ad5
correct registryAddress
solomonahmed Jan 29, 2025
0df3f06
enclose env vars passed via --set in double quotes
solomonahmed Jan 29, 2025
f330761
debug some placeholder values via configMap
solomonahmed Jan 29, 2025
84be4b1
debug redis-setup image tag
solomonahmed Jan 29, 2025
29f9f11
make sure the deploy job relies on the redis-setup job to ensure the …
solomonahmed Jan 29, 2025
e8f04c4
combine jobs to persist workspace
solomonahmed Jan 29, 2025
21dd7a1
ensure name of the configMap is unique by including the release name …
solomonahmed Jan 29, 2025
aefffaa
debug redis-setup image
solomonahmed Jan 29, 2025
1e1558f
handle imagenotfound exception
solomonahmed Jan 29, 2025
afc6e4a
ensure we setup aws before logging in to the ECR to push redis-setup
solomonahmed Jan 29, 2025
58130c7
wait for redis in an initcontainer and run setup in the main container
solomonahmed Jan 29, 2025
289204f
ensure we poll the right service name, add helm info
solomonahmed Jan 29, 2025
6c75329
pass REDIS_HOST into setup script
solomonahmed Jan 30, 2025
c046e30
change the release-name label so it refs the release number from helm…
solomonahmed Jan 30, 2025
9348310
copy in the redis gem so we cover any dependencies needed by the script
solomonahmed Jan 30, 2025
fb8d77e
adjust permissions on copied in Gemfiles
solomonahmed Jan 30, 2025
5d2721f
recusively travel through the directories adding *.feature files not …
solomonahmed Jan 30, 2025
e8a9600
add a pvc to store pod data and surface this in the artefacts tab in …
solomonahmed Jan 30, 2025
df5cb2f
stream logs in background so we can grab artefacts straightaway
solomonahmed Jan 30, 2025
58e6d5d
add debugging
solomonahmed Jan 30, 2025
3371c79
more debugging
solomonahmed Jan 30, 2025
4ccbd28
use RELEASE_NAME in the same step as kubectl cp
solomonahmed Jan 30, 2025
0aa739b
ensure name of pvc in pod matches name of pvc in pvc yaml
solomonahmed Jan 30, 2025
e1c4ad1
re-organised files/folders to split helm run into 2 whilst linking bo…
solomonahmed Feb 3, 2025
b288036
install petname dynamically to help with release name script
solomonahmed Feb 3, 2025
24d7fe6
use new next gen images cimg and ensure we use petname lib not petnames
solomonahmed Feb 3, 2025
00aaa3f
ensure we use a custom release name in both install commands and also…
solomonahmed Feb 3, 2025
4b1d2a2
set the RELEASE_NAME env var
solomonahmed Feb 3, 2025
ae587a6
correct release_name.txt location
solomonahmed Feb 3, 2025
67f90d8
retrieve release name in the same step as helm install
solomonahmed Feb 3, 2025
4338bb9
remove trailing backslash
solomonahmed Feb 3, 2025
c417c06
all yml files are in a templates sub-folder so make sure we ref that
solomonahmed Feb 3, 2025
6d73058
get ref to templates folder correct and add define keyword
solomonahmed Feb 3, 2025
5f67044
enclosed in double quotes
solomonahmed Feb 3, 2025
fffe833
add {{- end -}}
solomonahmed Feb 3, 2025
f2cc04b
correct yaml errors
solomonahmed Feb 3, 2025
46fa0e0
remove redis-setup from the release_name
solomonahmed Feb 3, 2025
c7ace85
test partial run mechanism
solomonahmed Feb 3, 2025
0d3c8fb
remove tests from feature.txt and see impact
solomonahmed Feb 3, 2025
2355e06
setup redis db to use a dedicated pvc
solomonahmed Feb 3, 2025
ec296f6
add redis-pvc to _helpers.tpl
solomonahmed Feb 3, 2025
a87ecfd
test partial run with 1 file in features.txt
solomonahmed Feb 3, 2025
e82a5e3
blank out features.txt to see if the feature list is derived from the…
solomonahmed Feb 3, 2025
b6a9453
add debugging
solomonahmed Feb 3, 2025
5202cfe
missing checkout step in the build redis setup job
solomonahmed Feb 3, 2025
029e07e
more debugging added
solomonahmed Feb 3, 2025
4a21471
add debugging to sanity check the redis list is populated correctly
solomonahmed Feb 4, 2025
a146232
add debugging
solomonahmed Feb 4, 2025
4d60af5
reduce pvc size and add more debugging
solomonahmed Feb 4, 2025
915fb6e
ensure that the service yaml targets the right redis app
solomonahmed Feb 4, 2025
fb8b74a
align labels correctly
solomonahmed Feb 4, 2025
ca55936
add 1 test to see if we can build a partial run
solomonahmed Feb 4, 2025
e989891
remove partial test list
solomonahmed Feb 4, 2025
5866ba7
make sure helm run command is correct
solomonahmed Feb 4, 2025
eca10a6
checkout first and ensure we get RELEASE_NAME correctly
solomonahmed Feb 4, 2025
f2e0e46
use the --replace flag as we want to re-use a previously used release…
solomonahmed Feb 4, 2025
f278328
use helm upgrade --install to share release name
solomonahmed Feb 4, 2025
6dc50cc
refactor clean-up steps and remove test report steps for now
solomonahmed Feb 4, 2025
3a8de61
stream output
solomonahmed Feb 4, 2025
8539c6c
add setup/run to release name etc...
solomonahmed Feb 4, 2025
d7dcfad
add keyword run to streaming logs command
solomonahmed Feb 4, 2025
1dd2637
remove backslash
solomonahmed Feb 4, 2025
e14ceb0
add debug step
solomonahmed Feb 4, 2025
cebd3ae
don't enclose the RELEASE_NAME in single quotes
solomonahmed Feb 4, 2025
f60a6fa
Merge branch 'main' into TA-3042_redis_service_and_db
vimalsuresh Feb 6, 2025
c168e54
test: update namespace context for redis deploy
andywelshmoj Mar 26, 2025
948f613
fix: another namespace correction
andywelshmoj Mar 26, 2025
0b5de7e
Merge branch 'main' into TA-3042_redis_service_and_db
vimalsuresh Mar 26, 2025
d861c3b
fix config after merge main
vimalsuresh Mar 26, 2025
d1bfea8
fix config after merge main
vimalsuresh Mar 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
219 changes: 192 additions & 27 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ orbs:
aws-ecr: circleci/aws-ecr@8.2.1
helm: circleci/helm@2.0.1
slack: circleci/slack@4.12.5
python: circleci/python@3.0.0

# ------------------
# EXECUTORS
Expand All @@ -19,7 +20,141 @@ executors:
- image: ministryofjustice/cloud-platform-tools

jobs:
Deploy_tests_on_cloud_platform:
generate_release_name:
docker:
- image: cimg/ruby:3.3.4
steps:
- checkout
- run:
name: Install Gem
command: gem install petname
- run:
name: Run Ruby Script
command: |
ruby docker/scripts/generate_release_name.rb > release_name.txt
- store_artifacts:
path: release_name.txt
destination: release_name.txt
- persist_to_workspace:
root: .
paths:
- release_name.txt

check_redis_setup_docker_image:
executor: build-executor
steps:
- checkout
- run:
name: Calculate checksums
command: |
DOCKERFILE_CHECKSUM=$(sha1sum docker/Dockerfile | awk '{ print $1 }')
SETUP_SCRIPT_CHECKSUM=$(sha1sum docker/scripts/setup.rb | awk '{ print $1 }')
REDIS_SETUP_IMAGE_TAG="redis-setup-${DOCKERFILE_CHECKSUM}-${SETUP_SCRIPT_CHECKSUM}"
echo "export REDIS_SETUP_IMAGE_TAG=${REDIS_SETUP_IMAGE_TAG}" >> "$BASH_ENV"
echo "Image Tag: ${REDIS_SETUP_IMAGE_TAG}"
- aws-cli/setup:
role_arn: $ECR_ROLE_TO_ASSUME
region: $ECR_REGION
- run:
name: Check if Docker image exists in ECR
command: |
echo "Checking if image exists in ECR..."
echo "Image Tag: ${REDIS_SETUP_IMAGE_TAG}"
IMAGE_EXISTS=$(aws ecr describe-images --repository-name ${ECR_REPOSITORY} --image-ids imageTag=${REDIS_SETUP_IMAGE_TAG} --region ${ECR_REGION} 2>&1 || true)
echo "IMAGE_EXISTS: $IMAGE_EXISTS"
if echo "$IMAGE_EXISTS" | grep -q 'ImageNotFoundException'; then
echo "Image ${REDIS_SETUP_IMAGE_TAG} does not exist in ECR. Proceeding with build."
echo "export SKIP_BUILD=false" >> "$BASH_ENV"
else
echo "Image ${REDIS_SETUP_IMAGE_TAG} already exists in ECR. Skipping build."
echo "export SKIP_BUILD=true" >> "$BASH_ENV"
fi
- run:
name: Save environment variables
command: cp $BASH_ENV bash.env
- persist_to_workspace:
root: .
paths:
- bash.env

build_and_push_redis_setup_docker_image:
executor: build-executor
steps:
- checkout
- attach_workspace:
at: .
- run:
name: Load environment variables
command: |
cat bash.env >> $BASH_ENV
- run: |
# verify; this should print 'true' or 'false'
printenv SKIP_BUILD
- setup_remote_docker:
docker_layer_caching: true
- aws-cli/setup:
role_arn: $ECR_ROLE_TO_ASSUME
region: $ECR_REGION
- run:
name: Build Docker image
command: |
if [ "$SKIP_BUILD" != "true" ]; then
docker build -t redis-setup:latest -f docker/Dockerfile .
else
echo "Skipping build"
fi
- run:
name: Tag Docker image
command: |
if [ "$SKIP_BUILD" != "true" ]; then
docker tag redis-setup:latest ${AWS_ECR_REGISTRY_ID}.dkr.ecr.${ECR_REGION}.amazonaws.com/${ECR_REPOSITORY}:${REDIS_SETUP_IMAGE_TAG}
else
echo "Skipping tag"
fi
- run:
name: Login to ECR
command: |
if [ "$SKIP_BUILD" != "true" ]; then
aws ecr get-login-password --region $ECR_REGION | docker login --username AWS --password-stdin ${AWS_ECR_REGISTRY_ID}.dkr.ecr.${ECR_REGION}.amazonaws.com
else
echo "Skipping ECR login"
fi
- run:
name: Push Docker image
command: |
if [ "$SKIP_BUILD" != "true" ]; then
docker push ${AWS_ECR_REGISTRY_ID}.dkr.ecr.${ECR_REGION}.amazonaws.com/${ECR_REPOSITORY}:${REDIS_SETUP_IMAGE_TAG}
else
echo "Skipping push"
fi

deploy_test_setup:
executor: deploy-executor
parameters:
environment:
description: Destination environment
type: string
default: laa-cwa-feature-tests-dev
token:
description: CircleCI Service account token
type: string
default: ${CIRCLE_CI_TOKEN}
steps:
- checkout
- attach_workspace:
at: .
- run:
name: Load environment variables
command: |
if [ -f bash.env ]; then
cat bash.env >> $BASH_ENV
source $BASH_ENV
fi
- run:
name: Debug REDIS_SETUP_IMAGE_TAG
command: echo "REDIS_SETUP_IMAGE_TAG=${REDIS_SETUP_IMAGE_TAG}"

deploy_tests_on_cloud_platform:
executor: deploy-executor
parameters:
environment:
Expand All @@ -32,6 +167,15 @@ jobs:
default: ${CIRCLE_CI_TOKEN}
steps:
- checkout
- attach_workspace:
at: .
- run:
name: Load environment variables
command: |
if [ -f bash.env ]; then
cat bash.env >> $BASH_ENV
source $BASH_ENV
fi
- run:
name: Authenticate with cluster
command: |
Expand All @@ -47,30 +191,36 @@ jobs:
export SANITISED_BRANCH=$(echo "${CIRCLE_BRANCH,,}" | sed -r 's/[/_]+/-/g')
export SHORT_SHA1=$(echo "${CIRCLE_SHA1,,}" | cut -c1-7)
export SANITISED_BRANCH_WITH_SHA="${SANITISED_BRANCH}-${SHORT_SHA1}"
helm install --generate-name ./charts/cwa-tests \
RELEASE_NAME=$(cat release_name.txt)
helm install "${RELEASE_NAME}-run" ./charts/cwa-tests \
-f charts/cwa-tests/Values.yaml \
--set ecr.image.tag=${SANITISED_BRANCH_WITH_SHA} \
--set run=true \
--set ecr.image.tag="${SANITISED_BRANCH_WITH_SHA}" \
--set global.registryAddress="${AWS_ECR_REGISTRY_ID}.dkr.ecr.${ECR_REGION}.amazonaws.com" \
--wait --timeout 300s
export POD_NAME=$(kubectl get pods -n laa-cwa-feature-tests-dev --no-headers | awk '{print $1}' | grep '^cwa-tests-[0-9]\{10\}$' | sort | tail -1)
kubectl logs -f -n laa-cwa-feature-tests-dev $POD_NAME
kubectl logs -f "${RELEASE_NAME}-run-laa-pcuam-cwa-tests"
- run:
name: Creating Artifacts folder
name: Wait for specific pod to complete
command: |
mkdir /tmp/artifacts;
echo "Test reports for CWA UI tests" > /tmp/artifacts/art-2;
- store_artifacts:
path: reports
destination: test-reports
RELEASE_NAME=$(cat release_name.txt)
export POD_NAME=$(kubectl get pods -o jsonpath='{.items[?(@.metadata.name=="${RELEASE_NAME}-run-laa-pcuam-cwa-tests")].metadata.name}')
echo "Waiting for pod ${POD_NAME} to complete..."
kubectl wait --for=condition=complete pod/${POD_NAME} --timeout=18000s
echo "...completed"
- run:
name: Clean namespace
command: helm ls -n << parameters.environment >> --short | xargs -L1 -I {} helm uninstall {} -n << parameters.environment >>
command: |
RELEASE_NAME=$(cat release_name.txt)
helm ls -n << parameters.environment >> --short | \
grep "${RELEASE_NAME}" | \
xargs -L1 -I {} helm uninstall {} -n << parameters.environment >>
- slack/notify:
channel: laa-cwa-testing
event: pass
mentions: '@pcuam-devs'
template: basic_success_1

Build_and_Push_Docker_Image:
build_and_push_docker_image:
executor: build-executor
steps:
- checkout
Expand Down Expand Up @@ -107,15 +257,16 @@ jobs:
mentions: '@pcuam-devs'
template: basic_fail_1

Notify_Slack_For_Approval:
notify_slack_for_approval:
executor: deploy-executor
steps:
- slack/notify:
channel: laa-cwa-testing
event: always
mentions: '@pcuam-devs'
template: basic_on_hold_1
Notify_Slack_For_Success:

notify_slack_for_success:
executor: deploy-executor
steps:
- slack/notify:
Expand All @@ -126,31 +277,45 @@ jobs:

workflows:
version: 2
build_and_push:
build_and_deploy:
jobs:
- Build_and_Push_Docker_Image
- Notify_Slack_For_Approval:
- generate_release_name
- check_redis_setup_docker_image
- build_and_push_redis_setup_docker_image:
requires:
- Build_and_Push_Docker_Image

deploy_tests:
jobs:
- check_redis_setup_docker_image
- deploy_test_setup:
requires:
- generate_release_name
- build_and_push_redis_setup_docker_image
- hold_test_setup:
type: approval
requires:
- deploy_test_setup
- build_and_push_docker_image:
requires:
- hold_test_setup
- notify_slack_for_approval:
requires:
- build_and_push_docker_image
- hold_test_deployment:
type: approval
- Deploy_tests_on_cloud_platform:
requires:
- notify_slack_for_approval
- deploy_tests_on_cloud_platform:
requires:
- hold_test_deployment

scheduled_ui_test_run:
jobs:
- Deploy_tests_on_cloud_platform
- Notify_Slack_For_Success:
- deploy_tests_on_cloud_platform
- notify_slack_for_success:
requires:
- Deploy_tests_on_cloud_platform
- deploy_tests_on_cloud_platform
triggers:
- schedule:
cron: "30 1 * * *"
filters:
branches:
only:
- main
- main
25 changes: 23 additions & 2 deletions charts/cwa-tests/Values.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
global:
branch: main
costcentre: LAA
namespace: "laa-cwa-test"
namespace: "laa-cwa-feature-tests-dev"
serviceAccount: "irsa-s3-laa-cwa-feature-tests-dev"
circle_sha1: ""
browser: chrome
test_env: tst

Expand All @@ -11,4 +12,24 @@ ecr:
registryAddress: 754256621582.dkr.ecr.eu-west-2.amazonaws.com
regPath: laa-pcuam/laa-cwa-feature-tests-dev
tag: batches-latest
pullPolicy: Always
pullPolicy: Always

redisSetup:
image:
tag: ""

securityContext:
runAsUser: 1000
runAsGroup: 1000
fsGroup: 1000
capabilities:
drop:
- "ALL"
seccompProfile:
type: RuntimeDefault

# Default values for cwa-tests.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
setup: false
run: false
12 changes: 12 additions & 0 deletions charts/cwa-tests/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- define "cwa-tests.setup" -}}
{{- include "cwa-tests.setup.config-map" . }}
{{- include "cwa-tests.setup.pvc" . }}
{{- include "cwa-tests.setup.redis-pvc" . }}
{{- include "cwa-tests.setup.redis-deployment" . }}
{{- include "cwa-tests.setup.redis-service" . }}
{{- include "cwa-tests.setup.redis-setup" . }}
{{- end -}}

{{- define "cwa-tests.run" -}}
{{- include "cwa-tests.run.pod" . }}
{{- end -}}
5 changes: 5 additions & 0 deletions charts/cwa-tests/templates/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{- if .Values.setup }}
{{- include "cwa-tests.setup" . }}
{{- else if .Values.run }}
{{- include "cwa-tests.run" . }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{{- define "cwa-tests.run.pod" -}}
apiVersion: v1
kind: Pod
metadata:
name: {{ .Release.Name }}
name: {{ .Release.Name }}-laa-pcuam-cwa-tests
labels:
app.kubernetes.io/managed-by: Helm
meta.helm.sh/release-name: {{ .Chart.Name }}
meta.helm.sh/release-name: {{ .Release.Name }}
meta.helm.sh/release-namespace: {{ .Values.global.namespace }}

spec:
restartPolicy: Never
serviceAccountName: {{ .Values.global.serviceAccount }}
containers:
- name: laa-pcuam-cwa-tests
image: {{ .Values.ecr.image.registryAddress }}/{{ .Values.ecr.image.regPath }}:{{ .Values.ecr.image.tag }}
image: "{{ .Values.global.registryAddress }}/{{ .Values.global.regPath }}:{{ .Values.ecr.image.tag }}"
env:
- name: TEST_ENV
value: {{ .Values.global.test_env }}
Expand All @@ -23,4 +24,5 @@ spec:
limits:
cpu: 4000m
memory: 8192Mi
command: ["/bin/sh", "-ec", "bundle exec cucumber"]
command: ["/bin/sh", "-ec", "bundle exec cucumber"]
{{- end -}}
12 changes: 12 additions & 0 deletions charts/cwa-tests/templates/setup/config-map.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- define "cwa-tests.setup.config-map" -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-config-map
labels:
meta.helm.sh/release-name: {{ .Release.Name }}
data:
redisSetupImageTag: "{{ .Values.redisSetup.image.tag }}"
circleSha1: "{{ .Values.global.circle_sha1 }}"
---
{{- end -}}
Loading