Skip to content

Commit 7849acc

Browse files
authored
Add cache for clickhouse migrator (#937)
1 parent 6cb4d9b commit 7849acc

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

.github/actions/start-services/action.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ runs:
4444
make -C tests/integration seed
4545
shell: bash
4646

47+
48+
- name: Set up Docker Buildx
49+
uses: docker/setup-buildx-action@v3
50+
51+
- name: Build codegen image with caching
52+
uses: docker/build-push-action@v6
53+
with:
54+
context: packages/clickhouse
55+
file: packages/clickhouse/Dockerfile
56+
tags: clickhouse-migrator:latest
57+
load: true # makes the image available for `docker run`
58+
cache-from: type=gha
59+
cache-to: type=gha,mode=max
60+
61+
4762
- name: Run Clickhouse
4863
env:
4964
CLICKHOUSE_USERNAME: "e2b"
@@ -62,7 +77,8 @@ runs:
6277
while [ "$(docker inspect -f '{{.State.Health.Status}}' clickhouse 2>/dev/null)" != "healthy" ]; do echo "Waiting for Clickhouse to be healthy..."; sleep 2; done
6378
echo "Clickhouse is healthy!"
6479
65-
make -C packages/clickhouse migrate
80+
# We build the image in separate step to cache it and avoid rebuilding it every time
81+
make -C packages/clickhouse migrate-without-build
6682
shell: bash
6783

6884
- name: Start Services

.github/workflows/pull-request.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ jobs:
4040
uses: actions/download-artifact@v4
4141
with:
4242
path: artifacts
43+
# Docker build artifacts have to ignored
44+
# https://github.com/actions/toolkit/pull/1874
45+
pattern: "!*.dockerbuild"
4346

4447
- name: Publish Test Results
4548
uses: EnricoMi/publish-unit-test-result-action@v2

packages/clickhouse/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ RUN apk add --no-cache git
55
RUN go install github.com/pressly/goose/v3/cmd/[email protected]
66

77
# Final stage
8-
FROM alpine:latest
8+
FROM alpine:3.22.1
99

1010
RUN apk add --no-cache bash ca-certificates
1111

1212
COPY --from=builder /go/bin/goose /usr/local/bin/goose
1313

1414
WORKDIR /app
15-
COPY /migrations ./migrations
15+
COPY migrations/ ./migrations/
1616

1717
ENV GOOSE_DRIVER=clickhouse
1818
ENTRYPOINT ["goose", "-table", "_migrations", "-dir", "migrations", "up"]

packages/clickhouse/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ CLICKHOUSE_MIGRATOR_IMAGE ?= $(GCP_REGION)-docker.pkg.dev/$(GCP_PROJECT_ID)/e2b-
55
CLICKHOUSE_HOST ?= clickhouse
66

77
.PHONY: migrate
8-
migrate:build
8+
migrate: build migrate-without-build
9+
10+
.PHONY: migrate-without-build
11+
migrate-without-build:
912
@echo "Applying Clickhouse migrations *$(notdir $@)*"
1013
@docker network create e2b || true
1114
@docker run --rm \
@@ -18,7 +21,6 @@ migrate:build
1821

1922
.PHONY: build
2023
build:
21-
@echo "$(CLICKHOUSE_MIGRATOR_IMAGE)"
2224
@docker build --platform linux/amd64 --tag "$(CLICKHOUSE_MIGRATOR_IMAGE)" .
2325

2426
.PHONY: build-and-upload

0 commit comments

Comments
 (0)