Skip to content

Commit 060b8ce

Browse files
committed
feat: replace sed-instructions with the yq processor
1 parent 4c85841 commit 060b8ce

File tree

1 file changed

+44
-26
lines changed

1 file changed

+44
-26
lines changed

dle-logical-init.sh.tpl

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -114,37 +114,49 @@ curl https://gitlab.com/postgres-ai/database-lab/-/raw/${dle_version}/configs/st
114114
curl https://gitlab.com/postgres-ai/database-lab/-/raw/${dle_version}/configs/standard/postgres/control/postgresql.conf --output $postgres_conf_path/postgresql.conf
115115
cat /tmp/postgresql_clones_custom.conf >> $postgres_conf_path/postgresql.conf
116116

117-
sed -ri "s/^(\s*)(debug:.*$)/\1debug: ${dle_debug_mode}/" $dle_config_path/server.yml
118-
sed -ri "s/^(\s*)(verificationToken:.*$)/\1verificationToken: ${dle_verification_token}/" $dle_config_path/server.yml
119-
sed -ri "s/^(\s*)(timetable:.*$)/\1timetable: \"${dle_retrieval_refresh_timetable}\"/" $dle_config_path/server.yml
120-
sed -ri "s/^(\s*)(forceInit:.*$)/\1forceInit: true/" $dle_config_path/server.yml
121-
sed -ri "s/^(\s*)(dbname:.*$)/\1dbname: ${source_postgres_dbname}/" $dle_config_path/server.yml
117+
# TODO: move to Packer instructions.
118+
wget https://github.com/mikefarah/yq/releases/download/v4.14.1/yq_linux_amd64 -O /usr/bin/yq &&\
119+
chmod +x /usr/bin/yq
120+
121+
yq e -i '
122+
.global.debug=${dle_debug_mode} |
123+
.server.verificationToken="${dle_verification_token}" |
124+
.retrieval.refresh.timetable="${dle_retrieval_refresh_timetable}" |
125+
.retrieval.spec.logicalDump.options.source.connection.dbname="${source_postgres_dbname}" |
126+
.retrieval.spec.logicalRestore.options.forceInit=true |
127+
.databaseContainer.dockerImage="postgresai/extended-postgres:${source_postgres_version}"
128+
' $dle_config_path/server.yml
129+
122130
# Enable Platform
123-
sed -ri "s/^(\s*)(#platform:$)/\1platform: /" $dle_config_path/server.yml
124-
sed -ri "s/^(\s*)(# url: \"https\\:\\/\\/postgres.ai\\/api\\/general\"$)/\1 url: \"https\\:\\/\\/postgres.ai\\/api\\/general\" /" $dle_config_path/server.yml
125-
sed -ri "s/^(\s*)(# accessToken: \"platform_access_token\"$)/\1 accessToken: \"${platform_access_token}\"/" $dle_config_path/server.yml
126-
sed -ri "s/^(\s*)(# enablePersonalTokens: true$)/\1 enablePersonalTokens: true/" $dle_config_path/server.yml
127-
sed -ri "s/:13/:${source_postgres_version}/g" $dle_config_path/server.yml
131+
yq e -i '
132+
.platform.url = "https://postgres.ai/api/general" |
133+
.platform.accessToken = "${platform_access_token}" |
134+
.platform.enablePersonalTokens = true |
135+
' $dle_config_path/server.yml
128136

129137
case "${source_type}" in
130138

131139
postgres)
132140
# Mount directory to store dump files.
133141
extra_mount="--volume /var/lib/dblab/dblab_pool_00/dump:/var/lib/dblab/dblab_pool/dump"
134142

