Skip to content

workflow test1

workflow test1 #4

Workflow file for this run

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: Create Docker network
run: docker network create ci_network || echo "Network ci_network already exists"
- name: Connect Postgres service to network
run: docker network connect ci_network postgres || echo "Postgres already connected"
- name: Run backup script test
run: |
mkdir -p ./backups
docker run --rm \
--network ci_network \
-e DB_HOST=postgres \
-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