diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..3d7f08da --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,78 @@ +name: Docker Build and Push + +on: + push: + branches: + - develop + paths: + - 'api/Dockerfile' + - 'bot/Dockerfile' + - 'docker-compose.yml' + - 'api/**' + - 'bot/**' + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + + - name: Build and push API image + uses: docker/build-push-action@v4 + with: + context: ./api + file: ./api/Dockerfile + push: true + tags: | + mzabiullah/onboarding-api:latest + mzabiullah/onboarding-api:${{ github.sha }} + + #bot + - name: Build and push Bot image + uses: docker/build-push-action@v4 + with: + context: ./bot + file: ./bot/Dockerfile + push: true + tags: | + mzabiullah/onboarding-bot:latest + mzabiullah/onboarding-bot:${{ github.sha }} + + + - name: Run docker-compose up + run: | + docker-compose up -d + - name: Wait for Postgres + run: | + echo "Waiting for postgres to be ready..." + for i in {1..20}; do + if docker exec postgres pg_isready -U myuser -d mydatabase; then + echo "Postgres is ready!" + break + fi + echo "Postgres is not ready yet, waiting..." + sleep 3 + done + + - name: Show docker-compose status + + run: docker-compose ps + + + - name: Tear down docker-compose + if: always() + run: docker-compose down + + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ca31aa02..885319a3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,10 +37,13 @@ jobs: - name: Install dependencies run: npm ci + - name: Install PostgreSQL client + run: sudo apt-get update && sudo apt-get install -y postgresql-client + - name: Wait for Postgres to be ready run: | - for i in {1..10}; do - pg_isready -h localhost -p 5432 && exit 0 + for i in {1..20}; do + pg_isready -h localhost -p 5433 && exit 0 echo "Waiting for postgres..." sleep 3 done