Skip to content

Commit e83886d

Browse files
committed
WIP: this build is working up to running unit tests on image
with pg_prove
1 parent 39f232b commit e83886d

File tree

7 files changed

+135
-22
lines changed

7 files changed

+135
-22
lines changed

ansible/tasks/setup-postgres.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,31 @@
5858
- 'generated-optimizations.conf'
5959
- 'custom-overrides.conf'
6060

61+
- name: locale-gen
62+
command: sudo locale-gen en_US.UTF-8
63+
64+
- name: Add LOCALE_ARCHIVE to .bashrc
65+
lineinfile:
66+
dest: "/home/postgres/.bashrc"
67+
line: 'export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive'
68+
create: yes
69+
become: yes
70+
71+
72+
- name: Add LANG items to .bashrc
73+
lineinfile:
74+
dest: "/home/postgres/.bashrc"
75+
line: "{{ item }}"
76+
77+
loop:
78+
- 'export LANG="en_US.UTF-8"'
79+
- 'export LANGUAGE="en_US.UTF-8"'
80+
- 'export LC_ALL="en_US.UTF-8"'
81+
- 'export LANG="en_US.UTF-8"'
82+
- 'export LC_CTYPE="en_US.UTF-8"'
83+
become: yes
84+
85+
6186
# Move Postgres configuration files into /etc/postgresql
6287
# Add postgresql.conf
6388
- name: import postgresql.conf

ansible/tasks/stage2/playbook.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@
1515

1616
- set_fact:
1717
parallel_jobs: 16
18+
19+
- name: locale-gen
20+
command: sudo locale-gen en_US.UTF-8
21+
22+
# - name: Ensure en_US.UTF-8 locale is enabled
23+
# shell: |
24+
# echo "LC_ALL=en_US.UTF-8" >> /etc/environment
25+
# echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
26+
# echo "LANG=en_US.UTF-8" > /etc/locale.conf
27+
# locale-gen en_US.UTF-8
28+
# become: yes
29+
30+
- name: check locales
31+
command: locale -a
32+
register: locales
1833

1934
- name: Install Postgres from nix binary cache
2035
import_tasks: stage2-setup-postgres.yml

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

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,34 @@
88
shell: |
99
sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install nixpkgs#glibcLocales"
1010
11+
12+
# - name: Generate en_US.UTF-8 locale
13+
# command: sudo localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
14+
15+
16+
# - name: Add LOCALE_ARCHIVE to .bashrc
17+
# ansible.builtin.lineinfile:
18+
# dest: "/home/postgres/.bashrc"
19+
# line: 'export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive'
20+
# create: yes
21+
# become: yes
22+
# become_user: postgres
23+
24+
# - name: Add LANG items to .bashrc
25+
# ansible.builtin.lineinfile:
26+
# dest: "/home/postgres/.bashrc"
27+
# line: "{{ item }}"
28+
29+
# loop:
30+
# - 'export LANG="en_US.UTF-8"'
31+
# - 'export LANGUAGE="en_US.UTF-8"'
32+
# - 'export LC_ALL="en_US.UTF-8"'
33+
# - 'export LANG="en_US.UTF-8"'
34+
# - 'export LC_CTYPE="en_US.UTF-8"'
35+
# become: yes
36+
# become_user: postgres
37+
38+
1139
#TODO include ls $(nix profile list | grep glibc-locales | tail -n 1 | cut -d ':' -f 2 | sed 's/^[ \t]*//')/lib/locale-archive
1240

1341
- name: Ensure /usr/lib/postgresql/bin directory exists
@@ -135,20 +163,26 @@
135163
owner: postgres
136164
group: postgres
137165

138-
- name: Ensure en_US.UTF-8 locale is enabled
139-
shell: |
140-
if ! grep -q "^en_US.UTF-8" /etc/locale.gen ; then
141-
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
142-
locale-gen
143-
fi
144-
become: yes
166+
# - name: Set LANG environment variable
167+
# environment:
168+
# LANG: en_US.UTF-8
169+
# #become: yes
170+
#source /home/postgres/.bashrc &&
145171

146172
- name: Initialize the database
147173
become: yes
148174
become_user: postgres
149-
shell: |
150-
export LOCALE_ARCHIVE=$(nix profile list | grep glibc-locales | tail -n 1 | cut -d ':' -f 2 | sed 's/^[ \t]*//')/lib/locale/locale-archive
151-
/usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data initdb -o "--allow-group-access --locale=en_US.UTF-8"
175+
shell: source /home/postgres/.bashrc && /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data initdb -o "--allow-group-access"
176+
args:
177+
executable: /bin/bash
178+
environment:
179+
LANG: en_US.UTF-8
180+
LANGUAGE: en_US.UTF-8
181+
LC_ALL: en_US.UTF-8
182+
LC_CTYPE: en_US.UTF-8
183+
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
184+
# LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
185+
# LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
152186
vars:
153187
ansible_command_timeout: 60
154188
# # Circumvents the following error:
@@ -168,8 +202,14 @@
168202
become: yes
169203
become_user: postgres
170204
shell: |
171-
export LOCALE_ARCHIVE=$(nix profile list | grep glibc-locales | tail -n 1 | cut -d ':' -f 2 | sed 's/^[ \t]*//')/lib/locale/locale-archive
205+
source /home/postgres/.bashrc
172206
/usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data start
207+
environment:
208+
LANG: en_US.UTF-8
209+
LANGUAGE: en_US.UTF-8
210+
LC_ALL: en_US.UTF-8
211+
LC_CTYPE: en_US.UTF-8
212+
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
173213

