|
2 | 2 |
|
3 | 3 | This guide explains how to use `pg-ami-builder` for local AMI development and iteration. |
4 | 4 |
|
| 5 | + Summary |
| 6 | + |
| 7 | + | Aspect | CI/CD Workflows | pg-ami-builder | |
| 8 | + |--------------------|---------------------------------|-----------------------------------------| |
| 9 | + | AMI Creation | Packer auto-creates only | Packer auto-creates + manual create-ami | |
| 10 | + | Workflow | Linear, automated | Iterative, debuggable | |
| 11 | + | State | Stateless, ephemeral | Stateful, persistent | |
| 12 | + | Error Handling | Terminate and restart | Preserve, debug, fix, continue | |
| 13 | + | Use Case | Production releases, CI testing | Local development, iteration | |
| 14 | + | Instance Lifecycle | Always terminated | Preserved for debugging | |
| 15 | + |
| 16 | + |
5 | 17 | ## Prerequisites |
6 | 18 |
|
7 | 19 | ### Required Tools |
@@ -36,25 +48,25 @@ Your AWS user/role needs these permissions: |
36 | 48 |
|
37 | 49 | ```bash |
38 | 50 | # Run phase 1 build (launches instance and runs packer build) |
39 | | -aws-vault exec dev -- nix run .#pg-ami-builder -- build phase1 --postgres-version 15 |
| 51 | +aws-vault exec <profile> -- nix run .#pg-ami-builder -- build phase1 --postgres-version 15 |
40 | 52 |
|
41 | 53 | # If packer build fails, instance stays alive for debugging |
42 | 54 | # SSH to investigate |
43 | | -aws-vault exec dev -- nix run .#pg-ami-builder -- ssh |
| 55 | +aws-vault exec <profile> -- nix run .#pg-ami-builder -- ssh |
44 | 56 |
|
45 | 57 | # Make local changes and re-run with file sync |
46 | 58 | vim ansible/playbook.yml |
47 | | -aws-vault exec dev -- nix run .#pg-ami-builder -- ansible-rerun phase1 --sync-files |
| 59 | +aws-vault exec <profile> -- nix run .#pg-ami-builder -- ansible-rerun phase1 --sync-files |
48 | 60 |
|
49 | 61 | # Cleanup when done |
50 | | -aws-vault exec dev -- nix run .#pg-ami-builder -- cleanup |
| 62 | +aws-vault exec <profile> -- nix run .#pg-ami-builder -- cleanup |
51 | 63 | ``` |
52 | 64 |
|
53 | 65 | ### Building Phase 2 |
54 | 66 |
|
55 | 67 | ```bash |
56 | 68 | # Run phase 2 with existing stage-1 AMI |
57 | | -aws-vault exec dev -- nix run .#pg-ami-builder -- build phase2 \ |
| 69 | +aws-vault exec <profile> -- nix run .#pg-ami-builder -- build phase2 \ |
58 | 70 | --source-ami ami-stage1-xyz \ |
59 | 71 | --postgres-version 15 |
60 | 72 | ``` |
@@ -161,40 +173,40 @@ nix run .#pg-ami-builder -- cleanup [flags] |
161 | 173 |
|
162 | 174 | ```bash |
163 | 175 | # Run phase 1 build (launches instance and runs packer build) |
164 | | -aws-vault exec dev -- nix run .#pg-ami-builder -- build phase1 --postgres-version 15 |
| 176 | +aws-vault exec <profile> -- nix run .#pg-ami-builder -- build phase1 --postgres-version 15 |
165 | 177 |
|
166 | 178 | # If packer fails, instance stays up for debugging |
167 | 179 | # SSH to investigate |
168 | | -aws-vault exec dev -- nix run .#pg-ami-builder -- ssh |
| 180 | +aws-vault exec <profile> -- nix run .#pg-ami-builder -- ssh |
169 | 181 |
|
170 | 182 | # Make local changes to ansible files |
171 | 183 | vim ansible/playbook.yml |
172 | 184 |
|
173 | 185 | # Re-run with your local changes |
174 | | -aws-vault exec dev -- nix run .#pg-ami-builder -- ansible-rerun phase1 --sync-files |
| 186 | +aws-vault exec <profile> -- nix run .#pg-ami-builder -- ansible-rerun phase1 --sync-files |
175 | 187 |
|
176 | 188 | # Repeat until working, then create AMI |
177 | | -aws-vault exec dev -- nix run .#pg-ami-builder -- build phase1 --postgres-version 15 --create-ami |
| 189 | +aws-vault exec <profile> -- nix run .#pg-ami-builder -- build phase1 --postgres-version 15 --create-ami |
178 | 190 |
|
179 | 191 | # Cleanup |
180 | | -aws-vault exec dev -- nix run .#pg-ami-builder -- cleanup |
| 192 | +aws-vault exec <profile> -- nix run .#pg-ami-builder -- cleanup |
181 | 193 | ``` |
182 | 194 |
|
183 | 195 | ### Workflow 2: Parallel builds for multiple postgres versions |
184 | 196 |
|
185 | 197 | ```bash |
186 | 198 | # Build PG 15 |
187 | | -aws-vault exec dev -- nix run .#pg-ami-builder -- build phase1 \ |
| 199 | +aws-vault exec <profile> -- nix run .#pg-ami-builder -- build phase1 \ |
188 | 200 | --postgres-version 15 \ |
189 | 201 | --state-file ~/.pg-ami-build/pg15.json |
190 | 202 |
|
191 | 203 | # Build PG 16 in parallel |
192 | | -aws-vault exec dev -- nix run .#pg-ami-builder -- build phase1 \ |
| 204 | +aws-vault exec <profile> -- nix run .#pg-ami-builder -- build phase1 \ |
193 | 205 | --postgres-version 16 \ |
194 | 206 | --state-file ~/.pg-ami-build/pg16.json |
195 | 207 |
|
196 | 208 | # SSH into PG 15 instance |
197 | | -aws-vault exec dev -- nix run .#pg-ami-builder -- ssh \ |
| 209 | +aws-vault exec <profile> -- nix run .#pg-ami-builder -- ssh \ |
198 | 210 | --state-file ~/.pg-ami-build/pg15.json |
199 | 211 | ``` |
200 | 212 |
|
|
0 commit comments