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

chore: Migrated orders component to Spring Data JDBC and PostgreSQL #429

Merged
merged 8 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 21 additions & 18 deletions deploy/docker-compose/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so.
#
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
Expand All @@ -19,7 +19,7 @@ version: '2'
services:
ui:
ports:
- 8888:8080
- 8888:8080
environment:
- JAVA_OPTS=-XX:MaxRAMPercentage=75.0 -Djava.security.egd=file:/dev/urandom
- SERVER_TOMCAT_ACCESSLOG_ENABLED=true
Expand Down Expand Up @@ -79,36 +79,39 @@ services:
hostname: carts-db
restart: always
mem_limit: 256m

orders:
hostname: orders
image: retail-store-sample-orders:${TAG:-latest}
restart: always
environment:
- JAVA_OPTS=-XX:MaxRAMPercentage=75.0 -Djava.security.egd=file:/dev/urandom
- SERVER_TOMCAT_ACCESSLOG_ENABLED=true
- SPRING_PROFILES_ACTIVE=mysql,rabbitmq
- SPRING_DATASOURCE_WRITER_URL=jdbc:mariadb://orders-db:3306/orders
- SPRING_DATASOURCE_WRITER_USERNAME=orders_user
- SPRING_DATASOURCE_WRITER_PASSWORD=${MYSQL_PASSWORD}
- SPRING_DATASOURCE_READER_URL=jdbc:mariadb://orders-db:3306/orders
- SPRING_DATASOURCE_READER_USERNAME=orders_user
- SPRING_DATASOURCE_READER_PASSWORD=${MYSQL_PASSWORD}
- SPRING_PROFILES_ACTIVE=rabbitmq
- SPRING_DATASOURCE_URL=jdbc:postgresql://orders-db:5432/orders
- SPRING_DATASOURCE_USERNAME=orders_user
- SPRING_DATASOURCE_PASSWORD=${MYSQL_PASSWORD}
- SPRING_RABBITMQ_HOST=rabbitmq
mem_limit: 512m
cap_drop:
- ALL

orders-db:
image: mariadb:10.9
image: postgres:16.1
hostname: orders-db
restart: always
security_opt:
- no-new-privileges:true
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_PASSWORD}
- MYSQL_ALLOW_EMPTY_PASSWORD=true
- MYSQL_DATABASE=orders
- MYSQL_USER=orders_user
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- reschedule=on-node-failure
- POSTGRES_PASSWORD=${MYSQL_PASSWORD}
- POSTGRES_DB=orders
- POSTGRES_USER=orders_user
healthcheck:
test: [ "CMD-SHELL", "pg_isready -d orders -U orders_user" ]
interval: 10s
timeout: 5s
retries: 30
mem_limit: 128m

checkout:
Expand Down Expand Up @@ -145,4 +148,4 @@ services:
image: rabbitmq:3-management
ports:
- "5672:5672"
- "15672:15672"
- "15672:15672"
48 changes: 16 additions & 32 deletions deploy/kubernetes/charts/orders/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,29 @@ Create the name of the config map to use
{{- end }}
{{- end -}}

{{- define "orders.mysql.fullname" -}}
{{- include "orders.fullname" . }}-mysql
{{- define "orders.postgresql.fullname" -}}
{{- include "orders.fullname" . }}-postgresql
{{- end -}}

