Skip to content
Open
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: 2 additions & 0 deletions roles/learningcircles-app/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
login_host: "127.0.0.1"
login_user: "{{PG_ADMIN_USER}}"
login_password: "{{PG_ADMIN_PASSWORD}}"
environment:
PGOPTIONS: "-c password_encryption=scram-sha-256"

- name: create postgres db
postgresql_db:
Expand Down
6 changes: 3 additions & 3 deletions roles/postgres/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
- name: start postgres docker image
docker_container:
name: p2pu-postgres
image: postgres:11
image: "postgres:{{VERSION}}"
state: started
pull: yes
restart: yes
restart_policy: always
ports:
- 127.0.0.1:5432:5432
volumes:
- "/var/p2pu/volumes/postgres-11/data:/var/lib/postgresql/data"
- "/var/p2pu/volumes/postgres-{{VERSION}}/data:/var/lib/postgresql/data"
env:
POSTGRES_USER: "{{ PG_ADMIN_USER }}"
POSTGRES_PASSWORD: "{{ PG_ADMIN_PASSWORD }}"

- name: wait for postgres startup
shell: docker run --rm --link p2pu-postgres:postgres postgres:11 pg_isready -h postgres
shell: "docker run --rm --link p2pu-postgres:postgres postgres:{{VERSION}} pg_isready -h postgres"
register: result
until: result.stdout.find("accepting connections") != -1
retries: 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,34 @@
- name: start new postgres docker image
docker_container:
name: new-postgres
image: postgres:11
image: "postgres:{{ NEW_VERSION }}"
state: started
pull: yes
restart: yes
restart_policy: always
volumes:
- "/var/p2pu/volumes/postgres-11/data:/var/lib/postgresql/data"
- "/var/p2pu/volumes/postgres-{{ NEW_VERSION }}/data:/var/lib/postgresql/data"
env:
POSTGRES_USER: "{{ PG_ADMIN_USER }}"
POSTGRES_PASSWORD: "{{ PG_ADMIN_PASSWORD }}"

# What about waiting for the db to be ready?
# docker exec learning-circles-db-11 pg_isready
# /var/run/postgresql:5432 - accepting connections
- name: wait for postgres startup
shell: "docker run --rm --link new-postgres:postgres postgres:{{ NEW_VERSION }} pg_isready -h postgres"
register: result
until: result.stdout.find("accepting connections") != -1
retries: 10
delay: 10

- name: load database dump
shell: docker exec -i new-postgres psql -U "{{ PG_ADMIN_USER }}" < /root/db-migrate.dump

- name: set postgres password again to ensure it uses the default encryption
shell: docker exec -i new-postgres psql -U "{{ PG_ADMIN_USER }}" -c "ALTER ROLE postgres WITH LOGIN PASSWORD '{{PG_ADMIN_PASSWORD}}'"

- name: Remove postgres container used to migrate
docker_container:
name: new-postgres
image: postgres:11
image: "postgres:{{ NEW_VERSION }}"
state: absent
keep_volumes: yes

Expand Down