174214
- name: Execute init SQL files
175215
become: yes
@@ -188,9 +228,16 @@
188228
become: yes
189229
become_user: postgres
190230
shell: |
191-
export LOCALE_ARCHIVE=$(nix profile list | grep glibc-locales | tail -n 1 | cut -d ':' -f 2 | sed 's/^[ \t]*//')/lib/locale/locale-archive
231+
source /home/postgres/.bashrc && \
192232
/usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data restart -o "-c shared_preload_libraries='pg_tle'"
193-
233+
args:
234+
executable: /bin/bash
235+
environment:
236+
LANG: en_US.UTF-8
237+
LANGUAGE: en_US.UTF-8
238+
LC_ALL: en_US.UTF-8
239+
LC_CTYPE: en_US.UTF-8
240+
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
194241

195242
- name: Run migrations
196243
import_tasks: setup-migrations.yml
@@ -209,3 +256,10 @@
209256
systemd:
210257
state: stopped
211258
name: postgresql
259+
260+
261+
- name: Stop Postgres Database without systemd
262+
become: yes
263+
become_user: postgres
264+
shell:
265+
cmd: /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data stop

ansible/tasks/stage2/test-image.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@
1212
- name: Start Postgres Database to load all extensions.
1313
become: yes
1414
become_user: postgres
15-
shell: |
16-
export LOCALE_ARCHIVE=$(nix profile list | grep glibc-locales | tail -n 1 | cut -d ':' -f 2 | sed 's/^[ \t]*//')/lib/locale/locale-archive
17-
cmd: /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data start "-o -c config_file=/etc/postgresql/postgresql.conf"
15+
shell: source /home/postgres/.bashrc && /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data start "-o -c config_file=/etc/postgresql/postgresql.conf"
16+
args:
17+
executable: /bin/bash
18+
environment:
19+
LANG: en_US.UTF-8
20+
LANGUAGE: en_US.UTF-8
21+
LC_ALL: en_US.UTF-8
22+
LC_CTYPE: en_US.UTF-8
23+
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
1824

1925
- name: Run Unit tests (with filename unit-test-*) on Postgres Database
20-
shell: /usr/bin/pg_prove -U postgres -h localhost -d postgres -v /tmp/unit-tests/unit-test-*.sql
26+
shell: /usr/bin/pg_prove -U postgres -h localhost -d postgres -v /tmp/unit-tests/unit-test-01.sql
2127
register: retval
2228
failed_when: retval.rc != 0
2329

@@ -38,8 +44,16 @@
3844
become: yes
3945
become_user: postgres
4046
shell: |
41-
export LOCALE_ARCHIVE=$(nix profile list | grep glibc-locales | tail -n 1 | cut -d ':' -f 2 | sed 's/^[ \t]*//')/lib/locale/locale-archive
47+
source /home/postgres/.bashrc && \
4248
/usr/lib/postgresql/bin/psql --no-password --no-psqlrc -d postgres -h localhost -U supabase_admin -c 'SELECT pg_stat_statements_reset(); SELECT pg_stat_reset();'
49+
args:
50+
executable: /bin/bash
51+
environment:
52+
LANG: en_US.UTF-8
53+
LANGUAGE: en_US.UTF-8
54+
LC_ALL: en_US.UTF-8
55+
LC_CTYPE: en_US.UTF-8
56+
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
4357

4458
- name: remove pg_prove
4559
apt:

ebssurrogate/scripts/surrogate-bootstrap.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ EOF
214214
# Run Ansible playbook
215215
#export ANSIBLE_LOG_PATH=/tmp/ansible.log && export ANSIBLE_DEBUG=True && export ANSIBLE_REMOTE_TEMP=/mnt/tmp
216216
export ANSIBLE_LOG_PATH=/tmp/ansible.log && export ANSIBLE_REMOTE_TEMP=/mnt/tmp
217-
ansible-playbook -c chroot -i '/mnt,' /tmp/ansible-playbook/ansible/playbook.yml $ARGS
217+
ansible-playbook -c chroot -i '/mnt,' /tmp/ansible-playbook/ansible/playbook.yml -vvv $ARGS
218218
}
219219

220220
function update_systemd_services {

scripts/nix-provision.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ EOF
3333
# Run Ansible playbook
3434
#export ANSIBLE_LOG_PATH=/tmp/ansible.log && export ANSIBLE_DEBUG=True && export ANSIBLE_REMOTE_TEMP=/tmp
3535
export ANSIBLE_LOG_PATH=/tmp/ansible.log && export ANSIBLE_REMOTE_TEMP=/tmp
36-
ansible-playbook /tmp/ansible-playbook/stage2/playbook.yml $ARGS
36+
ansible-playbook /tmp/ansible-playbook/stage2/playbook.yml -vvv $ARGS
3737
}
3838

3939

stage2-nix-psql.pkr.hcl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,13 @@ build {
7070
source = "migrations"
7171
destination = "/tmp"
7272
}
73-
74-
provisioner "shell" {
73+
74+
provisioner "shell" {
7575
script = "scripts/nix-provision.sh"
7676
}
77+
78+
provisioner "file" {
79+
source = "ebssurrogate/files/unit-tests"
80+
destination = "/tmp"
81+
}
7782
}

0 commit comments

Comments
 (0)