Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9b79aad

Browse files
Merge branch 'CFT_v2' into 'master'
AWS Marketplace version: use $N datasets and parametrized Docker image See merge request postgres-ai/database-lab!533
2 parents 004f3db + ec6289a commit 9b79aad

File tree

1 file changed

+74
-27
lines changed

1 file changed

+74
-27
lines changed

‎cloudformation/dle_cf_template.yaml‎

Lines changed: 74 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,29 @@ Metadata:
3434
Label:
3535
default: "Source PostgreSQL parameters"
3636
Parameters:
37+
- SourceDatabaseSize
3738
- SourcePostgresHost
3839
- SourcePostgresPort
3940
- SourcePostgresUsername
4041
- SourcePostgresPassword
4142
- SourcePostgresDBName
42-
- SourcePostgresVersion
4343
- PostgresConfigSharedPreloadLibraries
4444
- SourcePostgresDBList
45+
-
46+
Label:
47+
default: "Advanced DLE configuration"
48+
Parameters:
49+
- PostgresDockerImage
50+
- DLEZFSDataSetsNumber
4551
ParameterLabels:
4652
KeyName:
4753
default: "Key pair"
4854
InstanceType:
4955
default: "Instance type"
5056
SSHLocation:
5157
default: "Connection source IP range"
52-
ZFSVolumeSize:
53-
default: "EBS volume size in GB for ZFS"
58+
SourceDatabaseSize:
59+
default: "Total source database size in GiB"
5460
CertificateSubdomain:
5561
default: "Certificate subdomain"
5662
CertificateHostedZone:
@@ -63,6 +69,10 @@ Metadata:
6369
default: "DLE verification token"
6470
DLERetrievalRefreshTimetable:
6571
default: "DLE retrieval refresh timetable"
72+
PostgresDockerImage:
73+
default: "Postgres docker image"
74+
DLEZFSDataSetsNumber:
75+
default: "Number of supported snapshots."
6676
PostgresDumpParallelJobs:
6777
default: "Number of pg_dump jobs"
6878
SourcePostgresDBName:
@@ -71,8 +81,6 @@ Metadata:
7181
default: "VPC security group"
7282
Subnet:
7383
default: "Subnet"
74-
SourcePostgresVersion:
75-
default: "Postgres version"
7684
SourcePostgresHost:
7785
default: "Host name or IP"
7886
SourcePostgresPort:
@@ -85,7 +93,6 @@ Metadata:
8593
default: "shared_preload_libraries parameter"
8694
SourcePostgresDBList:
8795
default: "Comma separated list of databases to copy"
88-
8996
Parameters:
9097
Subnet:
9198
Description: Subnet to attach EC2 machine.
@@ -134,8 +141,8 @@ Parameters:
134141
MaxLength: '18'
135142
AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})'
136143
ConstraintDescription: Must be a valid IP CIDR range of the form x.x.x.x/x
137-
ZFSVolumeSize:
138-
Description: The size of the EBS volumes used for DLE ZFS pool
144+
SourceDatabaseSize:
145+
Description: The size of the source databases used to calculate the size of EBS volume, in GiB
139146
Type: Number
140147
Default: 40
141148
CertificateSubdomain:
@@ -167,21 +174,20 @@ Parameters:
167174
Description: DLE refresh schedule on cron format
168175
Type: String
169176
Default: '0 0 * * *'
177+
DLEZFSDataSetsNumber:
178+
Description: Number of database copies needed
179+
Type: Number
180+
Default: 2
181+
MinValue: 2
182+
MaxValue: 100
183+
PostgresDockerImage:
184+
Description: Docker image to run PostgreSQL
185+
Type: String
186+
Default: 'postgresai/extended-postgres:14'
170187
SourcePostgresDBName:
171188
Description: Source database name. This parameter is used to connect to the database
172189
Type: String
173190
Default: 'postgres'
174-
SourcePostgresVersion:
175-
Description: Source database Postgres version
176-
Type: String
177-
Default: 14
178-
AllowedValues:
179-
- 9.6
180-
- 10
181-
- 11
182-
- 12
183-
- 13
184-
- 14
185191
SourcePostgresHost:
186192
Description: Source Postgres cluster host name or IP
187193
Type: String
@@ -301,13 +307,45 @@ Conditions:
301307
!Not [!Equals [!Ref CertificateHostedZone, '']]
302308

