Skip to content

Commit ca707da

Browse files
0xBigBossclaude
andauthored
feat: implement playwright sharding with CI environment improvements (#1309)
* feat: add sharded playwright * feat: try docker build push ghcr * feat: update CI workflow to conditionally run jobs and handle missing artifacts in Playwright tests * chore: comment out conditional jobs in CI for testing purposes * feat: leverage .env.local.template for CI environment defaults in Docker builds - Add script to export env vars from template to GitHub Actions env - Update Dockerfile to include all environment variables from .env.local.template - Update GitHub workflow to read env vars from .env.local.template - Dynamically collect environment variables for Docker build - Mark all values as secrets in GitHub Actions for security - Update documentation with implementation details 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * fix: update build args generation in CI workflow Replace problematic variable expansion with printenv to fix GitHub Actions syntax error 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * fix(ci): simpler approach, cleanup * feat(ci): enhance Docker build process and artifact handling - Extract build args from environment file - Save and upload Docker image as tarball - Update workflow to utilize new image outputs * feat(ci): improve Playwright test setup and configuration - Set environment variables for Next app and Playwright command - Adjust Docker compose port mapping for clarity - Update Playwright config for conditional server command * fix(ci): update Playwright command to use `--rm` for better container management * feat(ci): refine Playwright command and port setup for better compatibility - Change Playwright command to `docker compose up` - Update Next app port configuration * feat(ci): enhance Playwright setup with startup checks and background logging - Add health check loop for Next app readiness - Update Docker command to run in detached mode * feat(ci): improve CI workflow with focused shard config and enhanced app readiness checks - Simplify matrix shard to only 1 - Add startup and readiness verification logic for Next app * cleanup * Revert "cleanup" This reverts commit 542126a. * use ubuntu latest * speed up playwright merge reports * Add option to install Tilt in setup-env action and check if already installed in install-tilt action * Update next-app service in CI to use .env.local and increase wait time for readiness check * Fix install-tilt action to run installation script from /tmp for better isolation * Add brew-bundle option to setup-env action for installing dependencies with Brew * Update CI workflow to use --env-file option for next-app docker compose command for improved environment variable management * Add Homebrew setup step and cleanup to setup-env action to streamline dependency management in CI workflows * Remove redundant shell declaration from Homebrew setup step in setup-env action to simplify configuration * Add Docker container specification for jobs in CI workflow to standardize execution environment across all steps * Remove Docker container from CI workflow jobs to simplify configuration and avoid redundancy across execution environments * Update Docker Compose to set resource limits and reservations for deployment, enhancing performance and resource management * Increase CI timeout to 60 minutes and streamline Playwright tests setup in workflow for better reliability and performance * Fix environment variable setup in CI for Docker compatibility, replacing localhost with host.docker.internal when necessary * Enhance CI workflow by adding skip_docker_compose flag to control Docker Compose execution based on configuration settings * Refactor CI workflow to properly pass --skip_docker_compose flag in tilt command and remove redundant debug step for clarity * Update CI workflow to use correct .env.local file and improve artifact handling for Playwright test results and reports * Fix CI workflow paths for Playwright reports and improve error handling in Markdown report generation * Update CI workflow to generalize blob report pattern and streamline artifact processing for improved readability * Refactor CI workflow to enhance Playwright report path handling and improve error messaging in Markdown report output * Enhance CI workflow to enable all shards in matrix for improved testing coverage and reliability across builds --------- Co-authored-by: Claude <[email protected]>
1 parent f8babb5 commit ca707da

File tree

15 files changed

+513
-127
lines changed

15 files changed

+513
-127
lines changed
Lines changed: 70 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,80 @@
1-
name: "Setup Docker Build Environment"
2-
description: "Set up Node.js, install Foundry, and set up Bun. Runs Yarn install run docker build"
1+
name: "Build and Push Next App Docker Image"
2+
description: "Builds the next-app Docker image using Buildx, caches layers with GHCR, tags, and pushes to GHCR."
3+
34
inputs:
4-
build-nextjs-docker:
5-
description: "Whether to build Next.js docker image"
6-
required: false
7-
default: "true"
8-
push-nextjs-docker-image:
9-
description: "Whether to push build to dockerhub"
10-
required: false
11-
default: "false"
12-
dockerhub_username:
13-
description: "Username to login to dockerhub"
14-
required: false
15-
dockerhub_password:
16-
description: "Password to login to dockerhub"
5+
build-args:
6+
description: "Build arguments to pass to docker buildx build (e.g., 'ARG1=value1 ARG2=value2')"
177
required: false
8+
default: ""
9+
ghcr-token:
10+
description: "Token for authenticating with GHCR"
11+
required: true
12+
default: ${{ github.token }}
13+
image-name:
14+
description: "Base name for the image in GHCR (e.g., next-app)"
15+
required: true
16+
default: "next-app"
17+
18+
outputs:
19+
image-tag:
20+
description: "The full GHCR tag of the pushed image (e.g., ghcr.io/owner/repo/next-app:sha)"
21+
value: ${{ steps.build-and-push.outputs.image-tag }}
22+
1823
runs:
1924
using: "composite"
2025
steps:
21-
- name: Use Node.js
22-
if: ${{ inputs.build-nextjs-docker == 'true' }}
23-
uses: actions/setup-node@v4
24-
with:
25-
node-version-file: .node-version
26-
cache: "yarn"
27-
- name: Setup Bun
28-
if: ${{ inputs.build-nextjs-docker == 'true' }}
29-
uses: oven-sh/setup-bun@v1
30-
- name: Install Foundry
31-
if: ${{ inputs.build-nextjs-docker == 'true' }}
32-
uses: foundry-rs/foundry-toolchain@v1
26+
- name: Login to GitHub Container Registry
27+
uses: docker/login-action@v3
3328
with:
34-
version: stable
35-
- name: Yarn Install
36-
if: ${{ inputs.build-nextjs-docker == 'true' }}
29+
registry: ghcr.io
30+
username: ${{ github.actor }}
31+
password: ${{ inputs.ghcr-token }}
32+
33+
- name: Generate Image Tag
34+
id: generate-tag
3735
shell: bash
38-
run: yarn install --immutable
39-
- name: Build Next.js
40-
if: ${{ inputs.build-nextjs-docker == 'true' }}
36+
run: |
37+
SHORT_SHA=$(git rev-parse --short=10 HEAD)
38+
IMAGE_TAG="ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ inputs.image-name }}:${SHORT_SHA}"
39+
echo "IMAGE_TAG=${IMAGE_TAG,,}" >> $GITHUB_OUTPUT # Lowercase for Docker compatibility
40+
41+
- name: Set Environment Variables from Template
4142
shell: bash
4243
run: |
43-
cp .env.local.template .env.local
44-
yarn web:docker:build
45-
rm .env.local
46-
- uses: docker/login-action@v3
47-
if: ${{ inputs.build-nextjs-docker == 'true' }} && ${{ inputs.push-nextjs-docker-image == 'true' }}
48-
with:
49-
username: ${{ inputs.dockerhub_username }}
50-
password: ${{ inputs.dockerhub_password }}
51-
- name: Push to dockerhub
44+
if [ -f "./scripts/github-actions-set-env-from-template.sh" ]; then
45+
chmod +x ./scripts/github-actions-set-env-from-template.sh
46+
./scripts/github-actions-set-env-from-template.sh .env.local.template
47+
else
48+
echo "Warning: Environment script not found, using default environment variables"
49+
fi
50+
51+
- name: Build and Push Docker Image
52+
id: build-and-push
5253
shell: bash
53-
if: ${{ inputs.build-nextjs-docker == 'true' }} && ${{ inputs.push-nextjs-docker-image == 'true' }}
54-
run: yarn web:docker:push
54+
run: |
55+
BUILD_ARGS_STRING=""
56+
if [[ -n "${{ inputs.build-args }}" ]]; then
57+
for arg in ${{ inputs.build-args }}; do
58+
BUILD_ARGS_STRING+=" --build-arg $arg"
59+
done
60+
fi
61+
62+
# Add environment variables from template as build arguments
63+
# Only include variables starting with NEXT_PUBLIC_ for the Next.js build
64+
for var in $(env | grep "^NEXT_PUBLIC_" | cut -d= -f1); do
65+
BUILD_ARGS_STRING+=" --build-arg ${var}=${!var}"
66+
done
67+
68+
echo "Building image: ${{ steps.generate-tag.outputs.IMAGE_TAG }}"
69+
echo "Using build args:${BUILD_ARGS_STRING}" # Be careful not to expose secrets here
70+
71+
docker buildx build \
72+
--tag ${{ steps.generate-tag.outputs.IMAGE_TAG }} \
73+
--cache-from type=gha \
74+
--cache-to type=gha,mode=max \
75+
--push \
76+
-f ./apps/next/Dockerfile \
77+
${BUILD_ARGS_STRING} \
78+
.
79+
80+
echo "image-tag=${{ steps.generate-tag.outputs.IMAGE_TAG }}" >> $GITHUB_OUTPUT
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
name: "Install Tilt"
2+
description: "Installs Tilt if not already installed."
23
runs:
34
using: "composite"
45
steps:
56
- name: Install Tilt
67
id: tilt
78
shell: bash
8-
run: curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash
9+
run: command -v tilt || cd /tmp && curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash

.github/actions/setup-env/action.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ inputs:
2121
description: "Whether to build Next.js."
2222
required: false
2323
default: "false"
24+
install-tilt:
25+
description: "Whether to install Tilt."
26+
required: false
27+
default: "true"
28+
brew-bundle:
29+
description: "Whether to run Brew bundle."
30+
required: false
31+
default: "true"
2432
runs:
2533
using: "composite"
2634
steps:
@@ -49,6 +57,20 @@ runs:
4957
if: ${{ inputs.yarn-install == 'true' }}
5058
shell: bash
5159
run: yarn install --immutable --inline-builds
60+
- name: Install Tilt
61+
if: ${{ inputs.install-tilt == 'true' }}
62+
uses: ./.github/actions/install-tilt
63+
- name: Set up Homebrew
64+
if: ${{ inputs.brew-bundle == 'true' }}
65+
id: set-up-homebrew
66+
uses: Homebrew/actions/setup-homebrew@master
67+
- name: Brew Bundle
68+
if: ${{ inputs.brew-bundle == 'true' }}
69+
shell: bash
70+
id: brew-bundle
71+
run: |
72+
brew bundle
73+
brew cleanup
5274
- name: Build Next.js
5375
if: ${{ inputs.build-nextjs == 'true' }}
5476
shell: bash

0 commit comments

Comments
 (0)