Skip to content

Commit b8f2b22

Browse files
committed
feat: ansible run unit and migration tests passing!
1 parent e83886d commit b8f2b22

File tree

4 files changed

+67
-21
lines changed

4 files changed

+67
-21
lines changed

ansible/tasks/stage2/playbook.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@
1515

1616
- set_fact:
1717
parallel_jobs: 16
18-
18+
19+
- name: stat unit test file copy
20+
copy:
21+
src: /tmp/unit-tests/unit-test-01.sql
22+
dest: /home/postgres/unit-test-01.sql
23+
# state: present
24+
owner: postgres
25+
group: postgres
26+
mode: '0644'
27+
1928
- name: locale-gen
2029
command: sudo locale-gen en_US.UTF-8
2130

ansible/tasks/stage2/stage2-setup-postgres.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
shell: |
44
sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres#psql_15/bin"
55
6-
- name: Install glibcLocales from nix binary cache
6+
- name: Install pg_prove from nix binary cache
77
become: yes
88
shell: |
9-
sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install nixpkgs#glibcLocales"
9+
sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/sam/2-stage-ami-nix#pg_prove"
1010
11+
#TODO switch pg_prove sourcing to develop branch once PR is merged
1112

1213
# - name: Generate en_US.UTF-8 locale
1314
# command: sudo localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8

ansible/tasks/stage2/test-image.yml

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
- name: install pg_prove
2-
apt:
3-
pkg:
4-
- libtap-parser-sourcehandler-pgtap-perl
5-
61
- name: Temporarily disable PG Sodium references in config
72
become: yes
83
become_user: postgres
@@ -22,17 +17,58 @@
2217
LC_CTYPE: en_US.UTF-8
2318
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
2419

20+
21+
- name: check contents of unit test file
22+
become: yes
23+
become_user: postgres
24+
shell: cat /home/postgres/unit-test-01.sql && ls -l /home/postgres/unit-test-01.sql
25+
26+
- name: verify postgres server is running
27+
become: yes
28+
become_user: postgres
29+
shell: psql -U postgres -h localhost -c "SELECT version();"
30+
register: pg_isready
31+
failed_when: pg_isready.rc != 0
32+
args:
33+
executable: /bin/bash
34+
environment:
35+
LANG: en_US.UTF-8
36+
LANGUAGE: en_US.UTF-8
37+
LC_ALL: en_US.UTF-8
38+
LC_CTYPE: en_US.UTF-8
39+
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
40+
PATH: /home/postgres/.nix-profile/bin:$PATH
41+
2542
- name: Run Unit tests (with filename unit-test-*) on Postgres Database
26-
shell: /usr/bin/pg_prove -U postgres -h localhost -d postgres -v /tmp/unit-tests/unit-test-01.sql
43+
become: yes
44+
become_user: postgres
45+
shell: source /home/postgres/.bashrc && /home/postgres/.nix-profile/bin/pg_prove -U postgres -h localhost -d postgres -f /home/postgres/unit-test-01.sql
2746
register: retval
2847
failed_when: retval.rc != 0
48+
args:
49+
executable: /bin/bash
50+
environment:
51+
LANG: en_US.UTF-8
52+
LANGUAGE: en_US.UTF-8
53+
LC_ALL: en_US.UTF-8
54+
LC_CTYPE: en_US.UTF-8
55+
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
56+
PATH: /home/postgres/.nix-profile/bin:$PATH
2957

3058
- name: Run migrations tests
31-
shell: /usr/bin/pg_prove -U supabase_admin -h localhost -d postgres -v tests/test.sql
59+
shell: /home/postgres/.nix-profile/bin/pg_prove -U supabase_admin -h localhost -d postgres -v tests/test.sql
3260
register: retval
3361
failed_when: retval.rc != 0
3462
args:
63+
executable: /bin/bash
3564
chdir: /tmp/migrations
65+
environment:
66+
LANG: en_US.UTF-8
67+
LANGUAGE: en_US.UTF-8
68+
LC_ALL: en_US.UTF-8
69+
LC_CTYPE: en_US.UTF-8
70+
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
71+
PATH: /home/postgres/.nix-profile/bin:$PATH
3672

3773
- name: Re-enable PG Sodium references in config
3874
become: yes
@@ -55,12 +91,11 @@
5591
LC_CTYPE: en_US.UTF-8
5692
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
5793

58-
- name: remove pg_prove
59-
apt:
60-
pkg:
61-
- libtap-parser-sourcehandler-pgtap-perl
62-
state: absent
63-
autoremove: yes
94+
# - name: remove pg_prove
95+
- name: Remove pg_prove
96+
become: yes
97+
shell: |
98+
sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile remove pg_prove"
6499
65100
- name: Stop Postgres Database
66101
become: yes

stage2-nix-psql.pkr.hcl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ build {
7070
source = "migrations"
7171
destination = "/tmp"
7272
}
73-
73+
74+
provisioner "file" {
75+
source = "ebssurrogate/files/unit-tests"
76+
destination = "/tmp/unit-tests"
77+
}
78+
7479
provisioner "shell" {
7580
script = "scripts/nix-provision.sh"
7681
}
7782

78-
provisioner "file" {
79-
source = "ebssurrogate/files/unit-tests"
80-
destination = "/tmp"
81-
}
8283
}

0 commit comments

Comments
 (0)