135-
sed -ri "s/^(\s*)(host: 34.56.78.90$)/\1host: ${source_postgres_host}/" $dle_config_path/server.yml
136-
sed -ri "s/^(\s*)(port: 5432$)/\1port: ${source_postgres_port}/" $dle_config_path/server.yml
137-
sed -ri "s/^(\s*)( username: postgres$)/\1 username: ${source_postgres_username}/" $dle_config_path/server.yml
138-
sed -ri "s/^(\s*)(password:.*$)/\1password: ${source_postgres_password}/" $dle_config_path/server.yml
143+
yq e -i '
144+
.retrieval.spec.logicalDump.options.source.connection.host = ${source_postgres_host}" |
145+
.retrieval.spec.logicalDump.options.source.connection.port = ${source_postgres_port}" |
146+
.retrieval.spec.logicalDump.options.source.connection.username = ${source_postgres_username}" |
147+
.retrieval.spec.logicalDump.options.source.connection.password = ${source_postgres_password}" |
148+
.retrieval.spec.logicalDump.options.parallelJobs = 1"
149+
' $dle_config_path/server.yml
150+
139151
# restore pg_dump via pipe - without saving it on the disk
140-
sed -ri "s/^(\s*)(parallelJobs:.*$)/\1parallelJobs: 1/" $dle_config_path/server.yml
141-
sed -ri "s/^(\s*)(# immediateRestore:.*$)/\1immediateRestore: /" $dle_config_path/server.yml
142-
sed -ri "s/^(\s*)(# enabled: true.*$)/\1 enabled: true /" $dle_config_path/server.yml
143-
sed -ri "s/^(\s*)(# forceInit: false.*$)/\1 forceInit: true /" $dle_config_path/server.yml
144-
sed -ri "s/^(\s*)( # configs:$)/\1 configs: /" $dle_config_path/server.yml
145-
sed -ri "s/^(\s*)( # shared_preload_libraries: .*$)/\1 shared_preload_libraries: '${postgres_config_shared_preload_libraries}'/" $dle_config_path/server.yml
146-
sed -ri "s/^(\s*)( shared_preload_libraries:.*$)/\1 shared_preload_libraries: '${postgres_config_shared_preload_libraries}'/" $dle_config_path/server.yml
147-
sed -ri "s/^(\s*)(- logicalRestore.*$)/\1#- logicalRestore /" $dle_config_path/server.yml
152+
yq e -i '
153+
.databaseContainer.dockerImage="postgresai/extended-postgres:${source_postgres_version}" |
154+
.retrieval.spec.logicalDump.options.immediateRestore.enabled=true |
155+
.retrieval.spec.logicalDump.options.immediateRestore.forceInit=true |
156+
.retrieval.spec.logicalDump.options.immediateRestore.configs alias = .databaseConfig |
157+
del(.retrieval.jobs[] | select(. == "logicalRestore")) |
158+
.databaseConfig.configs.shared_preload_libraries = ${postgres_config_shared_preload_libraries}
159+
' $dle_config_path/server.yml
148160
;;
149161

150162
s3)
@@ -154,10 +166,16 @@ case "${source_type}" in
154166

155167
extra_mount="--volume ${source_pgdump_s3_mount_point}:${source_pgdump_s3_mount_point}"
156168

157-
sed -ri "s/^(\s*)(- logicalDump.*$)/\1#- logicalDump /" $dle_config_path/server.yml
158-
sed -ri "s|^(\s*)( dumpLocation:.*$)|\1 dumpLocation: ${source_pgdump_s3_mount_point}/${source_pgdump_path_on_s3_bucket}|" $dle_config_path/server.yml
159-
sed -ri '/is always single-threaded./{n;s/.*/ parallelJobs: '${postgres_dump_parallel_jobs}'/}' $dle_config_path/server.yml
160-
sed -ri '/jobs to restore faster./{n;s/.*/ parallelJobs: '$(getconf _NPROCESSORS_ONLN)'/}' $dle_config_path/server.yml
169+
yq e -i '
170+
del(.retrieval.jobs[] | select(. == "logicalDump")) |
171+
.retrieval.spec.logicalRestore.options.dumpLocation="${source_pgdump_s3_mount_point}/${source_pgdump_path_on_s3_bucket}"
172+
' $dle_config_path/server.yml
173+
174+
nProcessors = $(getconf _NPROCESSORS_ONLN)
175+
yq e -i '
176+
.retrieval.spec.logicalDump.options.parallelJobs=${postgres_dump_parallel_jobs} |
177+
.retrieval.spec.logicalRestore.options.parallelJobs=$nProcessors
178+
' $dle_config_path/server.yml
161179
;;
162180

163181
esac

0 commit comments

Comments
 (0)