@@ -3,53 +3,69 @@ set -euxo pipefail
3
3
4
4
TAG=" ${TAG:- " master" } "
5
5
IMAGE2TEST=" registry.gitlab.com/postgres-ai/database-lab/dblab-server:${TAG} "
6
+ DLE_SERVER_NAME=" dblab_server_test"
6
7
7
8
# Environment variables for replacement rules
8
9
export SOURCE_HOST=" ${SOURCE_HOST:- 172.17.0.1} "
9
10
export SOURCE_PORT=" ${SOURCE_PORT:- 7432} "
10
11
export SOURCE_USERNAME=" ${SOURCE_USERNAME:- postgres} "
11
12
export SOURCE_PASSWORD=" ${SOURCE_PASSWORD:- secretpassword} "
12
13
export POSTGRES_VERSION=" ${POSTGRES_VERSION:- 13} "
14
+ export DLE_TEST_MOUNT_DIR=" /var/lib/test/dblab"
15
+ export DLE_TEST_POOL_NAME=" test_dblab_pool"
16
+ export DLE_SERVER_PORT=${DLE_SERVER_PORT:- 12345}
17
+ export DLE_PORT_POOL_FROM=${DLE_PORT_POOL_FROM:- 9000}
18
+ export DLE_PORT_POOL_TO=${DLE_PORT_POOL_TO:- 9100}
13
19
14
20
DIR=${0%/* }
15
21
16
22
if [[ " ${SOURCE_HOST} " = " 172.17.0.1" ]]; then
17
23
# ## Step 0. Create source database
18
- sudo rm -rf " $( pwd) " /postgresql/" ${POSTGRES_VERSION} " /test || true
24
+ TMP_DATA_DIR=" /tmp/dle_test/physical_basebackup"
25
+ cleanup_testdata_dir () {
26
+ sudo rm -rf " ${TMP_DATA_DIR} " /postgresql/" ${POSTGRES_VERSION} " /test || true
27
+ }
28
+
29
+ trap cleanup_testdata_dir EXIT
30
+
31
+ cleanup_testdata_dir
32
+ sudo docker rm postgres" ${POSTGRES_VERSION} " || true
33
+
19
34
sudo docker run \
20
35
--name postgres" ${POSTGRES_VERSION} " \
21
36
--label pgdb \
37
+ --label dblab_test \
22
38
--privileged \
23
39
--publish 172.17.0.1:" ${SOURCE_PORT} " :5432 \
24
40
--env PGDATA=/var/lib/postgresql/pgdata \
25
41
--env POSTGRES_USER=" ${SOURCE_USERNAME} " \
26
42
--env POSTGRES_PASSWORD=" ${SOURCE_PASSWORD} " \
27
43
--env POSTGRES_DB=test \
28
44
--env POSTGRES_HOST_AUTH_METHOD=md5 \
29
- --volume " $( pwd ) " /postgresql/" ${POSTGRES_VERSION} " /test:/var/lib/postgresql/pgdata \
45
+ --volume " ${TMP_DATA_DIR} " /postgresql/" ${POSTGRES_VERSION} " /test:/var/lib/postgresql/pgdata \
30
46
--detach \
31
47
postgres:" ${POSTGRES_VERSION} -alpine"
32
48
33
49
for i in {1..300}; do
34
- sudo docker exec -it postgres" ${POSTGRES_VERSION} " psql -d test -U postgres -c ' select' > /dev/null 2>&1 && break || echo " test database is not ready yet"
50
+ sudo docker exec postgres" ${POSTGRES_VERSION} " psql -d test -U postgres -c ' select' > /dev/null 2>&1 && break || echo " test database is not ready yet"
35
51
sleep 1
36
52
done
37
53
38
54
# add "host replication" to pg_hba.conf
39
- sudo docker exec -it postgres" ${POSTGRES_VERSION} " bash -c ' echo "host replication all 0.0.0.0/0 md5" >> $PGDATA/pg_hba.conf'
55
+ sudo docker exec postgres" ${POSTGRES_VERSION} " bash -c ' echo "host replication all 0.0.0.0/0 md5" >> $PGDATA/pg_hba.conf'
40
56
# reload conf
41
- sudo docker exec -it postgres" ${POSTGRES_VERSION} " psql -U postgres -c ' select pg_reload_conf()'
57
+ sudo docker exec postgres" ${POSTGRES_VERSION} " psql -U postgres -c ' select pg_reload_conf()'
42
58
43
59
# Generate data in the test database using pgbench
44
60
# 1,000,000 accounts, ~0.14 GiB of data.
45
- sudo docker exec -it postgres" ${POSTGRES_VERSION} " pgbench -U postgres -i -s 10 test
61
+ sudo docker exec postgres" ${POSTGRES_VERSION} " pgbench -U postgres -i -s 10 test
46
62
47
63
# Database info
48
- sudo docker exec -it postgres" ${POSTGRES_VERSION} " psql -U postgres -c " \l+ test"
64
+ sudo docker exec postgres" ${POSTGRES_VERSION} " psql -U postgres -c " \l+ test"
49
65
fi
50
66
51
67
# ## Step 1. Prepare a machine with disk, Docker, and ZFS
52
- source " ${DIR} /_prerequisites.ubuntu.sh"
68
+ # source "${DIR}/_prerequisites.ubuntu.sh"
53
69
source " ${DIR} /_zfs.file.sh"
54
70
55
71
@@ -69,6 +85,10 @@ yq eval -i '
69
85
.global.debug = true |
70
86
.global.telemetry.enabled = false |
71
87
.localUI.enabled = false |
88
+ .server.port = env(DLE_SERVER_PORT) |
89
+ .poolManager.mountDir = env(DLE_TEST_MOUNT_DIR) |
90
+ .provision.portPool.from = env(DLE_PORT_POOL_FROM) |
91
+ .provision.portPool.to = env(DLE_PORT_POOL_TO) |
72
92
.databaseContainer.dockerImage = "postgresai/extended-postgres:" + strenv(POSTGRES_VERSION) |
73
93
.retrieval.spec.physicalRestore.options.envs.PGUSER = strenv(SOURCE_USERNAME) |
74
94
.retrieval.spec.physicalRestore.options.envs.PGPASSWORD = strenv(SOURCE_PASSWORD) |
@@ -77,17 +97,19 @@ yq eval -i '
77
97
.retrieval.spec.physicalSnapshot.options.envs.PGUSER = strenv(SOURCE_USERNAME) |
78
98
.retrieval.spec.physicalSnapshot.options.envs.PGPASSWORD = strenv(SOURCE_PASSWORD) |
79
99
.retrieval.spec.physicalSnapshot.options.envs.PGHOST = strenv(SOURCE_HOST) |
80
- .retrieval.spec.physicalSnapshot.options.envs.PGPORT = env(SOURCE_PORT)
100
+ .retrieval.spec.physicalSnapshot.options.envs.PGPORT = env(SOURCE_PORT) |
101
+ .retrieval.spec.physicalRestore.options.customTool.command = "pg_basebackup -X stream -D " + strenv(DLE_TEST_MOUNT_DIR) + "/" + strenv(DLE_TEST_POOL_NAME) + "/data"
81
102
' " ${configDir} /server.yml"
82
103
83
104
# # Launch Database Lab server
84
105
sudo docker run \
85
- --name dblab_server \
106
+ --name ${DLE_SERVER_NAME} \
86
107
--label dblab_control \
108
+ --label dblab_test \
87
109
--privileged \
88
- --publish 2345:2345 \
110
+ --publish ${DLE_SERVER_PORT} : ${DLE_SERVER_PORT} \
89
111
--volume /var/run/docker.sock:/var/run/docker.sock \
90
- --volume /var/lib/dblab:/var/lib/dblab /:rshared \
112
+ --volume ${DLE_TEST_MOUNT_DIR} : ${DLE_TEST_MOUNT_DIR} /:rshared \
91
113
--volume " ${configDir} " :/home/dblab/configs:ro \
92
114
--volume " ${metaDir} " :/home/dblab/meta \
93
115
--volume /sys/kernel/debug:/sys/kernel/debug:rw \
@@ -98,11 +120,11 @@ sudo docker run \
98
120
" ${IMAGE2TEST} "
99
121
100
122
# Check the Database Lab Engine logs
101
- sudo docker logs dblab_server -f 2>&1 | awk ' {print "[CONTAINER dblab_server]: "$0}' &
123
+ sudo docker logs ${DLE_SERVER_NAME} -f 2>&1 | awk ' {print "[CONTAINER dblab_server]: "$0}' &
102
124
103
125
# ## Waiting for the Database Lab Engine initialization.
104
126
for i in {1..30}; do
105
- curl http://localhost:2345 > /dev/null 2>&1 && break || echo " dblab is not ready yet"
127
+ curl http://localhost:${DLE_SERVER_PORT} > /dev/null 2>&1 && break || echo " dblab is not ready yet"
106
128
sleep 10
107
129
done
108
130
@@ -118,7 +140,7 @@ dblab --version
118
140
# Initialize CLI configuration
119
141
dblab init \
120
142
--environment-id=test \
121
- --url=http://localhost:2345 \
143
+ --url=http://localhost:${DLE_SERVER_PORT} \
122
144
--token=secret_token \
123
145
--insecure
124
146
@@ -134,14 +156,14 @@ dblab clone create \
134
156
135
157
# Connect to a clone and check the available table
136
158
PGPASSWORD=secret_password psql \
137
- " host=localhost port=6000 user=dblab_user_1 dbname=test" -c ' \dt+'
159
+ " host=localhost port=${DLE_PORT_POOL_FROM} user=dblab_user_1 dbname=test" -c ' \dt+'
138
160
139
161
# Drop table
140
162
PGPASSWORD=secret_password psql \
141
- " host=localhost port=6000 user=dblab_user_1 dbname=test" -c ' drop table pgbench_accounts'
163
+ " host=localhost port=${DLE_PORT_POOL_FROM} user=dblab_user_1 dbname=test" -c ' drop table pgbench_accounts'
142
164
143
165
PGPASSWORD=secret_password psql \
144
- " host=localhost port=6000 user=dblab_user_1 dbname=test" -c ' \dt+'
166
+ " host=localhost port=${DLE_PORT_POOL_FROM} user=dblab_user_1 dbname=test" -c ' \dt+'
145
167
146
168
# # Reset clone
147
169
dblab clone reset testclone
@@ -151,11 +173,14 @@ dblab clone status testclone
151
173
152
174
# Check the database objects (everything should be the same as when we started)
153
175
PGPASSWORD=secret_password psql \
154
- " host=localhost port=6000 user=dblab_user_1 dbname=test" -c ' \dt+'
176
+ " host=localhost port=${DLE_PORT_POOL_FROM} user=dblab_user_1 dbname=test" -c ' \dt+'
155
177
156
178
# ## Step 4. Destroy clone
157
179
dblab clone destroy testclone
158
180
dblab clone list
159
181
182
+ # # Stop DLE.
183
+ sudo docker stop ${DLE_SERVER_NAME}
184
+
160
185
# ## Finish. clean up
161
186
source " ${DIR} /_cleanup.sh"
0 commit comments