From ca9742cceab9124243af966f1ac96f0e757a9d6d Mon Sep 17 00:00:00 2001 From: RawSalmon Date: Fri, 4 Jul 2025 23:08:48 +0700 Subject: [PATCH 1/2] feat: improve deployment --- .github/workflows/deploy.yml | 58 ++++++++++++++++++++++++++++++++---- Dockerfile | 13 ++++---- public/images/README.md | 7 +++++ public/images/logo.svg | 4 +++ public/images/test-image.svg | 4 +++ src/pages/index.astro | 13 ++++++++ 6 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 public/images/README.md create mode 100644 public/images/logo.svg create mode 100644 public/images/test-image.svg diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 218f123..aac45c4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -54,7 +54,27 @@ jobs: run: pnpm install --no-frozen-lockfile - name: Build Astro application (Development) - run: pnpm run build + run: | + echo "🏗️ Building Astro application..." + pnpm run build + + # Create checksum of build artifacts for verification + find ./dist -type f -name "*.css" -o -name "*.js" -o -name "*.mjs" | sort | xargs sha256sum > build-manifest.txt + echo "📄 Build manifest created:" + cat build-manifest.txt + + # Verify critical files exist + if [ ! -f "./dist/server/entry.mjs" ]; then + echo "❌ Server entry point missing" + exit 1 + fi + + if [ ! -d "./dist/client/_astro" ]; then + echo "❌ Client assets missing" + exit 1 + fi + + echo "✅ Build verification complete" env: PUBLIC_API_URL: ${{ env.API_URL }} PUBLIC_SITE_URL: ${{ env.SITE_URL }} @@ -74,7 +94,21 @@ jobs: - name: Build and push Docker image (Dev) run: | - # Build image with build args + echo "🐳 Building Docker image with pre-built artifacts..." + + # Verify build artifacts haven't changed + find ./dist -type f -name "*.css" -o -name "*.js" -o -name "*.mjs" | sort | xargs sha256sum > current-manifest.txt + if ! diff build-manifest.txt current-manifest.txt; then + echo "❌ Build artifacts changed between build and Docker build!" + echo "Original manifest:" + cat build-manifest.txt + echo "Current manifest:" + cat current-manifest.txt + exit 1 + fi + echo "✅ Build artifacts verified - no changes detected" + + # Build Docker image (will use existing dist/ directory) docker build --build-arg PUBLIC_API_URL=${{ env.API_URL }} --build-arg PUBLIC_SITE_URL=${{ env.SITE_URL }} -t ${{ env.REGISTRY_HOSTNAME }}/${{ env.GCP_PROJECT_ID }}/cloud-run-source-deploy/${{ env.SERVICE_NAME }}:${{ github.sha }} -t ${{ env.REGISTRY_HOSTNAME }}/${{ env.GCP_PROJECT_ID }}/cloud-run-source-deploy/${{ env.SERVICE_NAME }}:latest-dev . # Push both tags @@ -105,13 +139,27 @@ jobs: - name: Upload static assets to Cloud Storage (Dev) run: | - # Only upload if Cloud Run deployment succeeded - echo "Uploading static assets after successful deployment..." + echo "📦 Uploading static assets (same files used in Docker image)..." + + # Final verification - ensure we're uploading the EXACT same files + find ./dist -type f -name "*.css" -o -name "*.js" -o -name "*.mjs" | sort | xargs sha256sum > final-manifest.txt + if ! diff build-manifest.txt final-manifest.txt; then + echo "❌ CRITICAL: Static assets don't match the deployed application!" + exit 1 + fi + echo "✅ Verified: Static assets match deployed application" # Upload Astro static assets if [ -d "./dist/client/_astro" ]; then + echo "📄 Files being uploaded:" + ls -la ./dist/client/_astro/ + gsutil -m rsync -r -d ./dist/client/_astro gs://${{ env.BUCKET_NAME }}/_astro/ echo "✅ Uploaded _astro assets" + + # Verify upload + echo "📄 Files in bucket after upload:" + gsutil ls gs://${{ env.BUCKET_NAME }}/_astro/ else echo "❌ No _astro directory found" exit 1 @@ -129,7 +177,7 @@ jobs: gsutil -m setmeta -h "Cache-Control:public, max-age=86400" \ "gs://${{ env.BUCKET_NAME }}/images/**" || true - echo "✅ Static assets uploaded successfully" + echo "🎉 Static assets uploaded successfully and verified!" # Production deployment deploy-prod: diff --git a/Dockerfile b/Dockerfile index 6fc7964..4d63b8f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,17 +13,20 @@ COPY package.json pnpm-lock.yaml ./ # Install dependencies RUN pnpm install --no-frozen-lockfile -# Copy source code -COPY . . +# Copy pre-built application (built in GitHub Actions) +COPY ./dist ./dist -# Build args for build-time env vars +# Build args for runtime env vars (not used for building) ARG PUBLIC_API_URL ARG PUBLIC_SITE_URL ENV PUBLIC_API_URL=$PUBLIC_API_URL ENV PUBLIC_SITE_URL=$PUBLIC_SITE_URL -# Build the application -RUN pnpm run build +# Verify the build was copied correctly +RUN ls -la ./dist && \ + test -f "./dist/server/entry.mjs" || (echo "❌ Server entry missing" && exit 1) && \ + test -d "./dist/client/_astro" || (echo "❌ Client assets missing" && exit 1) && \ + echo "✅ Pre-built application verified" # Production stage FROM node:20-alpine AS runner diff --git a/public/images/README.md b/public/images/README.md new file mode 100644 index 0000000..3acbdb9 --- /dev/null +++ b/public/images/README.md @@ -0,0 +1,7 @@ +# Test Images + +This directory contains test images to verify the load balancer routing for `/images/*` paths. + +- `logo.svg` - A simple logo SVG +- `test-image.svg` - A blue rectangle with text +- All images should be served from Cloud Storage via the load balancer \ No newline at end of file diff --git a/public/images/logo.svg b/public/images/logo.svg new file mode 100644 index 0000000..793ec96 --- /dev/null +++ b/public/images/logo.svg @@ -0,0 +1,4 @@ + + + LOGO + \ No newline at end of file diff --git a/public/images/test-image.svg b/public/images/test-image.svg new file mode 100644 index 0000000..8a6aae3 --- /dev/null +++ b/public/images/test-image.svg @@ -0,0 +1,4 @@ + + + Test Image + \ No newline at end of file diff --git a/src/pages/index.astro b/src/pages/index.astro index 8707d64..3892ceb 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -6,6 +6,19 @@ import FD from "@firstdate/sample.astro"; --- +
+