{{/*
Common labels for mysql
Common labels for postgresql
*/}}
{{- define "orders.mysql.labels" -}}
{{- define "orders.postgresql.labels" -}}
helm.sh/chart: {{ include "orders.chart" . }}
{{ include "orders.mysql.selectorLabels" . }}
{{ include "orders.postgresql.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels for mysql
Selector labels for postgresql
*/}}
{{- define "orders.mysql.selectorLabels" -}}
{{- define "orders.postgresql.selectorLabels" -}}
app.kubernetes.io/name: {{ include "orders.fullname" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: mysql
app.kubernetes.io/component: postgresql
{{- end }}

{{- define "getOrGeneratePass" }}
Expand All @@ -123,35 +123,19 @@ app.kubernetes.io/component: mysql
{{- end -}}
{{- end }}

{{- define "orders.mysql.password" -}}
{{- if not (empty .Values.mysql.secret.password) -}}
{{- .Values.mysql.secret.password | b64enc -}}
{{- define "orders.postgresql.password" -}}
{{- if not (empty .Values.postgresql.secret.password) -}}
{{- .Values.postgresql.secret.password | b64enc -}}
{{- else -}}
{{- include "getOrGeneratePass" (dict "Namespace" .Release.Namespace "Kind" "Secret" "Name" .Values.mysql.secret.name "Key" "password") -}}
{{- include "getOrGeneratePass" (dict "Namespace" .Release.Namespace "Kind" "Secret" "Name" .Values.postgresql.secret.name "Key" "password") -}}
{{- end -}}
{{- end -}}

{{- define "orders.mysql.reader.password" -}}
{{- if not (empty .Values.mysql.reader.secret.password) -}}
{{- .Values.mysql.reader.secret.password | b64enc -}}
{{- define "orders.postgresql.endpoint" -}}
{{- if not (empty .Values.postgresql.endpoint.host) -}}
jdbc:postgresql://{{- .Values.postgresql.endpoint.host -}}:{{- .Values.postgresql.endpoint.port -}}/{{ .Values.postgresql.database }}
{{- else -}}
{{- include "getOrGeneratePass" (dict "Namespace" .Release.Namespace "Kind" "Secret" "Name" .Values.mysql.reader.secret.name "Key" "password") -}}
{{- end -}}
{{- end -}}

{{- define "orders.mysql.endpoint" -}}
{{- if not (empty .Values.mysql.endpoint) -}}
{{- .Values.mysql.endpoint -}}
{{- else -}}
jdbc:mariadb://{{ include "orders.mysql.fullname" . }}:{{ .Values.mysql.service.port }}/{{ .Values.mysql.database }}
{{- end -}}
{{- end -}}

{{- define "orders.mysql.reader.endpoint" -}}
{{- if not (empty .Values.mysql.reader.endpoint) -}}
{{- .Values.mysql.reader.endpoint -}}
{{- else -}}
{{- include "orders.mysql.endpoint" . -}}
jdbc:postgresql://{{ include "orders.postgresql.fullname" . }}:{{ .Values.postgresql.service.port }}/{{ .Values.postgresql.database }}
{{- end -}}
{{- end -}}

Expand Down
5 changes: 2 additions & 3 deletions deploy/kubernetes/charts/orders/templates/configmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ kind: ConfigMap
metadata:
name: {{ include "orders.configMapName" . }}
data:
SPRING_PROFILES_ACTIVE: mysql,rabbitmq
SPRING_DATASOURCE_READER_URL: {{ include "orders.mysql.endpoint" . }}
SPRING_DATASOURCE_WRITER_URL: {{ include "orders.mysql.reader.endpoint" . }}
SPRING_PROFILES_ACTIVE: rabbitmq
SPRING_DATASOURCE_URL: {{ include "orders.postgresql.endpoint" . }}
SPRING_RABBITMQ_ADDRESSES: {{ include "orders.rabbitmq.addresses" . }}
{{- end }}
18 changes: 4 additions & 14 deletions deploy/kubernetes/charts/orders/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,15 @@ spec:
env:
- name: JAVA_OPTS
value: -XX:MaxRAMPercentage=75.0 -Djava.security.egd=file:/dev/urandom
- name: SPRING_DATASOURCE_WRITER_USERNAME
- name: SPRING_DATASOURCE_USERNAME
valueFrom:
secretKeyRef:
name: {{ .Values.mysql.secret.name }}
name: {{ .Values.postgresql.secret.name }}
key: username
- name: SPRING_DATASOURCE_WRITER_PASSWORD
- name: SPRING_DATASOURCE_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.mysql.secret.name }}
key: password
- name: SPRING_DATASOURCE_READER_USERNAME
valueFrom:
secretKeyRef:
name: {{ .Values.mysql.reader.secret.name }}
key: username
- name: SPRING_DATASOURCE_READER_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.mysql.reader.secret.name }}
name: {{ .Values.postgresql.secret.name }}
key: password
envFrom:
- secretRef:
Expand Down

This file was deleted.

9 changes: 0 additions & 9 deletions deploy/kubernetes/charts/orders/templates/mysql-secret.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions deploy/kubernetes/charts/orders/templates/mysql-service.yaml

This file was deleted.

97 changes: 0 additions & 97 deletions deploy/kubernetes/charts/orders/templates/mysql-statefulset.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- if .Values.postgresql.secret.create }}
apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.postgresql.secret.name }}
data:
username: {{ .Values.postgresql.secret.username | b64enc | quote }}
password: "{{ include "orders.postgresql.password" . }}"
{{- end }}
17 changes: 17 additions & 0 deletions deploy/kubernetes/charts/orders/templates/postgresql-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if .Values.postgresql.create }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "orders.postgresql.fullname" . }}
labels:
{{- include "orders.postgresql.labels" . | nindent 4 }}
spec:
type: {{ .Values.postgresql.service.type }}
ports:
- port: {{ .Values.postgresql.service.port }}
targetPort: postgresql
protocol: TCP
name: postgresql
selector:
{{- include "orders.postgresql.selectorLabels" . | nindent 4 }}
{{- end }}
Loading