Skip to content

Commit 70657e2

Browse files
authored
feature: wal-g v 3 (#1456)
* feature: wal-g v 3 * chore: install, symlink * chore: wal-g user and groups in stage 1 * chore: bump versions to test wal-g * chore: build wal-g in ci and copy to binary cache on success * chore: minor correction * chore: maintainer * chore: release wal-g 3
1 parent bf7327c commit 70657e2

File tree

6 files changed

+144
-69
lines changed

6 files changed

+144
-69
lines changed

Diff for: ansible/playbook.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
- name: Install WAL-G
4040
import_tasks: tasks/setup-wal-g.yml
41-
when: debpkg_mode or nixpkg_mode
41+
when: debpkg_mode or nixpkg_mode or stage2_nix
4242

4343
- name: Install Gotrue
4444
import_tasks: tasks/setup-gotrue.yml

Diff for: ansible/tasks/setup-wal-g.yml

+78-64
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,73 @@
11
# Downloading dependencies
2-
- name: wal-g dependencies
3-
become: yes
4-
apt:
5-
pkg:
6-
- libbrotli-dev
7-
- liblzo2-dev
8-
- libsodium-dev
9-
- cmake
2+
# - name: wal-g dependencies
3+
# become: yes
4+
# apt:
5+
# pkg:
6+
# - libbrotli-dev
7+
# - liblzo2-dev
8+
# - libsodium-dev
9+
# - cmake
1010

1111
# install go dependency for WAL-G
12-
- name: wal-g go dependency
13-
get_url:
14-
url: "https://golang.org/dl/go{{ golang_version }}.linux-{{ platform }}.tar.gz"
15-
dest: /tmp
16-
checksum: "{{ golang_version_checksum[platform] }}"
17-
timeout: 60
12+
# - name: wal-g go dependency
13+
# get_url:
14+
# url: "https://golang.org/dl/go{{ golang_version }}.linux-{{ platform }}.tar.gz"
15+
# dest: /tmp
16+
# checksum: "{{ golang_version_checksum[platform] }}"
17+
# timeout: 60
1818

19-
- name: unpack go archive
20-
unarchive:
21-
remote_src: yes
22-
src: "/tmp/go{{ golang_version }}.linux-{{ platform }}.tar.gz"
23-
dest: /usr/local
19+
# - name: unpack go archive
20+
# unarchive:
21+
# remote_src: yes
22+
# src: "/tmp/go{{ golang_version }}.linux-{{ platform }}.tar.gz"
23+
# dest: /usr/local
2424

25-
# Download WAL-G
26-
- name: wal-g - download latest version
27-
git:
28-
repo: https://github.com/wal-g/wal-g.git
29-
dest: /tmp/wal-g
30-
version: "v{{ wal_g_release }}"
31-
become: yes
25+
# # Download WAL-G
26+
# - name: wal-g - download latest version
27+
# git:
28+
# repo: https://github.com/wal-g/wal-g.git
29+
# dest: /tmp/wal-g
30+
# version: "v{{ wal_g_release }}"
31+
# become: yes
3232

33-
- name: wal-g - pg_clean
34-
make:
35-
chdir: /tmp/wal-g
36-
target: pg_clean
37-
params:
38-
GOBIN: "/usr/local/bin"
39-
PATH: "{{ ansible_env.PATH }}:/usr/local/go/bin"
40-
USE_LIBSODIUM: true
41-
become: yes
42-
ignore_errors: yes
33+
# - name: wal-g - pg_clean
34+
# make:
35+
# chdir: /tmp/wal-g
36+
# target: pg_clean
37+
# params:
38+
# GOBIN: "/usr/local/bin"
39+
# PATH: "{{ ansible_env.PATH }}:/usr/local/go/bin"
40+
# USE_LIBSODIUM: true
41+
# become: yes
42+
# ignore_errors: yes
4343

44-
- name: wal-g - deps
45-
make:
46-
chdir: /tmp/wal-g
47-
target: deps
48-
params:
49-
GOBIN: "/usr/local/bin"
50-
PATH: "{{ ansible_env.PATH }}:/usr/local/go/bin"
51-
USE_LIBSODIUM: true
52-
become: yes
53-
ignore_errors: yes
44+
# - name: wal-g - deps
45+
# make:
46+
# chdir: /tmp/wal-g
47+
# target: deps
48+
# params:
49+
# GOBIN: "/usr/local/bin"
50+
# PATH: "{{ ansible_env.PATH }}:/usr/local/go/bin"
51+
# USE_LIBSODIUM: true
52+
# become: yes
53+
# ignore_errors: yes
5454

55-
- name: wal-g - build and install
56-
community.general.make:
57-
chdir: /tmp/wal-g
58-
target: pg_install
59-
jobs: "{{ parallel_jobs | default(omit) }}"
60-
params:
61-
GOBIN: "/usr/local/bin"
62-
PATH: "{{ ansible_env.PATH }}:/usr/local/go/bin"
63-
USE_LIBSODIUM: true
64-
become: yes
55+
# - name: wal-g - build and install
56+
# community.general.make:
57+
# chdir: /tmp/wal-g
58+
# target: pg_install
59+
# jobs: "{{ parallel_jobs | default(omit) }}"
60+
# params:
61+
# GOBIN: "/usr/local/bin"
62+
# PATH: "{{ ansible_env.PATH }}:/usr/local/go/bin"
63+
# USE_LIBSODIUM: true
64+
# become: yes
6565

6666
- name: Create wal-g group
6767
group:
6868
name: wal-g
6969
state: present
70+
when: nixpkg_mode
7071

7172
- name: Create wal-g user
7273
user:
@@ -75,22 +76,38 @@
7576
comment: WAL-G user
7677
group: wal-g
7778
groups: wal-g, postgres
78-
79+
when: nixpkg_mode
7980
- name: Create a config directory owned by wal-g
8081
file:
8182
path: /etc/wal-g
8283
state: directory
8384
owner: wal-g
8485
group: wal-g
8586
mode: '0770'
87+
when: nixpkg_mode
8688

89+
- name: Install wal-g from nix binary cache
90+
become: yes
91+
shell: |
92+
sudo -u wal-g bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#wal-g"
93+
when: stage2_nix
94+
95+
- name: Create symlink for wal-g from Nix profile to /usr/local/bin
96+
ansible.builtin.file:
97+
src: /home/wal-g/.nix-profile/bin/wal-g
98+
dest: /usr/local/bin/wal-g
99+
state: link
100+
force: yes # This will replace existing file/symlink if it exists
101+
become: yes # Need sudo to write to /usr/local/bin
102+
when: stage2_nix
87103
- name: Create /etc/wal-g/config.json
88104
file:
89105
path: /etc/wal-g/config.json
90106
state: touch
91107
owner: wal-g
92108
group: wal-g
93109
mode: '0664'
110+
when: stage2_nix
94111

95112
- name: Move custom wal-g.conf file to /etc/postgresql-custom/wal-g.conf
96113
template:
@@ -99,6 +116,7 @@
99116
mode: 0664
100117
owner: postgres
101118
group: postgres
119+
when: stage2_nix
102120

103121
- name: Add script to be run for restore_command
104122
template:
@@ -107,24 +125,20 @@
107125
mode: 0500
108126
owner: postgres
109127
group: postgres
128+
when: stage2_nix
110129

111130
- name: Add helper script for wal_fetch.sh
112131
template:
113132
src: "files/walg_helper_scripts/wal_change_ownership.sh"
114133
dest: /root/wal_change_ownership.sh
115134
mode: 0700
116135
owner: root
136+
when: stage2_nix
117137

118138
- name: Include /etc/postgresql-custom/wal-g.conf in postgresql.conf
119139
become: yes
120140
replace:
121141
path: /etc/postgresql/postgresql.conf
122142
regexp: "#include = '/etc/postgresql-custom/wal-g.conf'"
123143
replace: "include = '/etc/postgresql-custom/wal-g.conf'"
124-
125-
# Clean up Go
126-
- name: Uninstall Go
127-
become: yes
128-
file:
129-
path: /usr/local/go
130-
state: absent
144+
when: stage2_nix

Diff for: ansible/vars.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ postgres_major:
88

99
# Full version strings for each major version
1010
postgres_release:
11-
postgresorioledb-17: "17.0.1.048-orioledb"
12-
postgres15: "15.8.1.055"
11+
postgresorioledb-17: "17.0.1.049-orioledb"
12+
postgres15: "15.8.1.056"
1313

1414
# Non Postgres Extensions
1515
pgbouncer_release: "1.19.0"
@@ -45,7 +45,6 @@ kong_deb_checksum: sha1:2086f6ccf8454fe64435252fea4d29d736d7ec61
4545
nginx_release: 1.22.0
4646
nginx_release_checksum: sha1:419efb77b80f165666e2ee406ad8ae9b845aba93
4747

48-
wal_g_release: "2.0.1"
4948

5049
postgres_exporter_release: "0.15.0"
5150
postgres_exporter_release_checksum:

Diff for: docker/nix/build_nix.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ nix build .#checks.$SYSTEM.psql_orioledb-17 -L --no-link
1313
nix build .#psql_15/bin -o psql_15
1414

1515
nix build .#psql_orioledb-17/bin -o psql_orioledb_17
16-
16+
nix build .#wal-g -o wal-g
1717
# Copy to S3
18+
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./wal-g
1819
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./psql_15
1920
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./psql_orioledb_17
2021
if [ "$SYSTEM" = "aarch64-linux" ]; then
@@ -26,4 +27,5 @@ if [ "$SYSTEM" = "aarch64-linux" ]; then
2627
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./postgresql_15_src
2728
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./postgresql_orioledb-17_debug-debug
2829
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./postgresql_orioledb-17_src
30+
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./wal-g
2931
fi

Diff for: flake.nix

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
sfcgal = pkgs.callPackage ./nix/ext/sfcgal/sfcgal.nix { };
8888
supabase-groonga = pkgs.callPackage ./nix/supabase-groonga.nix { };
8989
mecab-naist-jdic = pkgs.callPackage ./nix/ext/mecab-naist-jdic/default.nix { };
90+
wal-g = pkgs.callPackage ./nix/wal-g.nix { };
9091
# Our list of PostgreSQL extensions which come from upstream Nixpkgs.
9192
# These are maintained upstream and can easily be used here just by
9293
# listing their name. Anytime the version of nixpkgs is upgraded, these
@@ -405,6 +406,7 @@
405406
# PostgreSQL versions.
406407
psql_15 = postgresVersions.psql_15;
407408
psql_orioledb-17 = postgresVersions.psql_orioledb-17;
409+
wal-g = wal-g;
408410
sfcgal = sfcgal;
409411
pg_prove = pkgs.perlPackages.TAPParserSourceHandlerpgTAP;
410412
inherit postgresql_15 postgresql_orioledb-17;

Diff for: nix/wal-g.nix

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
lib,
3+
buildGoModule,
4+
fetchFromGitHub,
5+
brotli,
6+
libsodium,
7+
installShellFiles,
8+
}:
9+
10+
buildGoModule rec {
11+
pname = "wal-g";
12+
version = "3.0.5";
13+
14+
src = fetchFromGitHub {
15+
owner = "wal-g";
16+
repo = "wal-g";
17+
rev = "v${version}";
18+
sha256 = "sha256-wVr0L2ZXMuEo6tc2ajNzPinVQ8ZVzNOSoaHZ4oFsA+U=";
19+
};
20+
21+
vendorHash = "sha256-YDLAmRfDl9TgbabXj/1rxVQ052NZDg3IagXVTe5i9dw=";
22+
23+
nativeBuildInputs = [ installShellFiles ];
24+
25+
buildInputs = [
26+
brotli
27+
libsodium
28+
];
29+
30+
subPackages = [ "main/pg" ];
31+
32+
tags = [
33+
"brotli"
34+
"libsodium"
35+
];
36+
37+
ldflags = [
38+
"-s"
39+
"-w"
40+
"-X github.com/wal-g/wal-g/cmd/pg.walgVersion=${version}"
41+
"-X github.com/wal-g/wal-g/cmd/pg.gitRevision=${src.rev}"
42+
];
43+
44+
postInstall = ''
45+
mv $out/bin/pg $out/bin/wal-g
46+
installShellCompletion --cmd wal-g \
47+
--bash <($out/bin/wal-g completion bash) \
48+
--zsh <($out/bin/wal-g completion zsh)
49+
'';
50+
51+
meta = with lib; {
52+
homepage = "https://github.com/wal-g/wal-g";
53+
license = licenses.asl20;
54+
description = "Archival restoration tool for PostgreSQL";
55+
mainProgram = "wal-g";
56+
maintainers = [ samrose ];
57+
};
58+
}

0 commit comments

Comments
 (0)