Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
1c061ebbee | |||
b9458ced17 | |||
31fdceb34f | |||
677b1d980b |
21
Dockerfile
21
Dockerfile
@@ -1,18 +1,16 @@
|
||||
FROM ubuntu:noble AS build18
|
||||
RUN apt update && apt upgrade -y && apt install -y wget curl tar build-essential libreadline-dev zlib1g-dev flex bison libicu-dev pkg-config
|
||||
RUN wget https://ftp.postgresql.org/pub/source/v18.0/postgresql-18.0.tar.gz -O pg18.tar.gz
|
||||
RUN tar -xf pg18.tar.gz
|
||||
RUN cd postgresql* && ./configure --prefix=/postgres/18 && make world-bin && make install-world-bin
|
||||
|
||||
FROM ubuntu:noble AS build17
|
||||
RUN apt update && apt upgrade -y && apt install -y wget curl tar build-essential libreadline-dev zlib1g-dev flex bison libicu-dev pkg-config
|
||||
|
||||
RUN wget https://ftp.postgresql.org/pub/source/v17.2/postgresql-17.2.tar.gz -O pg17.tar.gz
|
||||
RUN wget https://ftp.postgresql.org/pub/source/v17.6/postgresql-17.6.tar.gz -O pg17.tar.gz
|
||||
RUN tar -xf pg17.tar.gz
|
||||
RUN cd postgresql* && ./configure --prefix=/postgres/17 && make world-bin && make install
|
||||
RUN cd postgresql* && ./configure --prefix=/postgres/17 && make world-bin && make install-world-bin
|
||||
|
||||
|
||||
FROM ubuntu:noble AS build16
|
||||
RUN apt update && apt upgrade -y && apt install -y wget curl tar build-essential libreadline-dev zlib1g-dev flex bison libicu-dev pkg-config
|
||||
|
||||
RUN wget https://ftp.postgresql.org/pub/source/v16.6/postgresql-16.6.tar.gz -O pg16.tar.gz
|
||||
RUN tar -xf pg16.tar.gz
|
||||
RUN cd postgresql* && ./configure --prefix=/postgres/16 && make world-bin && make install
|
||||
|
||||
FROM ubuntu:noble
|
||||
RUN apt update && apt install -y \
|
||||
libicu74 \
|
||||
@@ -27,8 +25,9 @@ ENV LANG=en_US.utf8
|
||||
|
||||
ENV POSTGRES_USER=postgres
|
||||
|
||||
COPY --from=build18 /postgres/18 /postgres/18
|
||||
COPY --from=build17 /postgres/17 /postgres/17
|
||||
COPY --from=build16 /postgres/16 /postgres/16
|
||||
|
||||
|
||||
COPY migrate.sh /migrate.sh
|
||||
RUN chmod +x migrate.sh
|
||||
|
21
README.md
21
README.md
@@ -1,13 +1,22 @@
|
||||
# Docker migration helper
|
||||
This repo contains a `Dockerfile` that can helps you in performing your Docker images migration.
|
||||
|
||||
## Test
|
||||
Create an outdated database
|
||||
This repository will:
|
||||
|
||||
* Perform a temporary copy the old database
|
||||
* Initialize a new empty database with the default user / password couple provided as environment variables (`POSTGRES_USER` and `POSTGRES_PASSWORD`)
|
||||
* Run `pg_upgrade` from the copy of the old database to the new database
|
||||
* Replace the old database with the new one
|
||||
* Move the copy of the old database as sub-directory of the new database (in `old_db` directory, to allow rollback in case of failure)
|
||||
|
||||
## Perform the migration
|
||||
Create an outdated database:
|
||||
```bash
|
||||
mkdir test-db
|
||||
docker run --rm --name testdb -u 1000 -e POSTGRES_PASSWORD=password -v $(pwd)/test-db:/var/lib/postgresql/data -it postgres:16
|
||||
docker run --rm --name testdb --env PGDATA=/var/lib/postgresql/data -u 1000 -e POSTGRES_PASSWORD=password -v $(pwd)/test-db:/var/lib/postgresql/data -it postgres:17
|
||||
```
|
||||
|
||||
Perform the migration:
|
||||
Perform the migration (you need to replace `POSTGRES_USER` and `POSTGRES_PASSWORD` with the credentials of the root user of the database):
|
||||
```bash
|
||||
./build.sh && docker run -u 1000 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -v $(pwd)/test-db:/db --rm -it pierre42100/postgresmig:16to17
|
||||
```
|
||||
docker run -u 1000 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -v $(pwd)/test-db:/db --rm -it pierre42100/postgresmig:17to18
|
||||
```
|
||||
|
2
build.sh
2
build.sh
@@ -1,2 +1,2 @@
|
||||
#!/bin/bash
|
||||
docker build . -t pierre42100/postgresmig:16to17
|
||||
docker build . -t pierre42100/postgresmig:17to18
|
18
migrate.sh
18
migrate.sh
@@ -1,6 +1,9 @@
|
||||
#!/bin/bash
|
||||
echo Migrate PostgreSQL version
|
||||
|
||||
OLD_POSTGRES=/postgres/17
|
||||
NEW_POSTGRES=/postgres/18
|
||||
|
||||
DB_PATH=/db
|
||||
OLD_DB_PATH=/tmp/old_db
|
||||
NEW_DB_PATH=/tmp/new_db
|
||||
@@ -12,17 +15,26 @@ then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
# Run database on a COPY of the database
|
||||
# Run migration on a COPY of the database
|
||||
cp -r "$DB_PATH" "$OLD_DB_PATH"
|
||||
|
||||
# Initialize NEW database
|
||||
mkdir "$NEW_DB_PATH"
|
||||
/postgres/17/bin/initdb -D "$NEW_DB_PATH" --username "$POSTGRES_USER" --pwfile=<(printf "%s\n" "$POSTGRES_PASSWORD") || exit 1
|
||||
$NEW_POSTGRES/bin/initdb -D "$NEW_DB_PATH" --username "$POSTGRES_USER" --pwfile=<(printf "%s\n" "$POSTGRES_PASSWORD") || exit 1
|
||||
|
||||
# Enable / disable checksum on new database, depending on the configuration of the old one
|
||||
if $OLD_POSTGRES/bin/pg_checksums -c "$OLD_DB_PATH";
|
||||
then
|
||||
echo Enable checksums on new database
|
||||
$NEW_POSTGRES/bin/pg_checksums -e "$NEW_DB_PATH"
|
||||
else
|
||||
echo Disable checksums on new database
|
||||
$NEW_POSTGRES/bin/pg_checksums -d "$NEW_DB_PATH"
|
||||
fi
|
||||
|
||||
# Perform migration
|
||||
cd /tmp
|
||||
/postgres/17/bin/pg_upgrade -b /postgres/16/bin/ -d "$OLD_DB_PATH" -D "$NEW_DB_PATH" -U "$POSTGRES_USER" || exit 2
|
||||
$NEW_POSTGRES/bin/pg_upgrade -b $OLD_POSTGRES/bin/ -d "$OLD_DB_PATH" -D "$NEW_DB_PATH" -U "$POSTGRES_USER" || exit 2
|
||||
|
||||
# Configure database server
|
||||
echo Configure database server
|
||||
|
Reference in New Issue
Block a user