Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 68 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -74,9 +94,39 @@ jobs:

- name: Build and push Docker image (Dev)
run: |
# Build image with build args
echo "🐳 Building Docker image..."

# Store the GitHub Actions build for comparison
cp -r ./dist ./dist-github

# 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
Expand Down Expand Up @@ -105,13 +155,26 @@ 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 (EXACT same files from deployed Docker image)..."

# Verify we're using Docker build artifacts
if [ ! -f "./dist/server/entry.mjs" ]; then
echo "❌ Docker build artifacts not found!"
exit 1
fi
echo "✅ Using Docker build artifacts (matches deployed container)"

# 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
Expand All @@ -129,7 +192,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:
Expand Down
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ ENV PUBLIC_SITE_URL=$PUBLIC_SITE_URL
# 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 "✅ Build verification complete"

# Production stage
FROM node:20-alpine AS runner

Expand Down
7 changes: 7 additions & 0 deletions public/images/README.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions public/images/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/images/test-image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ import FD from "@firstdate/sample.astro";
---

<MainLayout title="Home" description="Hello World@Firstdate and RPKM">
<div class="p-4">
<h1 class="text-2xl font-bold mb-4">FreshmenFest 2025</h1>

<!-- Test image from /images/ path -->
<div class="mb-4">
<img src="/images/logo.svg" alt="Logo" class="w-32 h-32" />
</div>

<div class="mb-4">
<img src="/images/test-image.svg" alt="Test Image" class="w-48 h-24" />
</div>
</div>

<FD />
<RPKM />
</MainLayout>
Loading