|
| 1 | +name: Deploy Scraper to Prefect |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + deploy: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + services: |
| 12 | + elasticsearch: |
| 13 | + image: docker.elastic.co/elasticsearch/elasticsearch:8.17.3 |
| 14 | + ports: |
| 15 | + - 9200:9200 |
| 16 | + env: |
| 17 | + discovery.type: single-node |
| 18 | + ELASTIC_PASSWORD: ${{ secrets.ELASTIC_PASSWORD }} |
| 19 | + xpack.security.enabled: "false" |
| 20 | + options: >- |
| 21 | + --name es01 |
| 22 | + --health-cmd="curl --silent --fail localhost:9200/_cluster/health || exit 1" |
| 23 | + --health-interval=10s |
| 24 | + --health-timeout=5s |
| 25 | + --health-retries=10 |
| 26 | +
|
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v3 |
| 29 | + |
| 30 | + - name: Set up Python |
| 31 | + uses: actions/setup-python@v4 |
| 32 | + with: |
| 33 | + python-version: '3.10' |
| 34 | + |
| 35 | + - name: Install dependencies |
| 36 | + run: | |
| 37 | + pip install --upgrade pip |
| 38 | + pip install -r requirements.txt |
| 39 | +
|
| 40 | + - name: Wait for Elasticsearch to be ready |
| 41 | + run: | |
| 42 | + echo "Waiting for Elasticsearch..." |
| 43 | + until curl -s -u elastic:${{ secrets.ELASTIC_PASSWORD }} http://localhost:9200 >/dev/null; do |
| 44 | + sleep 5 |
| 45 | + done |
| 46 | + echo "Elasticsearch is up!" |
| 47 | +
|
| 48 | + - name: Log in to Docker Hub |
| 49 | + uses: docker/login-action@v2 |
| 50 | + with: |
| 51 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 52 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 53 | + |
| 54 | + - name: Build Docker image |
| 55 | + run: docker build -t ${{ secrets.DOCKER_USERNAME }}/scraping-image:latest . |
| 56 | + |
| 57 | + - name: Push Docker image |
| 58 | + run: docker push ${{ secrets.DOCKER_USERNAME }}/scraping-image:latest |
| 59 | + |
| 60 | + - name: Deploy flow to Prefect |
| 61 | + env: |
| 62 | + PREFECT_API_KEY: ${{ secrets.PREFECT_API_KEY }} |
| 63 | + PREFECT_API_URL: https://api.prefect.cloud/api/accounts/${{ secrets.PREFECT_ACCOUNT }}/workspaces/${{ secrets.PREFECT_WORKSPACE }} |
| 64 | + run: prefect deploy --prefect-file deployment.yaml |
| 65 | + |
| 66 | + - name: Elastic indexing |
| 67 | + run: | |
| 68 | + python elastic_script.py |
| 69 | + echo "Events indexed to Elasticsearch successfully." |
| 70 | + - name: Wait for indexing |
| 71 | + run: | |
| 72 | + echo "Waiting for events to be indexed..." |
| 73 | + sleep 100 # Adjust the sleep time as necessary |
| 74 | + |
| 75 | + - name: All indexed |
| 76 | + run: | |
| 77 | + echo "All events have been indexed to Elasticsearch." |
| 78 | + curl -X GET "localhost:9200/events_index/_search?pretty" -u elastic:${{ secrets.ELASTIC_PASSWORD }} -H 'Content-Type: application/json' -d' |
| 79 | + { |
| 80 | + "query": { |
| 81 | + "match_all": {} |
| 82 | + }, |
| 83 | + "size": 10 |
| 84 | + }' |
| 85 | + - name: Run FastAPI |
| 86 | + run: | |
| 87 | + uvicorn main:app --host 0.0.0.0 --port 8000 & |
| 88 | + sleep 5 # wait a few seconds for server to start |
| 89 | +
|
| 90 | + - name: Test streaming endpoint |
| 91 | + run: | |
| 92 | + curl -v http://localhost:8000/events |
| 93 | + echo "Streaming endpoint tested successfully." |
| 94 | + |
0 commit comments