fix: ajustes nos scripts para verificar se os serviços estão disponíveis #5
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: | |
| - prod-aws | |
| jobs: | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres-test: | |
| image: postgres:14-alpine | |
| env: | |
| POSTGRES_USER: testuser | |
| POSTGRES_PASSWORD: testpassword | |
| POSTGRES_DB: testdb | |
| ports: | |
| - 5432:5432 | |
| options: >- | |
| --health-cmd "pg_isready" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| redis-test: | |
| image: redis:6-alpine | |
| ports: | |
| - 6379:6379 | |
| options: >- | |
| --health-cmd "redis-cli ping" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| steps: | |
| - name: Wait for services | |
| run: | | |
| timeout 30 bash -c 'until nc -z localhost 5432; do sleep 1; done' | |
| timeout 30 bash -c 'until nc -z localhost 6379; do sleep 1; done' | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: | |
| Run tests | |
| env: | |
| SPRING_DATASOURCE_URL: jdbc:postgresql://localhost:5432/testdb | |
| SPRING_DATASOURCE_USERNAME: testuser | |
| SPRING_DATASOURCE_PASSWORD: testpassword | |
| SPRING_REDIS_HOST: localhost | |
| SPRING_REDIS_PORT: 6379 | |
| run: mvn test | |
| - name: Build with Maven | |
| env: | |
| SPRING_DATASOURCE_URL: jdbc:postgresql://localhost:5432/testdb | |
| SPRING_DATASOURCE_USERNAME: testuser | |
| SPRING_DATASOURCE_PASSWORD: testpassword | |
| SPRING_REDIS_HOST: localhost | |
| SPRING_REDIS_PORT: 6379 | |
| run: mvn clean package | |
| deploy: | |
| needs: build-and-test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Deploy to EC2 | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script: | | |
| cd ~/StudFit-API | |
| git pull origin prod-aws | |
| docker-compose build app | |
| docker-compose up -d |