Skip to content

Update ci-cd.yml

Update ci-cd.yml #3

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- 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: Build and Push Docker image (latest)
run: |
docker build -t furkmak/legalapp:latest .
docker push furkmak/legalapp:latest
- name: Run FastAPI application and test Q&A
run: |
docker run -d -p 8000:8000 furkmak/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."
docker stop $(docker ps -q) # Stop the running container
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Check out the code
uses: actions/checkout@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: Pull Docker image (latest)
run: docker pull furkmak/legalapp:latest
- name: Tag and Push Docker image with version
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