Update Docker login configuration #4
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: Build and Push Docker Images | |
on: | |
push: | |
branches: [ main, master ] | |
paths-ignore: | |
- '**.md' | |
- '.gitignore' | |
pull_request: | |
branches: [ main, master ] | |
paths-ignore: | |
- '**.md' | |
- '.gitignore' | |
workflow_dispatch: # Enable manual triggers | |
env: | |
DOCKER_USERNAME: tuandung12092002 | |
SEARCH_SERVER_IMAGE: tuandung12092002/semantic-search-server | |
DEMO_APP_IMAGE: tuandung12092002/semantic-search-demo | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to DockerHub | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ env.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Extract metadata for Search Server | |
id: meta-search-server | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.SEARCH_SERVER_IMAGE }} | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=sha,format=short | |
latest | |
- name: Extract metadata for Demo App | |
id: meta-demo-app | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.DEMO_APP_IMAGE }} | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=sha,format=short | |
latest | |
- name: Build and Push Search Server Image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./docker/search_server.Dockerfile | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta-search-server.outputs.tags }} | |
labels: ${{ steps.meta-search-server.outputs.labels }} | |
cache-from: type=registry,ref=${{ env.SEARCH_SERVER_IMAGE }}:buildcache | |
cache-to: ${{ github.event_name != 'pull_request' && format('type=registry,ref={0}:buildcache,mode=max', env.SEARCH_SERVER_IMAGE) || '' }} | |
- name: Build and Push Demo App Image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./docker/demo_app.Dockerfile | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta-demo-app.outputs.tags }} | |
labels: ${{ steps.meta-demo-app.outputs.labels }} | |
cache-from: type=registry,ref=${{ env.DEMO_APP_IMAGE }}:buildcache | |
cache-to: ${{ github.event_name != 'pull_request' && format('type=registry,ref={0}:buildcache,mode=max', env.DEMO_APP_IMAGE) || '' }} | |
test-deployment: | |
needs: build-and-push | |
if: github.event_name != 'pull_request' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Create OpenAI API key file | |
run: | | |
echo "${{ secrets.OPENAI_API_KEY }}" > openai_api_key.txt | |
echo "dummy-key" > weaviate_api_key.txt | |
- name: Deploy with Docker Compose for Testing | |
run: | | |
docker-compose -f docker/docker-compose.full.yml up -d | |
- name: Wait for Services to Start | |
run: | | |
# Wait for search server to be healthy | |
timeout=120 | |
counter=0 | |
echo "Waiting for services to be ready..." | |
while ! curl --silent --fail http://localhost:8000/health; do | |
if [ $counter -eq $timeout ]; then | |
echo "Timed out waiting for health check" | |
exit 1 | |
fi | |
echo "Services not ready yet. Waiting..." | |
sleep 5 | |
counter=$((counter + 5)) | |
done | |
echo "Services are ready!" | |
- name: Test Search API | |
run: | | |
# Process a test document | |
curl -X POST http://localhost:8000/process-text \ | |
-H "Content-Type: application/json" \ | |
-d '{"text":"This is a test document for CI/CD pipeline verification."}' | |
# Query the API | |
response=$(curl -s -X POST http://localhost:8000/ask-question \ | |
-H "Content-Type: application/json" \ | |
-d '{"question":"What is this document about?", "num_search_results":1, "num_generations":1}') | |
echo "API Response: $response" | |
# Check if the response contains expected keywords | |
if echo "$response" | grep -q "CI/CD"; then | |
echo "Test passed: Response contains expected content" | |
else | |
echo "Test failed: Response does not contain expected content" | |
exit 1 | |
fi | |
- name: Cleanup Resources | |
run: | | |
docker-compose -f docker/docker-compose.full.yml down |