chore #7
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: CI - Testcontainers | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| jobs: | |
| # temos o docker, mas os testes rodam foram de um container | |
| test-without-docker: | |
| name: Tests - Running Outside Container | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "24" | |
| cache: "npm" | |
| cache-dependency-path: "./src/16-docker-outside-of-docker/package.json" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Install dependencies | |
| working-directory: ./src/16-docker-outside-of-docker | |
| run: npm install | |
| - name: Run tests - Container reuse without compose (outside container) | |
| working-directory: ./src/16-docker-outside-of-docker | |
| env: | |
| TESTCONTAINERS_RYUK_DISABLED: true | |
| run: npm run test:without-compose | |
| - name: Run tests - Container reuse with compose (outside container) | |
| working-directory: ./src/16-docker-outside-of-docker | |
| env: | |
| TESTCONTAINERS_RYUK_DISABLED: true | |
| run: npm run test:with-compose | |
| test-inside-docker: | |
| name: Tests - Running Inside Container (Docker-in-Docker) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| # - name: Set up Docker Buildx | |
| # uses: docker/setup-buildx-action@v3 | |
| - name: Create Docker config file | |
| run: | | |
| mkdir -p ~/.docker | |
| echo '${{ secrets.DOCKER_CONFIG_JSON }}' > ~/.docker/config-read.json | |
| - name: Get user and docker group IDs | |
| id: get-ids | |
| run: | | |
| echo "user_id=$(id -u)" >> $GITHUB_OUTPUT | |
| echo "docker_gid=$(getent group docker | cut -d: -f3)" >> $GITHUB_OUTPUT | |
| echo "Current user ID: $(id -u)" | |
| echo "Docker group ID: $(getent group docker | cut -d: -f3)" | |
| # Setup Testcontainers Cloud Client right before your Testcontainers tests | |
| - name: Setup Testcontainers Cloud Client | |
| uses: atomicjar/testcontainers-cloud-setup-action@v1 | |
| with: | |
| token: ${{ secrets.TC_CLOUD_TOKEN }} | |
| - name: Configure Testcontainers for Docker network | |
| run: | | |
| echo "=== Testcontainers configuration files ===" | |
| if [ -f ~/.testcontainers.properties ]; then | |
| echo "=== ~/.testcontainers.properties ===" | |
| cat ~/.testcontainers.properties | |
| echo "✅ File will be mounted as-is (network_mode: host allows direct localhost access)" | |
| else | |
| echo "~/.testcontainers.properties not found" | |
| fi | |
| echo "=== Updating /etc/hosts ===" | |
| echo "127.0.0.1 host.docker.internal" | sudo tee -a /etc/hosts | |
| cat /etc/hosts | |
| - name: Start test container with docker compose | |
| working-directory: ./src/16-docker-outside-of-docker | |
| env: | |
| USER_ID: ${{ steps.get-ids.outputs.user_id }} | |
| DOCKER_GROUP_ID: ${{ steps.get-ids.outputs.docker_gid }} | |
| run: docker compose up -d | |
| - name: Test connectivity from inside container | |
| working-directory: ./src/16-docker-outside-of-docker | |
| run: | | |
| echo "=== Testing Testcontainers Cloud Agent connectivity from inside container ===" | |
| # Extrai a porta | |
| TCC_PORT=$(grep "tc.host" ~/.testcontainers.properties | sed 's/.*://g') | |
| echo "Testcontainers Cloud Agent port: $TCC_PORT" | |
| echo "Checking /etc/hosts inside container" | |
| docker compose exec -T tests cat /etc/hosts | |
| echo "Checking .testcontainers.properties inside container" | |
| docker compose exec -T tests cat /home/node/.testcontainers.properties | |
| echo "Trying to resolve host.docker.internal inside container" | |
| docker compose exec -T tests getent hosts host.docker.internal || echo "Failed to resolve" | |
| echo "Checking network configuration" | |
| docker compose exec -T tests ip route || echo "ip route not available, trying route -n" | |
| docker compose exec -T tests route -n || echo "route command not available" | |
| echo "Testing from container with host.docker.internal:$TCC_PORT" | |
| docker compose exec -T tests timeout 5 bash -c "cat < /dev/null > /dev/tcp/host.docker.internal/$TCC_PORT" 2>&1 && echo "✅ host.docker.internal:$TCC_PORT is accessible from container" || echo "❌ host.docker.internal:$TCC_PORT is NOT accessible from container" | |
| - name: Install dependencies inside container | |
| working-directory: ./src/16-docker-outside-of-docker | |
| run: docker compose exec -T tests npm install | |
| - name: Run tests - Container reuse without compose (inside container) | |
| working-directory: ./src/16-docker-outside-of-docker | |
| run: | | |
| docker compose exec -T \ | |
| -e TESTCONTAINERS_RYUK_DISABLED=true \ | |
| -e DEBUG=testcontainers* \ | |
| tests npm run test:without-compose | |
| - name: Run tests - Container reuse with compose (inside container) | |
| working-directory: ./src/16-docker-outside-of-docker | |
| run: | | |
| docker compose exec -T \ | |
| -e TESTCONTAINERS_RYUK_DISABLED=true \ | |
| tests npm run test:with-compose | |
| #Optional | |
| - name: Terminate Testcontainers Cloud Client active sessions | |
| uses: atomicjar/testcontainers-cloud-setup-action@v1 | |
| with: | |
| action: terminate |