Skip to content

Commit d5b49a4

Browse files
authored
ci: Cache postgres volume after first migration (#3488)
This patch caches all DB volumes based on the sentry and snuba images to avoid doing the same migrations over and over for every test run. This shaved off a whole minute from "Install self-hosted" jobs (so ~20% speed increase). Left side: cached re-run -- Right side: no-cache initial run ![image](https://github.com/user-attachments/assets/55b923ea-d4c8-44bf-ba3e-0d5708781fd8)
1 parent 1bb22c0 commit d5b49a4

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

.github/workflows/test.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ on:
1010
pull_request:
1111
schedule:
1212
- cron: "0 0,12 * * *"
13+
14+
concurrency:
15+
group: ${{ github.ref_name || github.sha }}
16+
cancel-in-progress: true
17+
1318
defaults:
1419
run:
1520
shell: bash
@@ -66,9 +71,48 @@ jobs:
6671
sudo curl -L https://github.com/docker/compose/releases/download/v2.26.0/docker-compose-`uname -s`-`uname -m` -o "/usr/local/lib/docker/cli-plugins/docker-compose"
6772
sudo chmod +x "/usr/local/lib/docker/cli-plugins/docker-compose"
6873
74+
- name: Prepare Docker Volume Caching
75+
id: cache_key
76+
run: |
77+
# Set permissions for docker volumes so we can cache and restore
78+
sudo chmod o+x /var/lib/docker
79+
sudo chmod -R o+rwx /var/lib/docker/volumes
80+
source .env
81+
SENTRY_IMAGE_SHA=$(docker buildx imagetools inspect $SENTRY_IMAGE --format "{{println .Manifest.Digest}}")
82+
echo "SENTRY_IMAGE_SHA=$SENTRY_IMAGE_SHA" >> $GITHUB_OUTPUT
83+
SNUBA_IMAGE_SHA=$(docker buildx imagetools inspect $SNUBA_IMAGE --format "{{println .Manifest.Digest}}")
84+
echo "SNUBA_IMAGE_SHA=$SNUBA_IMAGE_SHA" >> $GITHUB_OUTPUT
85+
86+
- name: Restore DB Volumes Cache
87+
id: restore_cache
88+
uses: actions/cache/restore@v4
89+
with:
90+
key: db-volumes-v4-${{ steps.cache_key.outputs.SENTRY_IMAGE_SHA }}-${{ steps.cache_key.outputs.SNUBA_IMAGE_SHA }}
91+
restore-keys: |
92+
db-volumes-v4-${{ steps.cache_key.outputs.SENTRY_IMAGE_SHA }}
93+
db-volumes-v4-
94+
path: |
95+
/var/lib/docker/volumes/sentry-postgres/_data
96+
/var/lib/docker/volumes/sentry-clickhouse/_data
97+
6998
- name: Install ${{ env.LATEST_TAG }}
7099
run: ./install.sh
71100

101+
- name: Prepare Docker Volume Caching
102+
run: |
103+
# Set permissions for docker volumes so we can cache and restore
104+
sudo chmod o+x /var/lib/docker
105+
sudo chmod -R o+rx /var/lib/docker/volumes
106+
107+
- name: Save DB Volumes Cache
108+
if: steps.restore_cache.outputs.cache-hit != 'true'
109+
uses: actions/cache/save@v4
110+
with:
111+
key: ${{ steps.restore_cache.outputs.cache-primary-key }}
112+
path: |
113+
/var/lib/docker/volumes/sentry-postgres/_data
114+
/var/lib/docker/volumes/sentry-clickhouse/_data
115+
72116
- name: Checkout current ref
73117
uses: actions/checkout@v4
74118

@@ -125,13 +169,52 @@ jobs:
125169
sudo curl -L https://github.com/docker/compose/releases/download/${{ matrix.compose_version }}/docker-compose-`uname -s`-`uname -m` -o "${{ matrix.compose_path }}/docker-compose"
126170
sudo chmod +x "${{ matrix.compose_path }}/docker-compose"
127171
172+
- name: Prepare Docker Volume Caching
173+
id: cache_key
174+
run: |
175+
# Set permissions for docker volumes so we can cache and restore
176+
sudo chmod o+x /var/lib/docker
177+
sudo chmod -R o+rwx /var/lib/docker/volumes
178+
source .env
179+
SENTRY_IMAGE_SHA=$(docker buildx imagetools inspect $SENTRY_IMAGE --format "{{println .Manifest.Digest}}")
180+
echo "SENTRY_IMAGE_SHA=$SENTRY_IMAGE_SHA" >> $GITHUB_OUTPUT
181+
SNUBA_IMAGE_SHA=$(docker buildx imagetools inspect $SNUBA_IMAGE --format "{{println .Manifest.Digest}}")
182+
echo "SNUBA_IMAGE_SHA=$SNUBA_IMAGE_SHA" >> $GITHUB_OUTPUT
183+
184+
- name: Restore DB Volumes Cache
185+
id: restore_cache
186+
uses: actions/cache/restore@v4
187+
with:
188+
key: db-volumes-v4-${{ steps.cache_key.outputs.SENTRY_IMAGE_SHA }}-${{ steps.cache_key.outputs.SNUBA_IMAGE_SHA }}
189+
restore-keys: |
190+
db-volumes-v4-${{ steps.cache_key.outputs.SENTRY_IMAGE_SHA }}
191+
db-volumes-v4-
192+
path: |
193+
/var/lib/docker/volumes/sentry-postgres/_data
194+
/var/lib/docker/volumes/sentry-clickhouse/_data
195+
128196
- name: Install self-hosted
129197
uses: nick-fields/retry@v3
130198
with:
131199
timeout_minutes: 10
132200
max_attempts: 3
133201
command: ./install.sh
134202

203+
- name: Prepare Docker Volume Caching
204+
run: |
205+
# Set permissions for docker volumes so we can cache and restore
206+
sudo chmod o+x /var/lib/docker
207+
sudo chmod -R o+rx /var/lib/docker/volumes
208+
209+
- name: Save DB Volumes Cache
210+
if: steps.restore_cache.outputs.cache-hit != 'true'
211+
uses: actions/cache/save@v4
212+
with:
213+
key: ${{ steps.restore_cache.outputs.cache-primary-key }}
214+
path: |
215+
/var/lib/docker/volumes/sentry-postgres/_data
216+
/var/lib/docker/volumes/sentry-clickhouse/_data
217+
135218
- name: Integration Test
136219
run: |
137220
docker compose up --wait

0 commit comments

Comments
 (0)