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 | |
workflow_dispatch: | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout code | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
# Step 2: Load .env file | |
- name: Load .env file | |
run: | | |
echo "PERSONAL_ACCESS_TOKEN_GITHUB=${{ secrets.PERSONAL_ACCESS_TOKEN_GITHUB }}" >> .env | |
echo "gemini_key=${{ secrets.gemini_key }}" >> .env | |
cat .env # Print the contents of the .env file for debugging | |
# Step 3: Authenticate to Google Cloud | |
- name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v1 | |
with: | |
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} # The GCP service account key stored in GitHub repository secrets | |
# Step 4: Set up Google Cloud SDK | |
- name: Set up Google Cloud SDK | |
uses: google-github-actions/setup-gcloud@v1 | |
with: | |
project_id: ${{ secrets.GCP_PROJECT_ID }} # GCP project ID stored in GitHub secrets | |
# Step 5: Authenticate Docker to use Google Artifact Registry (GAR) | |
- name: Authenticate Docker with GAR | |
run: gcloud auth configure-docker us-east1-docker.pkg.dev --quiet | |
# Step 6: Build backend Docker image | |
- name: Build backend Docker image | |
run: | | |
cd backend | |
docker build -t us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/devopsgeni/backend:latest \ | |
--build-arg gemini_key=${{ secrets.gemini_key }} \ | |
--build-arg PERSONAL_ACCESS_TOKEN_GITHUB=${{ secrets.PERSONAL_ACCESS_TOKEN_GITHUB }} \ | |
--build-arg ENVIRONMENT=${{ secrets.ENVIRONMENT }} \ | |
--build-arg FRONTEND_URL=${{ secrets.FRONTEND_URL }}. | |
# Step 7: Build frontend Docker image (navigate back to root first) | |
- name: Build frontend Docker image | |
run: | | |
cd frontend | |
docker build -t us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/devopsgeni/frontend:latest \ | |
--build-arg gemini_key=${{secrets.gemini_key }} \ | |
--build-arg PERSONAL_ACCESS_TOKEN_GITHUB=${{ secrets.PERSONAL_ACCESS_TOKEN_GITHUB }} \ | |
--build-arg REACT_APP_BASE_URL=${{secrets.REACT_APP_BASE_URL }} . | |
# Step 8: Push backend Docker image to GAR | |
- name: Push backend Docker image to GAR | |
run: | | |
docker push us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/devopsgeni/backend:latest | |
# Step 9: Push frontend Docker image to GAR | |
- name: Push frontend Docker image to GAR | |
run: | | |
docker push us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/devopsgeni/frontend:latest | |
- name: Deploy frontend to Cloud Run | |
run: | | |
gcloud run deploy devopsgeni-frontend \ | |
--image us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/devopsgeni/frontend:latest \ | |
--platform managed \ | |
--region us-central1 \ | |
--allow-unauthenticated | |
- name: Deploy frontend to Cloud Run | |
run: | | |
gcloud run deploy devopsgeni-baackend \ | |
--image us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/devopsgeni/backend:latest \ | |
--platform managed \ | |
--region us-central1 \ | |
--allow-unauthenticated |