testing endpoint #47
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: Deploy Scraper and Index to Elastic Cloud | |
| on: | |
| push: | |
| branches: | |
| - main | |
| # schedule: | |
| # - cron: '*/10 * * * *' | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10' | |
| - name: Install dependencies | |
| run: | | |
| pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install prefect | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build Docker image | |
| run: docker build -t ${{ secrets.DOCKER_USERNAME }}/scraping-image:latest . | |
| - name: Push Docker image | |
| run: docker push ${{ secrets.DOCKER_USERNAME }}/scraping-image:latest | |
| - name: Test Elastic Cloud connection | |
| env: | |
| ELASTIC_URL: ${{ secrets.ELASTIC_URL }} | |
| ELASTIC_API_KEY: ${{ secrets.ELASTIC_API_KEY }} | |
| run: | | |
| HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \ | |
| -H "Authorization: ApiKey $ELASTIC_API_KEY" \ | |
| "$ELASTIC_URL") | |
| echo "HTTP status: $HTTP_CODE" | |
| if [ "$HTTP_CODE" -ne 200 ]; then | |
| echo "Elastic Cloud connection failed!" | |
| exit 1 | |
| fi | |
| - name: Index events to Elastic Cloud | |
| env: | |
| CLOUD_ID: ${{ secrets.CLOUD_ID }} | |
| ELASTIC_PASSWORD: ${{ secrets.ELASTIC_PASSWORD }} | |
| run: python elastic_script.py | |
| - name: Run FastAPI and test endpoint | |
| env: | |
| CLOUD_ID: ${{ secrets.CLOUD_ID }} | |
| ELASTIC_PASSWORD: ${{ secrets.ELASTIC_PASSWORD }} | |
| run: | | |
| uvicorn main:app --host 127.0.0.1 --port 8000 & | |
| sleep 10 | |
| curl http://127.0.0.1:8000/events | |