303309
Resources:
310+
LambdaExecutionRole:
311+
Type: AWS::IAM::Role
312+
Properties:
313+
AssumeRolePolicyDocument:
314+
Version: '2012年10月17日'
315+
Statement:
316+
- Effect: Allow
317+
Principal: {Service: [lambda.amazonaws.com]}
318+
Action: ['sts:AssumeRole']
319+
Path: "/"
320+
ManagedPolicyArns:
321+
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
322+
PowerFunction:
323+
Type: AWS::Lambda::Function
324+
Properties:
325+
Handler: index.handler
326+
Role: !GetAtt LambdaExecutionRole.Arn
327+
Code:
328+
ZipFile: !Sub |
329+
var response = require('cfn-response');
330+
exports.handler = function(event, context) {
331+
var result = parseInt(event.ResourceProperties.Op1)*(parseInt(event.ResourceProperties.Op2)+2);
332+
response.send(event, context, response.SUCCESS, {Value: result});
333+
};
334+
Runtime: nodejs14.x
335+
SizeCalculate:
336+
Type: Custom::Power
337+
Properties:
338+
ServiceToken: !GetAtt PowerFunction.Arn
339+
Op1: !Ref SourceDatabaseSize
340+
Op2: !Ref DLEZFSDataSetsNumber
341+
304342
ZFSVolume:
305343
Type: AWS::EC2::Volume
306344
DeletionPolicy: Snapshot
307345
Properties:
308346
Encrypted: True
309347
AvailabilityZone: !GetAtt DLEInstance.AvailabilityZone
310-
Size: !Ref ZFSVolumeSize
348+
Size: !GetAtt SizeCalculate.Value
311349
Tags:
312350
-
313351
Key: Name
@@ -342,7 +380,6 @@ Resources:
342380
set -ex
343381

344382
sleep 30
345-
346383

347384
# This code tested and works on Ubuntu 20.04 (current base AMI)
348385
disk=$(lsblk -e7 --output PATH,NAME,FSTYPE --json | jq -r '.blockdevices[] | select(.children == null and .fstype == null) | .path ')
@@ -356,6 +393,10 @@ Resources:
356393
dblab_pool \
357394
$disk
358395

396+
for i in {1..${DLEZFSDataSetsNumber}}; do
397+
sudo zfs create dblab_pool/dataset_$i
398+
done
399+
359400
dle_config_path="/home/ubuntu/.dblab/engine/configs"
360401
dle_meta_path="/home/ubuntu/.dblab/engine/meta"
361402
postgres_conf_path="/home/ubuntu/.dblab/postgres_conf"
@@ -366,9 +407,11 @@ Resources:
366407
.server.verificationToken="${DLEVerificationToken}" |
367408
.retrieval.refresh.timetable="${DLERetrievalRefreshTimetable}" |
368409
.retrieval.spec.logicalRestore.options.forceInit=true |
369-
.databaseContainer.dockerImage="postgresai/extended-postgres:${SourcePostgresVersion}" |
370-
.databaseConfigs.configs.shared_preload_libraries="${PostgresConfigSharedPreloadLibraries}" |
371-
.databaseContainer.dockerImage="postgresai/extended-postgres:${SourcePostgresVersion}"
410+
.poolManager.mountDir = "/var/lib/dblab/dblab_pool" |
411+
.retrieval.spec.logicalDump.options.dumpLocation="/var/lib/dblab/dblab_pool/dataset_1/dump/" |
412+
.retrieval.spec.logicalRestore.options.dumpLocation="/var/lib/dblab/dblab_pool/dataset_1/dump/" |
413+
.databaseContainer.dockerImage="${PostgresDockerImage}" |
414+
.databaseConfigs.configs.shared_preload_libraries="${PostgresConfigSharedPreloadLibraries}"
372415
' $dle_config_path/server.yml
373416
374417
yq e -i '
@@ -397,13 +440,13 @@ Resources:
397440
--publish 2345:2345 \
398441
--volume /var/run/docker.sock:/var/run/docker.sock \
399442
--volume /var/lib/dblab:/var/lib/dblab/:rshared \
400-
--volume /var/lib/dblab/dblab_pool/dump:/var/lib/dblab/dblab_pool/dump/:rshared \
443+
--volume /var/lib/dblab/dblab_pool/dataset_1/dump/:/var/lib/dblab/dblab_pool/dataset_1/dump/:rshared \
401444
--volume $dle_config_path:/home/dblab/configs:ro \
402445
--volume $dle_meta_path:/home/dblab/meta \
403446
--volume $postgres_conf_path:/home/dblab/standard/postgres/control \
404447
--env DOCKER_API_VERSION=1.39 \
405448
--restart always \
406-
registry.gitlab.com/postgres-ai/database-lab/dblab-server:3.0.3
449+
registry.gitlab.com/postgres-ai/database-lab/dblab-server:3.1.0
407450
408451
if [ ! -z "${CertificateHostedZone}" ]; then
409452
export DOMAIN=${CertificateSubdomain}.${CertificateHostedZone}
@@ -495,7 +538,6 @@ Resources:
495538
CidrIp: '0.0.0.0/0'
496539
VpcId: !Ref VPC
497540

498-
499541
Outputs:
500542
VerificationToken:
501543
Description: 'DLE verification token'
@@ -511,6 +553,10 @@ Outputs:
511553
Value: !Sub 'https://${CertificateSubdomain}.${CertificateHostedZone}:446'
512554
Condition: CreateSubDomain
513555

556+
EBSVolume:
557+
Description: Size of provisioned EBS volume
558+
Value: !GetAtt SizeCalculate.Value
559+
514560
DNSName:
515561
Description: Public DNS name
516562
Value: !GetAtt DLEInstance.PublicDnsName
@@ -538,3 +584,4 @@ Outputs:
538584
Value: !Sub
539585
- 'ssh -N -L CLONE_PORT:${DNSName}:CLONE_PORT -i YOUR_PRIVATE_KEY ubuntu@${DNSName}'
540586
- DNSName: !GetAtt DLEInstance.PublicDnsName
587+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /