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

fix: use docker compose v2 #4622

Merged
merged 4 commits into from May 7, 2024
Merged

fix: use docker compose v2 #4622

merged 4 commits into from May 7, 2024

Conversation

ticoombs
Copy link
Contributor

@ticoombs ticoombs commented Apr 13, 2024

With Ubuntu 22.04 and Debian 12 when using v1 commands this happens:
(Ref: https://askubuntu.com/questions/1508129/docker-compose-giving-containerconfig-errors-after-update-today)

This means your containers end up in a broken state. Updating all commands to be v2 compatible ensures they still work

Edit: Draft. Just realised there are more problems with it than I thought. (you can't > 15_to_16 for example)

@dessalines
Copy link
Member

What's the error its giving you with > 15_16 ?

@ticoombs
Copy link
Contributor Author

sudo docker compose exec -T postgres pg_dumpall -c -U lemmy > 15_16_dump.sql runs as two different users. :

  • sudo docker compose exec -T postgres pg_dumpall -c -U lemmy
    • root
  • > 15_16_dump.sql
    • Whatever the local user that is using sudo.

If you end up running the script as the regular user, which doesn't have write permissions on the local directory wherever we are piping to, you end up with a failure because you cannot write the output.

You'd get around this by calling the script via sudo scripts/postgres_15_to_16_upgrade.sh as then the "local" user inside the script is still root. But then all sudo commands inside the script are superfluous.

Example Script

#!/bin/bash
echo `id -u`
echo `sudo id -u`
> /bin/bash test.sh
1000
0

> sudo /bin/bash test.sh
0
0

tl;dr, running script via sudo works. running script (as regular user) so that each command inside the script elevates to sudo will fail to write the sql file

@Nothing4You
Copy link
Contributor

people usually use sudo tee to deal with these cases:

sudo docker compose exec -T postgres pg_dumpall -c -U lemmy | sudo tee 15_16_dump.sql > /dev/null

echo "Waiting..."
sleep 20s

echo "Exporting the Database to 15_16.dump.sql ..."
sudo docker-compose exec -T postgres pg_dumpall -c -U lemmy > 15_16_dump.sql
sudo docker compose exec -T postgres pg_dumpall -c -U lemmy > 15_16_dump.sql
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case use the sudo tee method above.

echo "Waiting..."
sleep 20s

echo "Importing the database...."
cat 15_16_dump.sql | sudo docker-compose exec -T postgres psql -U lemmy
cat 15_16_dump.sql | sudo docker compose exec -T postgres psql -U lemmy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might also need to be sudo cat then now.

@dessalines dessalines marked this pull request as ready for review April 30, 2024 10:30
@dessalines
Copy link
Member

I made the fixes above, so this is ready.

@ticoombs
Copy link
Contributor Author

ticoombs commented May 1, 2024

I'll test in the next day or so to confirm it works on lemmy-ansible deploys

@Nutomic Nutomic merged commit 522f974 into LemmyNet:main May 7, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants