Skip to content

Commit

Permalink
Update ci-cd.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
furkmak authored Oct 2, 2024
1 parent 694ee9c commit 05b5153
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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

0 comments on commit 05b5153

Please sign in to comment.