Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Use PostgreSQL 16 and fix database issues in local/sandboxes #513

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.DO_SPACES_DEV_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.DO_SPACES_DEV_ACCESS_KEY }}
run: |
aws s3 cp --quiet --endpoint-url=${{ secrets.DO_SPACES_DEV_ENDPOINT }} s3://wagtail/ietfwww.dump ietfwww.dump
aws s3 cp --quiet --endpoint-url=${{ secrets.DO_SPACES_DEV_ENDPOINT }} s3://wagtail/ietfwww.dump ./docker/database/ietfwww.dump
aws s3 cp --quiet --endpoint-url=${{ secrets.DO_SPACES_DEV_ENDPOINT }} s3://wagtail/media.tgz media.tgz

- name: Deploy to containers
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ So the only requirement to run it locally is a recent version of Docker with doc

##### How to run (with a database dump)

1. Obtain a recent database dump with name like `ietfa.*.gz` and place in `docker/database/` directory. Otherwise, it will start with a fresh database.
1. Obtain a recent database dump with name like `ietf*.dump` and place in `docker/database/` directory. Otherwise, it will start with a fresh database.
2. Obtain and unarchive media files into `media/` folder.
3. Run `docker compose up`. It will build and start the frontend builder (`yarn run start`) and the backend (`python manage.py runserver` analog), along with a Postgresql database. The first run will take a while because the database dump needs to be restored.
4. After the frontend compilation finishes, the website should become available at http://localhost:8001
Expand Down
6 changes: 4 additions & 2 deletions dev/deploy-to-container/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ async function main () {
src: [
'docker/db.Dockerfile',
'docker/scripts/db-import.sh',
'ietfwww.dump'
'docker/database/ietfwww.dump'
]
}, {
dockerfile: 'docker/db.Dockerfile',
t: 'ws-db:latest'
t: 'ws-db:latest',
rm: true,
forcerm: true
})
await new Promise((resolve, reject) => {
dock.modem.followProgress(dbImageBuildStream, (err, res) => err ? reject(err) : resolve(res))
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ services:

database:
restart: on-failure
image: postgres:14.6
image: postgres:16
volumes:
- "./docker/database:/docker-entrypoint-initdb.d/"
environment:
Expand Down
23 changes: 7 additions & 16 deletions docker/database/02_convert_native_dump_to_sql_and_restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,20 @@
cd /docker-entrypoint-initdb.d

set +e
FILE=$(ls -1 ietfa.*.gz | head)
FILE=$(ls -1 *.dump | head)

set -e

restore_dump() {
# use docker_process_sql function from docker-entrypoint.sh in the Postgres container
# pg_restore -xO means restore no owner, no permissions
pg_restore -xO -f - | sed -e '/CREATE SCHEMA public/d' | docker_process_sql
# use docker_process_sql function from docker-entrypoint.sh in the Postgres container
# pg_restore -xO means restore no owner, no permissions
cat "$1" | pg_restore -xO -f - | sed -e '/CREATE SCHEMA public/d' | docker_process_sql
}

if [ -s "${FILE}" ]; then
echo "Found ${FILE}, converting..."
case $FILE in
*.gz)
echo "Restoring the gzipped archive..."
gzip -d -c $FILE | restore_dump
;;
*)
echo "Restoring the archive..."
cat $FILE | restore_dump
;;
esac
echo "Restoring the archive..."
restore_dump "$FILE"
else
echo "No dump, starting fresh."
echo "No dump, starting fresh."
fi

6 changes: 3 additions & 3 deletions docker/db.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# =====================
# --- Builder Stage ---
# =====================
FROM postgres:14.6 AS builder
FROM postgres:16 AS builder

ENV POSTGRES_PASSWORD=password
ENV POSTGRES_USER=postgres
Expand All @@ -10,15 +10,15 @@ ENV POSTGRES_HOST_AUTH_METHOD=trust
ENV PGDATA=/data

COPY docker/scripts/db-import.sh /docker-entrypoint-initdb.d/
COPY ietfa.torchbox.latest.gz /
COPY docker/database/ietfwww.dump /

RUN ["sed", "-i", "s/exec \"$@\"/echo \"skipping...\"/", "/usr/local/bin/docker-entrypoint.sh"]
RUN ["/usr/local/bin/docker-entrypoint.sh", "postgres"]

# ===================
# --- Final Image ---
# ===================
FROM postgres:14.6
FROM postgres:16
LABEL maintainer="IETF Tools Team <tools-discuss@ietf.org>"

COPY --from=builder /data $PGDATA
Expand Down
Loading