FreshmenFest 2025

+ + +
+ Logo +
+ +
+ Test Image +
+
+
From b6a789facb725bcc2c47103f5bc2b642cd6a60c4 Mon Sep 17 00:00:00 2001 From: RawSalmon Date: Fri, 4 Jul 2025 23:12:06 +0700 Subject: [PATCH 2/2] fix --- .github/workflows/deploy.yml | 53 +++++++++++++++++++++++------------- Dockerfile | 13 +++++---- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index aac45c4..fd5e01f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -94,23 +94,39 @@ jobs: - name: Build and push Docker image (Dev) run: | - echo "🐳 Building Docker image with pre-built artifacts..." + echo "🐳 Building Docker image..." - # Verify build artifacts haven't changed - find ./dist -type f -name "*.css" -o -name "*.js" -o -name "*.mjs" | sort | xargs sha256sum > current-manifest.txt - if ! diff build-manifest.txt current-manifest.txt; then - echo "❌ Build artifacts changed between build and Docker build!" - echo "Original manifest:" - cat build-manifest.txt - echo "Current manifest:" - cat current-manifest.txt - exit 1 - fi - echo "✅ Build artifacts verified - no changes detected" + # Store the GitHub Actions build for comparison + cp -r ./dist ./dist-github - # Build Docker image (will use existing dist/ directory) + # Build Docker image (will rebuild inside container) docker build --build-arg PUBLIC_API_URL=${{ env.API_URL }} --build-arg PUBLIC_SITE_URL=${{ env.SITE_URL }} -t ${{ env.REGISTRY_HOSTNAME }}/${{ env.GCP_PROJECT_ID }}/cloud-run-source-deploy/${{ env.SERVICE_NAME }}:${{ github.sha }} -t ${{ env.REGISTRY_HOSTNAME }}/${{ env.GCP_PROJECT_ID }}/cloud-run-source-deploy/${{ env.SERVICE_NAME }}:latest-dev . + # Extract build from Docker image to verify consistency + docker create --name temp-container ${{ env.REGISTRY_HOSTNAME }}/${{ env.GCP_PROJECT_ID }}/cloud-run-source-deploy/${{ env.SERVICE_NAME }}:${{ github.sha }} + docker cp temp-container:/app/dist ./dist-docker + docker rm temp-container + + # Compare the builds + echo "🔍 Comparing GitHub Actions build vs Docker build..." + find ./dist-github -type f -name "*.css" -o -name "*.js" -o -name "*.mjs" | sort | sed 's|./dist-github|./dist|' | xargs -I {} sh -c 'sha256sum ./dist-github/$(echo {} | sed "s|./dist/||")' > github-manifest.txt + find ./dist-docker -type f -name "*.css" -o -name "*.js" -o -name "*.mjs" | sort | sed 's|./dist-docker|./dist|' | xargs -I {} sh -c 'sha256sum ./dist-docker/$(echo {} | sed "s|./dist/||")' > docker-manifest.txt + + if ! diff github-manifest.txt docker-manifest.txt; then + echo "⚠️ WARNING: Docker build produced different artifacts!" + echo "GitHub build files:" + ls -la ./dist-github/client/_astro/ + echo "Docker build files:" + ls -la ./dist-docker/client/_astro/ + echo "Using Docker build (this is what runs in production)" + else + echo "✅ Docker build matches GitHub Actions build perfectly" + fi + + # Use Docker build artifacts for bucket upload + rm -rf ./dist + mv ./dist-docker ./dist + # Push both tags docker push ${{ env.REGISTRY_HOSTNAME }}/${{ env.GCP_PROJECT_ID }}/cloud-run-source-deploy/${{ env.SERVICE_NAME }}:${{ github.sha }} docker push ${{ env.REGISTRY_HOSTNAME }}/${{ env.GCP_PROJECT_ID }}/cloud-run-source-deploy/${{ env.SERVICE_NAME }}:latest-dev @@ -139,15 +155,14 @@ jobs: - name: Upload static assets to Cloud Storage (Dev) run: | - echo "📦 Uploading static assets (same files used in Docker image)..." + echo "📦 Uploading static assets (EXACT same files from deployed Docker image)..." - # Final verification - ensure we're uploading the EXACT same files - find ./dist -type f -name "*.css" -o -name "*.js" -o -name "*.mjs" | sort | xargs sha256sum > final-manifest.txt - if ! diff build-manifest.txt final-manifest.txt; then - echo "❌ CRITICAL: Static assets don't match the deployed application!" + # Verify we're using Docker build artifacts + if [ ! -f "./dist/server/entry.mjs" ]; then + echo "❌ Docker build artifacts not found!" exit 1 fi - echo "✅ Verified: Static assets match deployed application" + echo "✅ Using Docker build artifacts (matches deployed container)" # Upload Astro static assets if [ -d "./dist/client/_astro" ]; then diff --git a/Dockerfile b/Dockerfile index 4d63b8f..40a112f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,20 +13,23 @@ COPY package.json pnpm-lock.yaml ./ # Install dependencies RUN pnpm install --no-frozen-lockfile -# Copy pre-built application (built in GitHub Actions) -COPY ./dist ./dist +# Copy source code +COPY . . -# Build args for runtime env vars (not used for building) +# Build args for build-time env vars ARG PUBLIC_API_URL ARG PUBLIC_SITE_URL ENV PUBLIC_API_URL=$PUBLIC_API_URL ENV PUBLIC_SITE_URL=$PUBLIC_SITE_URL -# Verify the build was copied correctly +# Build the application +RUN pnpm run build + +# Verify the build completed correctly RUN ls -la ./dist && \ test -f "./dist/server/entry.mjs" || (echo "❌ Server entry missing" && exit 1) && \ test -d "./dist/client/_astro" || (echo "❌ Client assets missing" && exit 1) && \ - echo "✅ Pre-built application verified" + echo "✅ Build verification complete" # Production stage FROM node:20-alpine AS runner