pipeline test #3
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: BICA Backup CI/CD | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| env: | |
| IMAGE_NAME: bica-backup | |
| TAG: test | |
| jobs: | |
| build-and-test: | |
| name: 🔧 Build & Validate Backup | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_USER: testuser | |
| POSTGRES_PASSWORD: testpass | |
| POSTGRES_DB: testdb | |
| ports: | |
| - 5432:5432 | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| - name: Setup Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build backup container | |
| run: docker build -t $IMAGE_NAME:$TAG . | |
| - name: Run backup script test | |
| run: | | |
| mkdir -p ./backups | |
| docker run --rm \ | |
| -e DB_HOST=host.docker.internal \ | |
| -e DB_PORT=5432 \ | |
| -e DB_USER=testuser \ | |
| -e DB_PASSWORD=testpass \ | |
| -e DB_NAME=testdb \ | |
| -e BACKUP_DIR=/mnt/backups \ | |
| -e RETENTION_DAYS=7 \ | |
| -e ENCRYPT=false \ | |
| -v $(pwd)/backups:/mnt/backups \ | |
| $IMAGE_NAME:$TAG /backup.sh | |
| - name: Check backup created | |
| run: | | |
| ls -lh ./backups | |
| test -f ./backups/*.tar.gz || (echo "❌ Backup não foi criado!" && exit 1) | |
| docker-publish: | |
| name: Push to Docker Hub | |
| runs-on: ubuntu-latest | |
| needs: build-and-test | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Docker Login | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: 🚢 Push image | |
| run: | | |
| docker tag $IMAGE_NAME:$TAG ${{ secrets.DOCKER_USERNAME }}/$IMAGE_NAME:latest | |
| docker push ${{ secrets.DOCKER_USERNAME }}/$IMAGE_NAME:latest | |