fix: add Maven caching to CI workflow and update Redis configuration #16
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 | |
| env: | |
| POSTGRES_USER: ${{ secrets.POSTGRES_USER }} | |
| POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} | |
| POSTGRES_DB: ${{ secrets.POSTGRES_DB }} | |
| ports: | |
| - 5432:5432 | |
| options: >- | |
| --health-cmd "pg_isready" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| redis-test: | |
| image: redis:7.2 | |
| ports: | |
| - 6379:6379 | |
| options: >- | |
| --health-cmd "redis-cli ping" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - 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: Cache Maven | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.m2/repository | |
| key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-m2- | |
| - name: Build and Run Tests | |
| env: | |
| POSTGRES_USER: ${{ secrets.POSTGRES_USER }} | |
| POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} | |
| POSTGRES_DB: ${{ secrets.POSTGRES_DB }} | |
| POSTGRES_HOST_AUTH_METHOD: ${{ secrets.POSTGRES_HOST_AUTH_METHOD }} | |
| SPRING_REDIS_HOST: localhost | |
| SPRING_REDIS_PORT: 6379 | |
| AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| AWS_REGION: ${{ secrets.AWS_REGION }} | |
| AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }} | |
| AWS_BUCKET_ATESTADO: ${{ secrets.AWS_BUCKET_ATESTADO }} | |
| API_MAIL: ${{ secrets.API_EMAIL }} | |
| API_PASSWORD: ${{ secrets.API_PASSWORD }} | |
| KEY: ${{ secrets.KEY }} | |
| run: mvn clean package | |
| deploy: | |
| needs: build-and-test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - 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 stud-fit-api | |
| docker compose up -d |