feat: implement email validation and collection in chat functionality… #23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Frontend Deploy v2 | |
on: | |
push: | |
branches: [main, prod] | |
paths: | |
- "frontend/**" | |
- ".github/workflows/frontend-deploy.yml" | |
pull_request: | |
branches: [main] | |
paths: | |
- "frontend/**" | |
env: | |
FRONTEND_DIR: frontend | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
id-token: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up environment variables | |
id: env | |
run: | | |
if [[ ${{ github.ref }} == 'refs/heads/prod' ]]; then | |
echo "ENVIRONMENT=production" >> $GITHUB_ENV | |
else | |
echo "ENVIRONMENT=development" >> $GITHUB_ENV | |
fi | |
echo "GCP_PROJECT=${{ secrets.GCP_DEV_PROJECT_ID }}" >> $GITHUB_ENV | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
cache: "npm" | |
cache-dependency-path: ${{ env.FRONTEND_DIR }}/package-lock.json | |
- name: Install Dependencies | |
working-directory: ${{ env.FRONTEND_DIR }} | |
run: npm ci | |
- name: Build | |
working-directory: ${{ env.FRONTEND_DIR }} | |
env: | |
VITE_BACKEND_URL: ${{ secrets.VITE_BACKEND_URL }} | |
VITE_ENV: ${{ env.ENVIRONMENT }} | |
run: npm run build | |
- name: Google Auth | |
uses: google-github-actions/auth@v2 | |
with: | |
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} | |
service_account: ${{ secrets.GCP_SA_EMAIL }} | |
- name: Set up Cloud SDK | |
uses: google-github-actions/setup-gcloud@v2 | |
- name: Prepare deployment files | |
working-directory: ${{ env.FRONTEND_DIR }} | |
run: | | |
# Create nginx.conf | |
cat > nginx.conf << 'EOL' | |
server { | |
listen 80; | |
server_name _; | |
root /usr/share/nginx/html; | |
index index.html; | |
location / { | |
try_files $uri $uri/ /index.html; | |
add_header Cache-Control "no-cache"; | |
} | |
location /assets { | |
expires 1y; | |
add_header Cache-Control "public"; | |
} | |
} | |
EOL | |
# Create Dockerfile with the full build process | |
cat > Dockerfile << 'EOL' | |
FROM node:20-alpine as builder | |
WORKDIR /app | |
COPY package*.json ./ | |
RUN npm ci | |
COPY . . | |
RUN npm run build | |
FROM nginx:alpine | |
COPY --from=builder /app/dist /usr/share/nginx/html | |
COPY nginx.conf /etc/nginx/conf.d/default.conf | |
EXPOSE 80 | |
CMD ["nginx", "-g", "daemon off;"] | |
EOL | |
# Create .gcloudignore to ensure proper file inclusion | |
cat > .gcloudignore << 'EOL' | |
.git | |
.gitignore | |
node_modules | |
README.md | |
.env* | |
.vscode | |
.github | |
!src/** | |
!public/** | |
!index.html | |
!package.json | |
!package-lock.json | |
!tsconfig.json | |
!vite.config.ts | |
!tailwind.config.js | |
!postcss.config.js | |
!Dockerfile | |
!nginx.conf | |
EOL | |
# Verify files | |
echo "Checking for required files:" | |
ls -la Dockerfile nginx.conf | |
- name: Deploy to Cloud Run | |
id: deploy | |
run: | | |
echo "Starting deployment process..." | |
cd ${{ env.FRONTEND_DIR }} | |
gcloud run deploy frontend \ | |
--source . \ | |
--platform managed \ | |
--region me-west1 \ | |
--project ${{ env.GCP_PROJECT }} \ | |
--allow-unauthenticated \ | |
--port=80 \ | |
--min-instances=0 \ | |
--max-instances=4 \ | |
--memory=256Mi \ | |
--timeout=300 \ | |
--service-account=${{ secrets.GCP_SA_EMAIL }} \ | |
--set-env-vars="VITE_ENV=${{ env.ENVIRONMENT }},VITE_BACKEND_URL=${{ secrets.VITE_BACKEND_URL }}" \ | |
--labels="managed-by=github-actions,commit-sha=${{ github.sha }}" \ | |
--quiet | |
- name: Map Custom Domain | |
if: github.ref == 'refs/heads/prod' || github.ref == 'refs/heads/main' | |
run: | | |
DOMAIN="${{ github.ref == 'refs/heads/prod' && secrets.PROD_DOMAIN || secrets.DEV_DOMAIN }}" | |
gcloud beta run domain-mappings create \ | |
--service frontend \ | |
--domain $DOMAIN \ | |
--region me-west1 || echo "Domain mapping failed but continuing deployment" |