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

refactor: dbaas meta service check #302

Merged
merged 2 commits into from
Mar 8, 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
15 changes: 15 additions & 0 deletions cmd/template_dbaas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ func TestDBaaSTemplateGeneration(t *testing.T) {
templatePath: "testdata/output",
want: "../internal/testdata/node/dbaas-templates/dbaas-2",
},
{
name: "test6 - postgres",
args: testdata.GetSeedData(
testdata.TestData{
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "../internal/testdata/complex/lagoon.services.yml",
ProjectVariables: []lagoon.EnvironmentVariable{
{Name: "LAGOON_DBAAS_ENVIRONMENT_TYPES", Value: "postgres-15:production-postgres,mongo-4:production-mongo", Scope: "build"},
},
}, true),
templatePath: "testdata/output",
want: "../internal/testdata/complex/dbaas-templates/dbaas-4",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
26 changes: 26 additions & 0 deletions internal/testdata/complex/dbaas-templates/dbaas-4/dbaas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
apiVersion: mariadb.amazee.io/v1
kind: MariaDBConsumer
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: mariadb-10-11
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: mariadb-dbaas
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: mariadb-10-11
lagoon.sh/service-type: mariadb-dbaas
lagoon.sh/template: mariadb-dbaas-0.1.0
name: mariadb-10-11
spec:
consumer:
services: {}
environment: production
provider: {}
status: {}
116 changes: 116 additions & 0 deletions internal/testdata/complex/docker-compose.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
version: '2'

volumes:
solr-7-data:
solr-8-data:
opensearch-2-data:
scratch:

services:
web:
build:
context: .
dockerfile: Dockerfile
labels:
lagoon.type: basic-persistent
lagoon.persistent: /app/files
lagoon.persistent.size: 10Mi
lagoon.persistent.class: bulk
ports:
- '3000:3000'
container_name: go-web
environment:
- LAGOON_TEST_VAR=internal-services-test
- LAGOON_GIT_SHA=SHA256
- LAGOON_ENVIRONMENT_TYPE=development
- STORAGE_LOCATION=/app/files
volumes:
- scratch:/app/files

mariadb-10-5:
image: uselagoon/mariadb-10.5:latest
labels:
lagoon.type: mariadb-single
lagoon.persistent.size: 100Mi
ports:
- '3306'

mariadb-10-11:
image: uselagoon/mariadb-10.11:latest
labels:
lagoon.type: mariadb
ports:
- '3306'

postgres-11:
image: uselagoon/postgres-11:latest
labels:
lagoon.type: postgres-single
lagoon.persistent.size: 100Mi
ports:
- '5432'

postgres-15:
image: uselagoon/postgres-15:latest
labels:
lagoon.type: postgres
ports:
- '5432'

opensearch-2:
image: uselagoon/opensearch-2:latest
environment:
- cluster.name=opensearch-cluster
- node.name=opensearch-2
- discovery.seed_hosts=opensearch-2
- cluster.initial_cluster_manager_nodes=opensearch-2
- bootstrap.memory_lock=true
- "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
volumes:
- opensearch-2-data:/usr/share/opensearch/data
labels:
lagoon.type: opensearch
lagoon.persistent.size: 100Mi
ports:
- '9200'

mongo-4:
image: uselagoon/mongo-4:latest
labels:
lagoon.type: mongo
ports:
- '27017'

redis-6:
image: uselagoon/redis-5:latest
labels:
lagoon.type: redis
ports:
- '6379'

redis-7:
image: uselagoon/redis-6:latest
labels:
lagoon.type: redis
ports:
- '6379'

solr-8:
image: uselagoon/solr-8:latest
labels:
lagoon.type: solr
lagoon.persistent.size: 100Mi
ports:
- "8983"
volumes:
- solr-8-data:/var/solr
command:
- solr-precreate
- mycore
5 changes: 5 additions & 0 deletions internal/testdata/complex/lagoon.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
docker-compose-yaml: ../internal/testdata/complex/docker-compose.services.yml

environment_variables:
git_sha: 'true'
32 changes: 30 additions & 2 deletions legacy/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then
fi
set -x

# loop through created DBAAS templates
DBAAS=($(build-deploy-tool identify dbaas))
for COMPOSE_SERVICE in "${COMPOSE_SERVICES[@]}"
do
# The name of the service can be overridden, if not we use the actual servicename
Expand Down Expand Up @@ -444,6 +446,34 @@ do
# The ImageName is the same as the Name of the Docker Compose ServiceName
IMAGE_NAME=$COMPOSE_SERVICE

for DBAAS_ENTRY in "${DBAAS[@]}"
do
IFS=':' read -ra DBAAS_ENTRY_SPLIT <<< "$DBAAS_ENTRY"
DBAAS_SERVICE_NAME=${DBAAS_ENTRY_SPLIT[0]}
DBAAS_SERVICE_TYPE=${DBAAS_ENTRY_SPLIT[1]}
if [ "$SERVICE_TYPE" == "mariadb" ]; then
if [ "$DBAAS_SERVICE_NAME" == "$SERVICE_NAME" ]; then
SERVICE_TYPE=$DBAAS_SERVICE_TYPE
else
SERVICE_TYPE="mariadb-single"
fi
fi
if [ "$SERVICE_TYPE" == "postgres" ]; then
if [ "$DBAAS_SERVICE_NAME" == "$SERVICE_NAME" ]; then
SERVICE_TYPE=$DBAAS_SERVICE_TYPE
else
SERVICE_TYPE="postgres-single"
fi
fi
if [ "$SERVICE_TYPE" == "mongo" ]; then
if [ "$DBAAS_SERVICE_NAME" == "$SERVICE_NAME" ]; then
SERVICE_TYPE=$DBAAS_SERVICE_TYPE
else
SERVICE_TYPE="mongodb-single"
fi
fi
done

# Do not handle images for shared services
if [[ "$SERVICE_TYPE" != "mariadb-dbaas" ]] &&
[[ "$SERVICE_TYPE" != "mariadb-shared" ]] &&
Expand Down Expand Up @@ -1303,8 +1333,6 @@ do

SERVICE_NAME=${DBAAS_ENTRY_SPLIT[0]}
SERVICE_TYPE=${DBAAS_ENTRY_SPLIT[1]}
# remove the image from images to pull
unset IMAGES_PULL[$SERVICE_NAME]
tobybellwood marked this conversation as resolved.
Show resolved Hide resolved

SERVICE_NAME_UPPERCASE=$(echo "$SERVICE_NAME" | tr '[:lower:]' '[:upper:]' | tr '-' '_')

Expand Down
Loading