From 05b51539356ab4bf70715b8d140e1f44f339df42 Mon Sep 17 00:00:00 2001 From: furkmak <93638016+furkmak@users.noreply.github.com> Date: Wed, 2 Oct 2024 16:05:08 -0700 Subject: [PATCH] Update ci-cd.yml --- .github/workflows/ci-cd.yml | 43 ++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 98b31cc..0135df8 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -19,20 +19,22 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - - name: Log in to Docker Hub (or another registry) - env: - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - run: echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin + - name: Authenticate to GCP + uses: google-github-actions/auth@v1 + with: + credentials_json: ${{ secrets.GCP_CREDENTIALS }} - - name: Build and Push Docker image (latest) + - name: Configure Docker to use the Google Cloud Registry + run: gcloud auth configure-docker + + - name: Build and push Docker image to GCR run: | - docker build -t furkmak/legalapp:latest . - docker push furkmak/legalapp:latest + docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/legalapp:latest . + docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/legalapp:latest - name: Run FastAPI application and test Q&A run: | - docker run -d -p 8000:8000 furkmak/legalapp:latest # Start container + docker run -d -p 8000:8000 gcr.io/${{ secrets.GCP_PROJECT_ID }}/legalapp:latest # Start container sleep 10 # Wait for the server to start curl -X POST "http://localhost:8000/qa" -H "Content-Type: application/x-www-form-urlencoded" \ -d "question=What is the legal definition of negligence?&context=Negligence is the failure to take proper care in doing something." @@ -46,18 +48,15 @@ jobs: - name: Check out the code uses: actions/checkout@v3 - - name: Log in to Docker Hub (or another registry) - env: - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - run: echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - - - name: Pull Docker image (latest) - run: docker pull furkmak/legalapp:latest + - name: Authenticate to GCP + uses: google-github-actions/auth@v1 + with: + credentials_json: ${{ secrets.GCP_CREDENTIALS }} - - name: Tag and Push Docker image with version + - name: Deploy to Cloud Run run: | - # Automatically version the image by using the commit SHA - IMAGE_VERSION=$(echo $GITHUB_SHA | cut -c1-7) - docker tag furkmak/legalapp:latest furkmak/legalapp:$IMAGE_VERSION - docker push furkmak/legalapp:$IMAGE_VERSION + gcloud run deploy legalapp \ + --image gcr.io/${{ secrets.GCP_PROJECT_ID }}/legalapp:latest \ + --platform managed \ + --region ${{ secrets.GCP_REGION }} \ + --allow-unauthenticated