Skip to content

Commit cc2f07e

Browse files
committed
Split CI docker validation into separate workflow + Cache docker builds
1 parent 98aea31 commit cc2f07e

6 files changed

Lines changed: 121 additions & 53 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -153,29 +153,3 @@ jobs:
153153
BETTER_AUTH_SECRET: 'test-secret-minimum-32-characters-long-for-ci'
154154
BETTER_AUTH_URL: 'http://localhost:8080'
155155
NEXT_PUBLIC_API_URL: 'http://localhost:8080/api'
156-
157-
docker-build:
158-
runs-on: ubuntu-latest
159-
needs: [lint, typecheck]
160-
if: github.event_name == 'pull_request'
161-
steps:
162-
- uses: actions/checkout@v4
163-
164-
- name: Set up Docker Buildx
165-
uses: docker/setup-buildx-action@v3
166-
167-
- name: Build API image
168-
uses: docker/build-push-action@v6
169-
with:
170-
context: .
171-
file: ./apps/api/Dockerfile
172-
push: false
173-
174-
- name: Build Web image
175-
uses: docker/build-push-action@v6
176-
with:
177-
context: .
178-
file: ./apps/web/Dockerfile
179-
push: false
180-
build-args: |
181-
NEXT_PUBLIC_API_URL=http://localhost:8080/api

.github/workflows/docker-build.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Docker Build
2+
3+
on:
4+
pull_request:
5+
branches: [main, development]
6+
push:
7+
branches: [main]
8+
9+
# Cancel in-progress runs when a new commit is pushed
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
build-api:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v3
22+
23+
- name: Build API image
24+
uses: docker/build-push-action@v6
25+
with:
26+
context: .
27+
file: ./apps/api/Dockerfile
28+
push: false
29+
cache-from: type=gha
30+
cache-to: type=gha,mode=max
31+
32+
build-web:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- name: Set up Docker Buildx
38+
uses: docker/setup-buildx-action@v3
39+
40+
- name: Build Web image
41+
uses: docker/build-push-action@v6
42+
with:
43+
context: .
44+
file: ./apps/web/Dockerfile
45+
push: false
46+
build-args: |
47+
NEXT_PUBLIC_API_URL=http://localhost:8080/api
48+
cache-from: type=gha
49+
cache-to: type=gha,mode=max

create-blitzpack/src/ci-workflow-template.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -156,31 +156,4 @@ jobs:
156156
BETTER_AUTH_URL: 'http://localhost:8080'
157157
NEXT_PUBLIC_API_URL: 'http://localhost:8080/api'
158158
159-
# @feature dockerDeploy
160-
docker-build:
161-
runs-on: ubuntu-latest
162-
needs: [lint, typecheck]
163-
if: github.event_name == 'pull_request'
164-
steps:
165-
- uses: actions/checkout@v4
166-
167-
- name: Set up Docker Buildx
168-
uses: docker/setup-buildx-action@v3
169-
170-
- name: Build API image
171-
uses: docker/build-push-action@v6
172-
with:
173-
context: .
174-
file: ./apps/api/Dockerfile
175-
push: false
176-
177-
- name: Build Web image
178-
uses: docker/build-push-action@v6
179-
with:
180-
context: .
181-
file: ./apps/web/Dockerfile
182-
push: false
183-
build-args: |
184-
NEXT_PUBLIC_API_URL=http://localhost:8080/api
185-
# @endfeature
186159
`;

create-blitzpack/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export const FEATURE_EXCLUSIONS: Record<FeatureKey, string[]> = {
105105
'apps/api/Dockerfile',
106106
'apps/web/Dockerfile',
107107
'deploy/docker',
108+
'.github/workflows/docker-build.yml',
108109
],
109110
ciCd: ['.github/workflows/cd.yml'],
110111
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
export const DOCKER_CI_WORKFLOW_TEMPLATE = `name: Docker Build
2+
3+
on:
4+
pull_request:
5+
branches: [main, development]
6+
push:
7+
branches: [main]
8+
9+
# Cancel in-progress runs when a new commit is pushed
10+
concurrency:
11+
group: \${{ github.workflow }}-\${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
build-api:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v3
22+
23+
- name: Build API image
24+
uses: docker/build-push-action@v6
25+
with:
26+
context: .
27+
file: ./apps/api/Dockerfile
28+
push: false
29+
cache-from: type=gha
30+
cache-to: type=gha,mode=max
31+
32+
build-web:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- name: Set up Docker Buildx
38+
uses: docker/setup-buildx-action@v3
39+
40+
- name: Build Web image
41+
uses: docker/build-push-action@v6
42+
with:
43+
context: .
44+
file: ./apps/web/Dockerfile
45+
push: false
46+
build-args: |
47+
NEXT_PUBLIC_API_URL=http://localhost:8080/api
48+
cache-from: type=gha
49+
cache-to: type=gha,mode=max
50+
`;

create-blitzpack/src/transform.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
REPLACEABLE_FILES,
1010
type TemplateVariables,
1111
} from './constants.js';
12+
import { DOCKER_CI_WORKFLOW_TEMPLATE } from './docker-ci-workflow-template.js';
1213

1314
const TESTING_SCRIPTS = [
1415
'test',
@@ -42,6 +43,7 @@ const TESTING_FILE_PATTERNS = [
4243
const TS_CONFIG_FILE_PATTERN = /^tsconfig(?:\.[^.]+)?\.json$/;
4344
const AGENT_DOC_TARGETS = ['CLAUDE.md', 'AGENTS.md'];
4445
const CI_WORKFLOW_RELATIVE_PATH = '.github/workflows/ci.yml';
46+
const DOCKER_CI_WORKFLOW_RELATIVE_PATH = '.github/workflows/docker-build.yml';
4547

4648
const MARKER_FILES = [
4749
'apps/api/src/app.ts',
@@ -283,6 +285,7 @@ async function applyFeatureTransforms(
283285
}
284286

285287
await transformCiWorkflow(targetDir, disabledFeatures);
288+
await transformDockerCiWorkflow(targetDir, features);
286289
await transformAgentDocs(targetDir, disabledFeatures);
287290
}
288291

@@ -515,3 +518,21 @@ async function transformCiWorkflow(
515518
content = cleanEmptyLines(content).trimEnd() + '\n';
516519
await fs.writeFile(workflowPath, content, 'utf-8');
517520
}
521+
522+
async function transformDockerCiWorkflow(
523+
targetDir: string,
524+
features: FeatureOptions
525+
): Promise<void> {
526+
const workflowPath = path.join(targetDir, DOCKER_CI_WORKFLOW_RELATIVE_PATH);
527+
528+
if (!features.dockerDeploy) {
529+
if (await fs.pathExists(workflowPath)) {
530+
await fs.remove(workflowPath);
531+
}
532+
return;
533+
}
534+
535+
await fs.ensureDir(path.dirname(workflowPath));
536+
const content = DOCKER_CI_WORKFLOW_TEMPLATE.trimEnd() + '\n';
537+
await fs.writeFile(workflowPath, content, 'utf-8');
538+
}

0 commit comments

Comments
 (0)