Skip to content

Commit d201499

Browse files
authored
Merge branch 'main' into DR-112
2 parents 5d6b789 + 470de8d commit d201499

15 files changed

+353
-85
lines changed

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "maven"
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "weekly"

.github/workflows/cd.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
environment: STAGE
3939
steps:
4040
- name: Checkout repository
41-
uses: actions/checkout@v3
41+
uses: actions/checkout@v4.2.2
4242

4343
- name: Deploy to Kubernetes [STAGING ENVIRONMENT]
4444
run: |
@@ -67,32 +67,32 @@ jobs:
6767
needs: [staging-end2end-tests]
6868
steps:
6969
- name: Checkout repository
70-
uses: actions/checkout@v3
70+
uses: actions/checkout@v4.2.2
7171

7272
- name: 'Az CLI Login via OIDC'
73-
uses: azure/login@v1.4.6
73+
uses: azure/login@v2.2.0
7474
with:
7575
client-id: ${{ secrets.AZURE_CLIENT_ID }}
7676
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
7777
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
7878

7979
# Use kubelogin to configure your kubeconfig for Azure auth
8080
- name: Set up kubelogin for non-interactive login
81-
uses: azure/use-kubelogin@v1
81+
uses: azure/use-kubelogin@v1.2
8282
with:
8383
kubelogin-version: 'v0.0.25'
8484

8585
# Retrieves your Azure Kubernetes Service cluster's kubeconfig file
8686
- name: Get K8s context
87-
uses: azure/aks-set-context@v3
87+
uses: azure/aks-set-context@v4.0.1
8888
with:
8989
resource-group: ${{ env.RESOURCE_GROUP }}
9090
cluster-name: ${{ env.CLUSTER_NAME }}
9191
admin: 'false'
9292
use-kubelogin: 'true'
9393

9494
- name: Install Helm
95-
uses: azure/setup-helm@v1
95+
uses: azure/setup-helm@v4.2.0
9696
with:
9797
version: v3.12.2
9898

.github/workflows/ci.yml

Lines changed: 114 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,18 @@ jobs:
6262
fail-fast: false
6363
matrix:
6464
language: [ 'java', 'javascript' ]
65-
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
66-
# Use only 'java' to analyze code written in Java, Kotlin or both
67-
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
68-
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
65+
66+
# # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
67+
# # Use only 'java' to analyze code written in Java, Kotlin or both
68+
# # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
69+
# # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
6970

