Skip to content

Commit 8bd0aa5

Browse files
authored
Fix docker publish (#697)
* fix migrations + do docker builds in parallel * do arm64 build on arm runner * regenerate new migrations * migration validation * temporarily modify journal * fetch previous commit * bruh * another test * fix * use v4 actions * fix image manifest
1 parent 997b43b commit 8bd0aa5

23 files changed

+247
-11598
lines changed

.github/workflows/docker-build-web.yml

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@ on:
1111

1212
jobs:
1313
build:
14-
name: Build Docker Image
15-
runs-on: ubuntu-latest
14+
name: Build Docker Image (${{ matrix.platform }})
15+
runs-on: ${{ matrix.runner }}
16+
strategy:
17+
matrix:
18+
include:
19+
- platform: amd64
20+
runner: ubuntu-24.04
21+
- platform: arm64
22+
runner: ubuntu-24.04-arm
23+
fail-fast: false
1624
permissions:
1725
contents: read
1826
packages: write
@@ -39,25 +47,59 @@ jobs:
3947
username: ${{ github.actor }}
4048
password: ${{ secrets.GITHUB_TOKEN }}
4149

42-
- name: Prepare Docker Metadata
43-
id: meta
44-
uses: docker/metadata-action@v5
45-
with:
46-
images: ghcr.io/capsoftware/cap-web
47-
tags: |
48-
type=raw,value=${{ inputs.tag || 'latest' }}
49-
50-
- name: Build Docker Image
50+
- name: Build and Push Platform Image
51+
id: build
5152
uses: docker/build-push-action@v5
5253
with:
5354
context: .
5455
file: apps/web/Dockerfile
55-
platforms: linux/amd64,linux/arm64
56-
tags: ${{ steps.meta.outputs.tags }}
56+
platforms: linux/${{ matrix.platform }}
5757
push: true
58-
load: false
59-
cache-from: type=gha
60-
cache-to: type=gha,mode=max
58+
outputs: type=image,name=ghcr.io/capsoftware/cap-web,push-by-digest=true
59+
cache-from: type=gha,scope=buildx-${{ matrix.platform }}
60+
cache-to: type=gha,mode=max,scope=buildx-${{ matrix.platform }}
61+
62+
- name: Export Digest
63+
run: |
64+
mkdir -p /tmp/digests
65+
digest="${{ steps.build.outputs.digest }}"
66+
touch "/tmp/digests/${digest#sha256:}"
67+
68+
- name: Upload Digest
69+
uses: actions/upload-artifact@v4
70+
with:
71+
name: digests-${{ matrix.platform }}
72+
path: /tmp/digests/*
73+
if-no-files-found: error
74+
retention-days: 1
75+
76+
merge:
77+
name: Create Multi-Architecture Manifest
78+
needs: build
79+
runs-on: ubuntu-latest
80+
permissions:
81+
contents: read
82+
packages: write
83+
84+
steps:
85+
- name: Download Digests
86+
uses: actions/download-artifact@v4
87+
with:
88+
path: /tmp/digests
89+
pattern: digests-*
90+
merge-multiple: true
6191

62-
- name: Show Docker Images
63-
run: docker images
92+
- name: Set up Docker Buildx
93+
uses: docker/setup-buildx-action@v3
94+
95+
- name: Login to GitHub Container Registry
96+
uses: docker/login-action@v3
97+
with:
98+
registry: ghcr.io
99+
username: ${{ github.actor }}
100+
password: ${{ secrets.GITHUB_TOKEN }}
101+
102+
- name: Create Image Manifest
103+
run: |
104+
docker buildx imagetools create -t ghcr.io/capsoftware/cap-web:${{ inputs.tag || 'latest' }} \
105+
$(find /tmp/digests -type f -not -path "*/\.*" -exec basename {} \; | xargs -I {} echo "ghcr.io/capsoftware/cap-web@sha256:{}")
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Validate Migrations
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "packages/database/migrations/**"
7+
8+
jobs:
9+
validate-journal:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout PR branch
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Validate journal is append-only
18+
run: |
19+
JOURNAL_PATH="packages/database/migrations/meta/_journal.json"
20+
21+
# Get the journal from previous commit
22+
git fetch origin
23+
24+
# Check if journal exists in previous commit
25+
if git show 34cd664a1215:$JOURNAL_PATH > /dev/null 2>&1; then
26+
git show 34cd664a1215:$JOURNAL_PATH > base.json
27+
else
28+
echo '{"version":"5","dialect":"mysql","entries":[]}' > base.json
29+
fi
30+
31+
# Get current journal
32+
cp $JOURNAL_PATH current.json
33+
34+
# Check version and dialect haven't changed
35+
BASE_VERSION=$(jq -r '.version' base.json)
36+
CURRENT_VERSION=$(jq -r '.version' current.json)
37+
if [ "$BASE_VERSION" != "$CURRENT_VERSION" ]; then
38+
echo "::error file=$JOURNAL_PATH,line=2,title=Version Changed::Migration journal version cannot be changed (was: $BASE_VERSION, now: $CURRENT_VERSION)"
39+
exit 1
40+
fi
41+
42+
BASE_DIALECT=$(jq -r '.dialect' base.json)
43+
CURRENT_DIALECT=$(jq -r '.dialect' current.json)
44+
if [ "$BASE_DIALECT" != "$CURRENT_DIALECT" ]; then
45+
echo "::error file=$JOURNAL_PATH,line=3,title=Dialect Changed::Migration journal dialect cannot be changed (was: $BASE_DIALECT, now: $CURRENT_DIALECT)"
46+
exit 1
47+
fi
48+
49+
# Check that entries weren't removed
50+
BASE_COUNT=$(jq '.entries | length' base.json)
51+
CURRENT_COUNT=$(jq '.entries | length' current.json)
52+
if [ "$CURRENT_COUNT" -lt "$BASE_COUNT" ]; then
53+
echo "::error file=$JOURNAL_PATH,title=Entries Removed::Migration entries cannot be removed (base has $BASE_COUNT entries, current has $CURRENT_COUNT)"
54+
exit 1
55+
fi
56+
57+
# Extract and compare the overlapping entries
58+
jq --argjson n "$BASE_COUNT" '.entries[:$n]' current.json > current_overlap.json
59+
jq '.entries' base.json > base_entries.json
60+
61+
if ! diff -q base_entries.json current_overlap.json > /dev/null; then
62+
echo "::error file=$JOURNAL_PATH,title=Existing Entries Modified::Existing migration entries have been modified. Migrations are append-only."
63+
64+
# Find which entry was modified using jq
65+
for i in $(seq 0 $((BASE_COUNT - 1))); do
66+
BASE_ENTRY=$(jq ".entries[$i]" base.json)
67+
CURRENT_ENTRY=$(jq ".entries[$i]" current.json)
68+
if [ "$BASE_ENTRY" != "$CURRENT_ENTRY" ]; then
69+
TAG=$(echo "$BASE_ENTRY" | jq -r '.tag')
70+
echo "::error file=$JOURNAL_PATH,title=Entry Modified::Migration entry '$TAG' (index $i) was modified"
71+
fi
72+
done
73+
exit 1
74+
fi
75+
76+
echo "::notice file=$JOURNAL_PATH,title=Journal Valid::✅ Migration journal validation passed! ($((CURRENT_COUNT - BASE_COUNT)) new entries added)"

packages/database/migrations/0002_zippy_rocket_raccoon.sql renamed to packages/database/migrations/0002_dusty_maginty.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CREATE TABLE `space_members` (
22
`id` varchar(15) NOT NULL,
33
`spaceId` varchar(15) NOT NULL,
44
`userId` varchar(15) NOT NULL,
5-
`role` varchar(255) NOT NULL,
5+
`role` varchar(255) NOT NULL DEFAULT 'member',
66
`createdAt` timestamp NOT NULL DEFAULT (now()),
77
`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
88
CONSTRAINT `space_members_id` PRIMARY KEY(`id`),
@@ -21,12 +21,15 @@ CREATE TABLE `space_videos` (
2121
--> statement-breakpoint
2222
CREATE TABLE `spaces` (
2323
`id` varchar(15) NOT NULL,
24+
`primary` boolean NOT NULL DEFAULT false,
2425
`name` varchar(255) NOT NULL,
2526
`organizationId` varchar(15) NOT NULL,
2627
`createdById` varchar(15) NOT NULL,
28+
`iconUrl` varchar(255),
2729
`description` varchar(1000),
2830
`createdAt` timestamp NOT NULL DEFAULT (now()),
2931
`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
32+
`privacy` varchar(255) NOT NULL DEFAULT 'Private',
3033
CONSTRAINT `spaces_id` PRIMARY KEY(`id`),
3134
CONSTRAINT `spaces_id_unique` UNIQUE(`id`)
3235
);

packages/database/migrations/0003_fat_krista_starr.sql

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/database/migrations/0006_melted_paibok.sql

Lines changed: 0 additions & 42 deletions
This file was deleted.

packages/database/migrations/0007_outgoing_tiger_shark.sql

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/database/migrations/0008_absent_skaar.sql

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/database/migrations/0009_messy_shen.sql

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/database/migrations/0010_lean_terror.sql

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/database/migrations/0011_deep_multiple_man.sql

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)