ci: test docker container #7
Workflow file for this run
  
    
      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: Tests | |
| on: | |
| push: | |
| pull_request: | |
| #on: | |
| # push: | |
| # branches: | |
| # - main | |
| # pull_request: | |
| # branches: | |
| # - main | |
| env: | |
| IMAGE_NAME: mysql-bkup | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| services: | |
| mysql8: | |
| image: mysql:8 | |
| env: | |
| MYSQL_ROOT_PASSWORD: root | |
| MYSQL_DATABASE: testdb | |
| MYSQL_USER: user | |
| MYSQL_PASSWORD: password | |
| ports: | |
| - 3306:3306 | |
| options: >- | |
| --health-cmd="mysqladmin ping -h 127.0.0.1 -uuser -ppassword" | |
| --health-interval=10s | |
| --health-timeout=5s | |
| --health-retries=5 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # Build the Docker image | |
| - name: Build Docker Image | |
| run: | | |
| docker buildx build -t ${{ env.IMAGE_NAME }}:latest --load . | |
| - name: Create docker network | |
| run: | | |
| docker network create web | |
| - name: Test restore | |
| run: | | |
| docker run -d --name ${{ env.IMAGE_NAME }} \ | |
| -v ./migrations:/backup/ \ | |
| --network web \ | |
| -e DB_HOST=mysql8 \ | |
| -e DB_USERNAME=user \ | |
| -e DB_PASSWORD=password \ | |
| -e DB_NAME=testdb \ | |
| ${{ env.IMAGE_NAME }}:latest restore -f init.sql | |
| echo "Database restore completed" | |
| - name: Test backup | |
| run: | | |
| docker run -d --name ${{ env.IMAGE_NAME }} \ | |
| -v ./migrations:/backup/ \ | |
| --network web \ | |
| -e DB_HOST=mysql8 \ | |
| -e DB_USERNAME=user \ | |
| -e DB_PASSWORD=password \ | |
| -e DB_NAME=testdb \ | |
| ${{ env.IMAGE_NAME }}:latest backup | |
| echo "Database backup completed" | |
| # Cleanup: Stop and remove containers | |
| - name: Clean up | |
| run: | | |
| docker stop ${{ env.IMAGE_NAME }} || true | |
| docker rm ${{ env.IMAGE_NAME }} || true | |
| docker network rm web || true |