Add workflows CI/CD #1
This file contains 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: Docker Compose CI | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build-and-test: | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] # Chạy trên Ubuntu, macOS, Windows | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Docker | |
uses: docker/setup-buildx-action@v2 | |
- name: Validate Docker Compose file | |
run: docker-compose config | |
- name: Pull and build services | |
run: | | |
docker-compose pull | |
docker-compose build | |
- name: Run services | |
run: docker-compose up -d | |
- name: Check if WordPress is running | |
run: | | |
curl -f http://localhost:8080 || (echo "WordPress is not running!" && exit 1) | |
- name: Check database connection | |
run: | | |
docker exec $(docker ps -qf "name=database") mysqladmin ping -h localhost -u"${MYSQL_USER}" -p"${MYSQL_PASSWORD}" --silent || exit 1 | |
- name: List running containers (debugging) | |
run: docker-compose ps | |
- name: Clean up services | |
if: always() | |
run: docker-compose down |