GovAssist #254
This file contains 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: CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
id-token: write | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Set up Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
flutter-version: '3.27.0' | |
- name: Build Flutter Web App | |
run: | | |
cd app | |
flutter pub get | |
flutter build web --release | |
# Verify build success | |
if [ ! -d "build/web" ]; then | |
echo "Error: build/web directory does not exist" | |
exit 1 | |
fi | |
echo "Flutter Web build completed successfully." | |
- name: Upload Build Artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: flutter-web-build | |
path: app/build/web | |
docker-build-push: | |
runs-on: ubuntu-latest | |
needs: build | |
permissions: | |
contents: read | |
id-token: write | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Download Flutter Web Build Artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: flutter-web-build | |
path: flutter-web-build | |
- name: Verify Downloaded Artifact | |
run: | | |
echo "Verifying downloaded artifact..." | |
ls -la # This will show the current directory's contents | |
ls -la flutter-web-build || echo "flutter-web-build directory doesn't exist" # Added check for existence of the directory | |
- name: Prepare Build Context | |
run: | | |
mkdir -p build/web | |
cp -r flutter-web-build/* build/web # Copy files from the downloaded artifact to the build/web folder | |
echo "Build context prepared:" | |
ls -la build/web # Verify the files are in the build/web directory | |
- name: Authenticate to GCP | |
uses: google-github-actions/auth@v1 | |
with: | |
credentials_json: ${{ secrets.GCP_CREDENTIALS }} | |
- name: Configure Docker Authentication | |
run: | | |
gcloud auth configure-docker us-central1-docker.pkg.dev | |
- name: Build Docker Image for API | |
run: | | |
docker build \ | |
-t us-central1-docker.pkg.dev/government-assistant-001/government-assistant-docker-repo/government-assistant-api \ | |
-f Dockerfile . | |
- name: Build Docker Image for Flutter Web App | |
run: | | |
docker build \ | |
-t us-central1-docker.pkg.dev/government-assistant-001/government-assistant-docker-repo/flutter-web-app \ | |
-f Dockerfile.web . | |
- name: Verify Files in Docker Image | |
run: | | |
docker run us-central1-docker.pkg.dev/government-assistant-001/government-assistant-docker-repo/flutter-web-app ls -l /usr/share/nginx/html | |
- name: Push Docker Images | |
run: | | |
docker push us-central1-docker.pkg.dev/government-assistant-001/government-assistant-docker-repo/government-assistant-api | |
docker push us-central1-docker.pkg.dev/government-assistant-001/government-assistant-docker-repo/flutter-web-app | |
deploy: | |
runs-on: ubuntu-latest | |
needs: docker-build-push | |
permissions: | |
contents: read | |
id-token: write | |
actions: read | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Authenticate to GCP | |
uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: ${{ secrets.GCP_CREDENTIALS }} | |
- name: Deploy API to Cloud Run | |
env: | |
XAI_API_KEY: ${{ secrets.XAI_API_KEY }} | |
run: | | |
gcloud run deploy government-assistant-api \ | |
--image us-central1-docker.pkg.dev/government-assistant-001/government-assistant-docker-repo/government-assistant-api \ | |
--platform managed \ | |
--region us-central1 \ | |
--allow-unauthenticated \ | |
--update-env-vars XAI_API_KEY=$XAI_API_KEY | |
- name: Deploy Flutter Web App to Cloud Run | |
run: | | |
gcloud run deploy flutter-web-app \ | |
--image us-central1-docker.pkg.dev/government-assistant-001/government-assistant-docker-repo/flutter-web-app \ | |
--platform managed \ | |
--region us-central1 \ | |
--allow-unauthenticated |