Fix Docker login and disk space management #7
This file contains hidden or 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, master ] | |
paths-ignore: | |
- '**/*.md' | |
- '.gitignore' | |
pull_request: | |
branches: [ main, master ] | |
env: | |
DOCKER_USERNAME: tuandung12092002 | |
SEARCH_SERVER_IMAGE: tuandung12092002/semantic-search-server | |
DEMO_APP_IMAGE: tuandung12092002/semantic-search-demo | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.9' | |
- name: Create environment files | |
run: | | |
echo "${{ secrets.OPENAI_API_KEY }}" > openai_api_key.txt | |
echo "${{ secrets.WEAVIATE_API_KEY }}" > weaviate_api_key.txt | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
pip install pytest | |
- name: Install package in development mode | |
run: | | |
pip install -e . | |
- name: Run tests | |
env: | |
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
WEAVIATE_API_KEY: ${{ secrets.WEAVIATE_API_KEY }} | |
run: | | |
pytest src/test_connection.py -v | |
build-and-push: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Free disk space | |
run: | | |
sudo rm -rf /usr/share/dotnet | |
sudo rm -rf /usr/local/lib/android | |
sudo rm -rf /opt/ghc | |
sudo rm -rf /opt/hostedtoolcache/CodeQL | |
sudo docker image prune -af | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
with: | |
buildkitd-flags: --debug | |
- name: Docker Login | |
run: | | |
echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u tuandung12092002 --password-stdin | |
- name: Build and push search server | |
run: | | |
docker buildx build \ | |
--platform linux/amd64 \ | |
--file ./docker/search_server.Dockerfile \ | |
--tag tuandung12092002/semantic-search-server:latest \ | |
--push \ | |
. | |
- name: Build and push demo app | |
run: | | |
docker buildx build \ | |
--platform linux/amd64 \ | |
--file ./docker/demo_app.Dockerfile \ | |
--tag tuandung12092002/semantic-search-demo:latest \ | |
--push \ | |
. | |
test-deployment: | |
needs: build-and-push | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Create environment files | |
run: | | |
mkdir -p secrets | |
echo "${{ secrets.OPENAI_API_KEY }}" > secrets/openai_api_key.txt | |
echo "${{ secrets.WEAVIATE_API_KEY }}" > secrets/weaviate_api_key.txt | |
- name: Docker Login | |
run: | | |
echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u tuandung12092002 --password-stdin | |
- name: Deploy application | |
env: | |
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
WEAVIATE_API_KEY: ${{ secrets.WEAVIATE_API_KEY }} | |
run: | | |
docker-compose -f docker/docker-compose.full.yml up -d | |
- name: Wait for services to start | |
run: | | |
sleep 30 | |
docker-compose -f docker/docker-compose.full.yml ps | |
- name: Test Search API | |
run: | | |
# Wait for the API to be ready | |
sleep 10 | |
curl -X POST http://localhost:8000/process-text \ | |
-H "Content-Type: application/json" \ | |
-d '{"text": "This is a test document for CI/CD pipeline."}' | |
curl -X POST http://localhost:8000/ask-question \ | |
-H "Content-Type: application/json" \ | |
-d '{"question": "What is semantic search?", "num_search_results": 3, "num_generations": 1}' | |
- name: Cleanup | |
if: always() | |
run: | | |
docker-compose -f docker/docker-compose.full.yml down | |
docker logout |