1+ #
2+ # Licensed to the Apache Software Foundation (ASF) under one
3+ # or more contributor license agreements. See the NOTICE file
4+ # distributed with this work for additional information
5+ # regarding copyright ownership. The ASF licenses this file
6+ # to you under the Apache License, Version 2.0 (the
7+ # "License"); you may not use this file except in compliance
8+ # with the License. You may obtain a copy of the License at
9+ #
10+ # http://www.apache.org/licenses/LICENSE-2.0
11+ #
12+ # Unless required by applicable law or agreed to in writing,
13+ # software distributed under the License is distributed on an
14+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+ # KIND, either express or implied. See the License for the
16+ # specific language governing permissions and limitations
17+ # under the License.
18+ #
19+
20+ EC2_INSTANCE_ID=$( cat /var/lib/cloud/data/instance-id)
21+
22+ DESCRIBE_INSTANCE=$( aws ec2 describe-instances \
23+ --instance-ids $EC2_INSTANCE_ID \
24+ --query ' Reservations[*].Instances[*].{Instance:InstanceId,VPC:VpcId,AZ:Placement.AvailabilityZone}' \
25+ --output json)
26+
27+ CURRENT_VPC=$( echo $DESCRIBE_INSTANCE | jq -r .[0].[0]." VPC" )
28+
29+ CURRENT_REGION=$( echo $DESCRIBE_INSTANCE | jq -r .[0].[0]." AZ" | sed ' s/.$//' )
30+
31+ ALL_SUBNETS=$( aws ec2 describe-subnets \
32+ --region $CURRENT_REGION \
33+ --query ' Subnets[*].{SubnetId:SubnetId}' \
34+ --output json \
35+ | jq -r ' [.[]["SubnetId"]] | join(" ")' )
36+
37+ RANDOM_SUFFIX=$( head /dev/urandom | tr -dc ' A-Za-z0-9' | head -c 8)
38+ SUBNET_GROUP_NAME=" polaris-db-subnet-group-$RANDOM_SUFFIX "
39+ INSTANCE_NAME=" polaris-backend-test-$RANDOM_SUFFIX "
40+
41+ aws rds create-db-subnet-group \
42+ --db-subnet-group-name $SUBNET_GROUP_NAME \
43+ --db-subnet-group-description " Apache Polaris Quickstart DB Subnet Group" \
44+ --subnet-ids $ALL_SUBNETS
45+
46+ DB_INSTANCE_INFO=$( aws rds create-db-instance \
47+ --db-instance-identifier $INSTANCE_NAME \
48+ --db-instance-class db.t3.micro \
49+ --engine postgres \
50+ --master-username postgres \
51+ --master-user-password postgres \
52+ --db-name POLARIS \
53+ --db-subnet-group-name $SUBNET_GROUP_NAME \
54+ --allocated-storage 10)
55+
56+ DB_ARN=$( echo $DB_INSTANCE_INFO | jq -r ' .["DBInstance"]["DBInstanceArn"]' )
57+
58+ DESCRIBE_DB=$( aws rds describe-db-instances --db-instance-identifier $DB_ARN )
59+
60+ until echo $DESCRIBE_DB | jq -e ' .["DBInstances"][0] | has("Endpoint")' ;
61+ do
62+ echo " sleeping 10s to wait for Postgres DB provisioning..."
63+ sleep 10
64+ DESCRIBE_DB=$( aws rds describe-db-instances --db-instance-identifier $DB_ARN )
65+ done
66+
67+ POSTGRES_ADDR=$( echo $DESCRIBE_DB | jq -r ' .["DBInstances"][0]["Endpoint"]' | jq -r ' "\(.Address):\(.Port)"' )
68+
69+ FULL_POSTGRES_ADDR=$( printf ' %s\n' " jdbc:postgresql://$POSTGRES_ADDR /{realm}" | sed ' s/[&/\]/\\&/g' )
70+ sed -i " /jakarta.persistence.jdbc.url/ s|value=\" [^\" ]*\" |value=\" $FULL_POSTGRES_ADDR \" |" " getting-started/assets/eclipselink/persistence.xml"
71+
72+ ./gradlew clean :polaris-quarkus-server:assemble :polaris-quarkus-admin:assemble \
73+ -PeclipseLinkDeps=org.postgresql:postgresql:42.7.4 \
74+ -Dquarkus.container-image.tag=postgres-latest \
75+ -Dquarkus.container-image.build=true \
76+ --no-build-cache
77+
78+ docker compose -f getting-started/eclipselink/docker-compose-bootstrap-db.yml -f getting-started/eclipselink/docker-compose.yml up -d
0 commit comments