7071
# defining steps for the job as explained above
7172
steps:
7273
- name: Checkout repository
73-
uses: actions/checkout@v3 # cache maven packages step - caching maven packages to speed up the build process. Link to the documentation - https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows
74+
uses: actions/checkout@v4.2.2 # cache maven packages step - caching maven packages to speed up the build process. Link to the documentation - https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows
7475
- name: Cache Maven packages
75-
uses: actions/cache@v3 # defining cache key and restore keys for the cache step. Link to the documentation - https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#matching-a-cache-key
76+
uses: actions/cache@v4.1.2 # defining cache key and restore keys for the cache step. Link to the documentation - https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#matching-a-cache-key
7677
with:
7778
path: ~/.m2/repository # path to the directory where maven packages are stored - /root/.m2 in the container
7879
key: ${{ runner.os }}-build-${{ hashFiles('**/pom.xml') }}
@@ -109,7 +110,9 @@ jobs:
109110
uses: github/codeql-action/analyze@v2
110111
with:
111112
category: "/language:${{matrix.language}}" # defining the language for the CodeQL analysis
112-
- uses: actions/upload-artifact@v3 # uploading the artifact to the GitHub Artifacts. Link to the documentation - https://docs.github.com/en/actions/guides/storing-workflow-data-as-artifacts
113+
114+
- uses: actions/[email protected] # uploading the artifact to the GitHub Artifacts. Link to the documentation - https://docs.github.com/en/actions/guides/storing-workflow-data-as-artifacts
115+
if: matrix.language == 'java' # upload the artifact only for the java language
113116
with:
114117
name: jar-artifact # naming the artifact jar file/s path
115118
path: target/ # actual relative path to the artifact in the container - target/
@@ -122,7 +125,7 @@ jobs:
122125
- build
123126
- runner-indexes
124127
container:
125-
image: mrkostin/maven:3.6.0-alpine-git-curl-jq # ruinning the job in a container - mrkostin/maven:3.6.0-alpine-git-curl-jq
128+
image: ghcr.io/tsviz/tsvi-spring-test:v2.0.0 # using the base maven:3.8.7-openjdk-18 image + jq + curl + nodejs 18
126129
services:
127130
# postgres service container
128131
postgres: # service name - postgres. This name is used to access the service container from the job container as the host name.
@@ -149,52 +152,94 @@ jobs:
149152
runner-index: ${{ fromjson(needs.runner-indexes.outputs.json) }} # using the runner-indexes job output to define the matrix strategy
150153
steps:
151154
- name: Checkout repository # checkout the repository
152-
uses: actions/checkout@v3.0.2
155+
uses: actions/checkout@v4.2.2
153156
# caching the maven packages to speed up the build process.
154157
# Link to the documentation - https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows
155158
- name: Cache Maven packages
156-
uses: actions/cache@v3 # using the actions/cache@v3 action to cache the maven packages
159+
uses: actions/cache@v4.1.2 # defining the cache key and restore keys for the cache step. Link to the documentation - https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#matching-a-cache-key
157160
with:
158161
path: /root/.m2 # path to cache
159162
key: ${{ runner.os }}-junit-${{ hashFiles('**/pom.xml') }} # key for restoring and saving the cache
160163
restore-keys: ${{ runner.os }}-junit- # key for restoring the cache if no exact match is found
164+
161165
# In this step, we are downloading the latest artifact from the build job and storing it in the container
162-
- run: |
163-
# Download the latest tests results artifact number from the GitHub API using jq to parse the JSON response
164-
curl \
165-
-H "Accept: application/vnd.github+json" \
166-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\
167-
-H "X-GitHub-Api-Version: 2022-11-28" \
168-
https://api.github.com/repos/${{ github.repository }}/actions/artifacts | jq -r '.artifacts | sort_by(.created_at) | .[] | select(.name == "Test Results") | .id' > artifacts_list.txt
166+
- name: Download and unzip all test results artifacts
167+
run: |
168+
# Fetch the last successful workflow run ID
169+
LAST_SUCCESSFUL_RUN_ID=$(curl \
170+
-H "Accept: application/vnd.github+json" \
171+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
172+
-H "X-GitHub-Api-Version: 2022-11-28" \
173+
"https://api.github.com/repos/${{ github.repository }}/actions/runs?status=success&per_page=1" | \
174+
jq -r '.workflow_runs[0].id')
169175
170-
LATEST_ARTIFACT_NUMBER=$(cut -d: -f 2 artifacts_list.txt | sort -n | tail -n 1)
171-
172-
curl \
176+
if [ -z "$LAST_SUCCESSFUL_RUN_ID" ]; then
177+
echo "No successful runs found."
178+
exit 1
179+
fi
180+
181+
ARTIFACT_IDS=$(curl \
173182
-H "Accept: application/vnd.github+json" \
174183
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
175184
-H "X-GitHub-Api-Version: 2022-11-28" \
176-
-L -o my_artifact.zip \
177-
https://api.github.com/repos/${{ github.repository }}/actions/artifacts/"${LATEST_ARTIFACT_NUMBER}"/zip
185+
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${LAST_SUCCESSFUL_RUN_ID}/artifacts" | \
186+
jq -r '.artifacts | sort_by(.created_at) | .[] | select(.name | startswith("testresults-")) | .id')
187+
188+
mkdir -p test_results
189+
190+
echo "Downloading artifacts for run ID: $LAST_SUCCESSFUL_RUN_ID"
191+
192+
for ARTIFACT_ID in $ARTIFACT_IDS; do
193+
curl \
194+
-H "Accept: application/vnd.github+json" \
195+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
196+
-H "X-GitHub-Api-Version: 2022-11-28" \
197+
-L -o my_artifact.zip \
198+
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts/${ARTIFACT_ID}/zip"
178199
179-
mkdir test_results
180-
unzip my_artifact.zip -d test_results 2> /dev/null || true
200+
echo "Contents of my_artifact.zip for artifact ID: $ARTIFACT_ID"
201+
unzip -l my_artifact.zip
202+
203+
unzip my_artifact.zip -d test_results 2> /dev/null || true
204+
echo "Contents of test_results directory for artifact ID: $ARTIFACT_ID"
205+
ls -l test_results
206+
rm my_artifact.zip
207+
done
208+
209+
- name: Ensure junit-path exists and that all xml files are readable in path 'test_results/**/*xml' with this syntax
210+
run: |
211+
if [ ! -d "test_results" ]; then
212+
echo "test_results directory does not exist"
213+
exit 1
214+
fi
215+
if ! ls test_results/*xml 1> /dev/null 2>&1; then
216+
echo "No xml files found in test_results directory"
217+
exit 1
218+
fi
219+
if ! ls -l test_results/*xml 1> /dev/null 2>&1; then
220+
echo "Not all xml files in test_results directory are readable"
221+
exit 1
222+
fi
223+
224+
echo "All xml files in test_results directory are readable"
225+
ls -l test_results/*xml
181226
182227
- name: Setup tmate session
183-
uses: mxschmitt/action-tmate@v3
184-
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
228+
uses: mxschmitt/action-tmate@v3.19
229+
if: ${{ github.event_name == 'workflow_dispatch' && inputs.ssh_debug_enabled }}
185230

186231
# split-tests action - splits the tests into x number of groups
187232
# based on the total number of github-hosted runners and junit previous test results by time and line count.
188233
# Link to the action - https://github.com/marketplace/actions/split-tests
189-
- uses: chaosaffe/split-tests@v1-alpha.1
234+
- uses: scruplelesswizard/split-tests@4f1ca766cb93923ca216e02f1aefed20944e313f
190235
id: split-tests
191236
name: Split tests
192237
with:
193238
glob: src/test/**/**/**.java # glob pattern to match the test files
194239
split-total: ${{ env.total-runners }} # total number of github-hosted runners
195240
split-index: ${{ matrix.runner-index }} # current runner index
196-
junit-path: test_results/*xml # path to the junit test results with wildcards to match all the files
197-
line-count: true # split the tests based on the junit test results by line count
241+
junit-path: test_results/**/*xml # path to the junit test results with wildcards to match all the files
242+
# line-count: true # split the tests based on the junit test results by line count
198243
# run the tests in parallel looping through the test-suite output from the split-tests action
199244
- run: 'echo "This runner will execute the following tests: ${{ steps.split-tests.outputs.test-suite }}"'
200245
- run: |
@@ -206,12 +251,46 @@ jobs:
206251
mvn -Dtest=$(basename $file | sed -e "s/.java/,/" | tr -d '\r\n') -e test -Dspring.datasource.url=${{ secrets.LIQUIBASE_COMMAND_URL }} -Dspring.datasource.username=${{ secrets.LIQUIBASE_COMMAND_USERNAME }} -Dspring.datasource.password=${{ secrets.LIQUIBASE_COMMAND_PASSWORD }} -Dspring.liquibase.change-log=classpath:db/changelog/changelog_version-3.3.xml -Dserver.port=8086 -Dspring.redis.host=redis -Dspring.redis.port=6379 -Dspring.redis.mode=standalone
207252
done
208253
209-
- uses: actions/upload-artifact@v3 # upload the test results as an artifact
254+
- uses: actions/upload-artifact@v4.4.3 # uploading the artifact to the GitHub Artifacts. Link to the documentation - https://docs.github.com/en/actions/guides/storing-workflow-data-as-artifacts
210255
with:
211-
name: Test Results
256+
name: testresults-${{ github.run_id }}-split-${{ matrix.runner-index }} # naming the artifact with the test results
212257
path: ./target/surefire-reports # path to the test results
213258
retention-days: 90 # retention period for the artifact in days. Link to the documentation - https://docs.github.com/en/actions/guides/storing-workflow-data-as-artifacts#about-workflow-artifact-retention
214259

