ci: fix environment variables setup in GitHub Actions workflow #39
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 Test System | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| jobs: | |
| build-api: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Build API service | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: ./api | |
| push: false | |
| load: true | |
| tags: lucidata-api:latest | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| build-llm-engine: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Build LLM Engine service | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: ./llm_engine | |
| push: false | |
| load: true | |
| tags: lucidata-llm-engine:latest | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| build-query-runner: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Build Query Runner service | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: ./query_runner | |
| push: false | |
| load: true | |
| tags: lucidata-query-runner:latest | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| system-test: | |
| needs: [build-api, build-llm-engine, build-query-runner] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| # Save and load images from the build jobs | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| # Download the images built in the previous jobs | |
| - name: Download API image | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: ./api | |
| load: true | |
| tags: lucidata-api:latest | |
| cache-from: type=gha | |
| outputs: type=docker,dest=/tmp/api-image.tar | |
| - name: Download LLM Engine image | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: ./llm_engine | |
| load: true | |
| tags: lucidata-llm-engine:latest | |
| cache-from: type=gha | |
| outputs: type=docker,dest=/tmp/llm-engine-image.tar | |
| - name: Download Query Runner image | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: ./query_runner | |
| load: true | |
| tags: lucidata-query-runner:latest | |
| cache-from: type=gha | |
| outputs: type=docker,dest=/tmp/query-runner-image.tar | |
| - name: Load saved images | |
| run: | | |
| docker load < /tmp/api-image.tar | |
| docker load < /tmp/llm-engine-image.tar | |
| docker load < /tmp/query-runner-image.tar | |
| docker images | |
| - name: Create .env file | |
| run: | | |
| cat > .env << EOF | |
| # Rust config | |
| RUST_LOG=${{ vars.RUST_LOG }} | |
| # Database variables | |
| POSTGRES_DB=${{ vars.POSTGRES_DB }} | |
| POSTGRES_USER=${{ vars.POSTGRES_USER }} | |
| POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} | |
| DATABASE_URL="postgres://${{ vars.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@db:5432/${{ vars.POSTGRES_DB }}" | |
| # API Service variables | |
| API_PORT=${{ vars.API_PORT }} | |
| API_HOST=${{ vars.API_HOST }} | |
| API_URL=${{ vars.API_URL }} | |
| # LLM Engine variables | |
| LLM_API_KEY=${{ secrets.LLM_API_KEY }} | |
| LLM_MODEL=${{ vars.LLM_MODEL }} | |
| LLM_ENGINE_PORT=${{ vars.LLM_ENGINE_PORT }} | |
| EOF | |
| - name: Start database container only | |
| run: | | |
| docker compose up -d db | |
| # Wait for database to be ready | |
| echo "Waiting for database to be healthy..." | |
| sleep 30 | |
| - name: Start API container with logs | |
| run: | | |
| # Start API container in detached mode | |
| docker compose up -d api | |
| # Show logs as it starts | |
| docker compose logs api | |
| # Check container status | |
| docker ps -a | |
| - name: Debug - Check environment variables | |
| run: | | |
| echo "=== Docker Compose Configuration ===" | |
| # Use grep to filter out potential secrets | |
| docker compose config | grep -v -E '(PASSWORD|SECRET|TOKEN|KEY|PASS)' | |
| echo "=== API Container Environment ===" | |
| docker compose exec -T db env | grep -v -E '(PASSWORD|SECRET|TOKEN|KEY|PASS)' | sort | |
| - name: Debug - Database container logs | |
| run: | | |
| echo "=== Database Container Logs ===" | |
| docker compose logs db | |
| - name: Debug - Test database connection | |
| run: | | |
| # Use a temporary container to test connection | |
| docker run --rm --network lucidata_default postgres:15 \ | |
| pg_isready -h db -U lucidata | |
| echo "Connection result: $?" | |
| - name: Start services with docker compose | |
| run: docker compose up -d | |
| env: | |
| COMPOSE_DOCKER_CLI_BUILD: 0 | |
| DOCKER_BUILDKIT: 1 | |
| - name: Debug - API container logs | |
| run: | | |
| echo "=== API Container Logs ===" | |
| docker compose logs api | |
| - name: Wait for services to be healthy | |
| run: | | |
| # Give services some time to start up | |
| echo "Waiting for services to start..." | |
| sleep 60 | |
| # Check if API is healthy | |
| if curl -s http://localhost:8000/api/health > /dev/null; then | |
| echo "API is healthy" | |
| else | |
| echo "API health check failed" | |
| docker compose logs | |
| exit 1 | |
| fi | |
| echo "All services are running properly!" | |
| - name: Stop services | |
| if: always() # Ensures this step runs even if previous steps fail | |
| run: docker compose down |