This repository was archived by the owner on Apr 16, 2026. It is now read-only.
Implements rate limiting for API protection #13
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 to EC2 | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ secrets.DOCKER_USERNAME }}/api-onibusbh:latest | |
| - name: Copy config to EC2 | |
| uses: appleboy/scp-action@master | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| source: "filebeat.prod.yml" | |
| target: "/home/${{ secrets.EC2_USERNAME }}/api-onibusbh/" | |
| - name: Deploy to EC2 | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: | | |
| WORKDIR="/home/${{ secrets.EC2_USERNAME }}/api-onibusbh" | |
| docker stop api-onibusbh filebeat-prod || true | |
| docker rm api-onibusbh filebeat-prod || true | |
| docker pull ${{ secrets.DOCKER_USERNAME }}/api-onibusbh:latest | |
| docker run -d \ | |
| --name api-onibusbh \ | |
| -p 8080:8080 \ | |
| -e SPRING_PROFILES_ACTIVE=prod \ | |
| -e MONGO_HOST=${{ secrets.MONGO_HOST }} \ | |
| -e MONGO_PORT=${{ secrets.MONGO_PORT }} \ | |
| -e MONGO_DATABASE=${{ secrets.MONGO_DATABASE }} \ | |
| -e MONGO_USERNAME=${{ secrets.MONGO_USERNAME }} \ | |
| -e MONGO_PASSWORD=${{ secrets.MONGO_PASSWORD }} \ | |
| -e ELASTIC_HOST=${{ secrets.ELASTIC_HOST }} \ | |
| --restart unless-stopped \ | |
| ${{ secrets.DOCKER_USERNAME }}/api-onibusbh:latest | |
| docker run -d \ | |
| --name filebeat-prod \ | |
| --user root \ | |
| --restart unless-stopped \ | |
| -e ELASTIC_HOST=${{ secrets.ELASTIC_HOST }} \ | |
| -v /var/lib/docker/containers:/var/lib/docker/containers:ro \ | |
| -v /var/run/docker.sock:/var/run/docker.sock:ro \ | |
| -v $WORKDIR/filebeat.prod.yml:/usr/share/filebeat/filebeat.yml:ro \ | |
| docker.elastic.co/beats/filebeat:8.15.0 \ | |
| --strict.perms=false |