260+
261+
publish-test-results:
262+
needs: [build, unit-parallel-tests]
263+
runs-on: ubuntu-latest
264+
steps:
265+
- name: Checkout repository
266+
uses: actions/[email protected]
267+
268+
- name: List Artifacts
269+
id: list-artifacts
270+
run: |
271+
curl -s -u ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} \
272+
-H 'Accept: application/vnd.github.v3+json' \
273+
https://api.github.com/repos/octodemo/java-springboot-demo/actions/runs/${{ github.run_id }}/artifacts > artifacts.json
274+
cat artifacts.json
275+
276+
- name: Download Artifacts
277+
run: |
278+
mkdir -p test_results
279+
for url in $(jq -r '.artifacts[] | select(.name | startswith("testresults-")) | .archive_download_url' artifacts.json); do
280+
artifact_name=$(echo $url | awk -F/ '{print $NF}' | awk -F? '{print $1}')
281+
curl -s -u ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} -L -o test_results/testresults.zip $url
282+
unzip -o test_results/testresults.zip -d test_results
283+
rm test_results/testresults.zip
284+
done
285+
286+
- name: Publish Test Results
287+
uses: dorny/[email protected]
288+
if: success() || failure()
289+
with:
290+
reporter: java-junit
291+
name: JUnit Test Results
292+
path: test_results/*.xml
293+
215294
build-and-publish-docker-image: # job to build the docker image and publish it to the GitHub Container Registry
216295
runs-on: ubuntu-latest # using the latest ubuntu runner
217296
outputs:
@@ -233,24 +312,24 @@ jobs:
233312
# 6. push the docker image to the GitHub Container Registry
234313
steps:
235314
- name: Checkout repository
236-
uses: actions/checkout@v3
237-
- uses: actions/download-artifact@v1
315+
uses: actions/checkout@v4.2.2
316+
- uses: actions/download-artifact@v4.1.8
238317
with:
239318
name: jar-artifact
240319
path: target/
241320

242321
# build the docker image using the Dockerfile in the root of the repository
243322
# and tag it with the current run number from the github action workflow run
244323
- name: Log in to the GH Container Registry
245-
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 # using the docker login action from the github marketplace - github.com/marketplace/actions/docker-login
324+
uses: docker/login-action@v3.3.0 # using the docker login action from the github marketplace - github.com/marketplace/actions/docker-login
246325
with:
247326
registry: ${{ env.REGISTRY }} # using the registry environment variable
248327
username: ${{ github.actor }} # using the github.actor context
249328
password: ${{ secrets.GITHUB_TOKEN }} # using the GITHUB_TOKEN secret
250329

251330
- name: Build and push Docker image
252331
id: build_image
253-
uses: docker/build-push-action@v4 # using the docker build and push action from the github marketplace - github.com/marketplace/actions/build-and-push-docker-images
332+
uses: docker/build-push-action@v6.9.0 # using the docker build and push action from the github marketplace - github.com/marketplace/actions/build-and-push-docker-images
254333
with:
255334
context: . # using the current directory as the context
256335
push: true # push the docker image to the registry

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ ENV USER_NAME=postgres
55
ENV PASSWORD=password
66
ENV CHANGELOG_VERSION=master.xml
77
ENV SPRING_JPA_PROPERTIES_HIBERNATE_DEFAULT_SCHEMA=public
8+
ENV SEARCH_FEATURE_FLAG=false
89
RUN mkdir workspace
910
WORKDIR /workspace/
1011
COPY target/salesmanager-*-SNAPSHOT.jar .
1112
EXPOSE 8086
12-
CMD ["/bin/sh", "-c", "java -jar salesmanager-*-SNAPSHOT.jar --spring.datasource.url=${DB_URL} --spring.datasource.username=${USER_NAME} --spring.datasource.password=${PASSWORD} --spring.redis.port=6379 --spring.redis.host=${REDIS_HOST} --spring.liquibase.change-log=classpath:db/changelog/${CHANGELOG_VERSION}"]
13+
CMD ["/bin/sh", "-c", "java -DenableSearchFeature=${SEARCH_FEATURE_FLAG} -jar salesmanager-*-SNAPSHOT.jar --spring.datasource.url=${DB_URL} --spring.datasource.username=${USER_NAME} --spring.datasource.password=${PASSWORD} --spring.redis.port=6379 --spring.redis.host=${REDIS_HOST} --spring.liquibase.change-log=classpath:db/changelog/${CHANGELOG_VERSION}"]

build_and_run_app_in_container.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ trap cleanup EXIT
2525

2626
set -e # Exit immediately if a command exits with a non-zero status.
2727
# Getting local ip address from ifconfig
28-
LOCAL_IP=$(ifconfig | grep 'inet ' | grep -Fv 127.0.0.1 | awk '{print $2}')
28+
# LOCAL_IP=$(ifconfig | grep 'inet ' | grep -Fv 127.0.0.1 | awk '{print $2}')
29+
LOCAL_IP=192.168.64.1
2930
# Run a postgresql container with a volume to persist data
3031
docker run -d -p 5432:5432 --name postgres_container -e POSTGRES_PASSWORD=Password123 -v postgresql-data:/var/lib/postgresql/data postgres
3132
# [Optional] Run any previous migrations and tag the latest version with Liquibase

my-chart/templates/spring-app-deployment-v1.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ spec:
3131
value: {{ .Values.v1.springAppContainer.env.redisHost }}
3232
- name: KUBERNETES_CLUSTER_DOMAIN
3333
value: {{ .Values.kubernetesClusterDomain }}
34+
- name: SEARCH_FEATURE_FLAG
35+
value: {{ .Values.v1.springAppContainer.env.searchFeatureEnabled | quote }}
3436
image: {{ .Values.v1.springAppContainer.image.repository }}:{{ .Values.v1.springAppContainer.image.tag }}
3537
imagePullPolicy: Always
3638
name: spring-app-container

my-chart/templates/spring-app-deployment-v2.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ spec:
2929
value: {{ .Values.v2.springAppContainer.env.changelogVersion }}
3030
- name: REDIS_HOST
3131
value: {{ .Values.v2.springAppContainer.env.redisHost }}
32+
- name: SEARCH_FEATURE_FLAG
33+
value: {{ .Values.v2.springAppContainer.env.searchFeatureFlag | quote }}
3234
image: {{ .Values.v2.springAppContainer.image.repository }}:{{ .Values.v2.springAppContainer.image.tag }}
3335
imagePullPolicy: Always
3436
name: spring-app-container

my-chart/values.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
v1:
2-
replicas: 1
2+
replicas: 2
33
springAppContainer:
44
env:
55
changelogVersion: changelog_version-3.3.xml
66
dbUrl: jdbc:postgresql://postgres-database-service:5432/postgres
77
password: admin123
88
redisHost: redis-database-service
99
userName: postgresadmin
10+
searchFeatureEnabled: "false"
1011
image:
1112
repository: ghcr.io/octodemo/java-springboot-demo
12-
tag: "199"
13+
tag: "273"
1314
resources:
1415
limits:
1516
cpu: "1"
@@ -18,17 +19,18 @@ v1:
1819
cpu: 125m
1920
memory: 128Mi
2021
v2:
21-
replicas: 3
22+
replicas: 2
2223
springAppContainer:
2324
env:
2425
changelogVersion: changelog_version-3.3.xml
2526
dbUrl: jdbc:postgresql://postgres-database-service:5432/postgres
2627
password: admin123
2728
redisHost: redis-database-service
2829
userName: postgresadmin
30+
searchFeatureFlag: "true"
2931
image:
3032
repository: ghcr.io/octodemo/java-springboot-demo
31-
tag: "198"
33+
tag: "274"
3234
resources:
3335
limits:
3436
cpu: "1"

0 commit comments

Comments
 (0)