diff --git a/.containerignore b/.containerignore new file mode 120000 index 00000000..5a3c9b7d --- /dev/null +++ b/.containerignore @@ -0,0 +1 @@ +.dockerignore \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index aa525814..c23f5809 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -85,8 +85,8 @@ To ensure tests run in a clean state, use the `resetFixtures()` utility. - **What it does**: Reloads the database fixtures to their initial state. - **How it works**: - - **Locally**: Runs `docker compose exec php composer reload-fixture` in the sibling `../narvik-back` directory. - - **CI**: Runs the command inside the CI's docker environment. + - **Locally**: Runs `docker compose exec php composer reload-fixture` (or `podman compose` equivalent) in the sibling `../narvik-back` directory. + - **CI**: Runs the command inside the CI's container environment. **Configuration**: If your backend repository is not located at `../narvik-back`, set the `BACKEND_PATH` environment variable: diff --git a/Makefile b/Makefile index c523ed39..1da6fed7 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,9 @@ -# Executables (local) -DOCKER_COMP = docker compose +# Container runtime detection (supports docker and podman) +CONTAINER_RUNTIME ?= $(shell command -v podman >/dev/null 2>&1 && echo podman || echo docker) +CONTAINER_COMP = $(CONTAINER_RUNTIME) compose # Docker containers -NODE_CONT = $(DOCKER_COMP) exec front +NODE_CONT = $(CONTAINER_COMP) exec front # Container repo BUILD_REPO = benoitvignal/narvik-front @@ -10,7 +11,7 @@ BUILD_REPO = benoitvignal/narvik-front # Misc .DEFAULT_GOAL = help -## β€”β€” 🎡 🐳 The Docker Makefile 🐳 🎡 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” +## β€”β€” 🎡 🐳 The Narvik Makefile 🐳 🎡 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” help: ## Outputs this help screen @grep -E '(^[a-zA-Z0-9\./_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/' @@ -25,24 +26,24 @@ generate-local-ssl: ## Generate local SSL certificates using mkcert @chmod +x localhost.pem localhost-key.pem @echo "\033[32mCertificates generated and permissions set.\033[0m" -## β€”β€” Docker 🐳 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” +## β€”β€” Container 🐳 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” build-cloud-latest-only: ## Build using cloud and push it under latest tag (use for preprod testing) - @docker buildx build . --builder cloud-benoitvignal-narvik-cloud --pull --no-cache -t $(BUILD_REPO):latest --target run - @docker image push $(BUILD_REPO):latest + @$(CONTAINER_RUNTIME) buildx build . --builder cloud-benoitvignal-narvik-cloud --pull --no-cache -t $(BUILD_REPO):latest --target run + @$(CONTAINER_RUNTIME) image push $(BUILD_REPO):latest build-prod: - @docker build --pull --no-cache -t $(BUILD_REPO):latest -t $(BUILD_REPO):`cat package.json | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o | grep '^[0-9]\+\+' -o` -t $(BUILD_REPO):`cat package.json | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o | grep '^[0-9]\+\.[0-9]\+' -o` -t $(BUILD_REPO):`cat package.json | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o` --target run . + @$(CONTAINER_RUNTIME) build --pull --no-cache -t $(BUILD_REPO):latest -t $(BUILD_REPO):`cat package.json | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o | grep '^[0-9]\+\+' -o` -t $(BUILD_REPO):`cat package.json | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o | grep '^[0-9]\+\.[0-9]\+' -o` -t $(BUILD_REPO):`cat package.json | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o` --target run . build-cloud-prod: - @docker buildx build . --builder cloud-benoitvignal-narvik-cloud --pull --no-cache -t $(BUILD_REPO):latest -t $(BUILD_REPO):`cat package.json | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o | grep '^[0-9]\+\+' -o` -t $(BUILD_REPO):`cat package.json | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o | grep '^[0-9]\+\.[0-9]\+' -o` -t $(BUILD_REPO):`cat package.json | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o` --target run + @$(CONTAINER_RUNTIME) buildx build . --builder cloud-benoitvignal-narvik-cloud --pull --no-cache -t $(BUILD_REPO):latest -t $(BUILD_REPO):`cat package.json | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o | grep '^[0-9]\+\+' -o` -t $(BUILD_REPO):`cat package.json | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o | grep '^[0-9]\+\.[0-9]\+' -o` -t $(BUILD_REPO):`cat package.json | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o` --target run sh: ## Connect to the Node container @$(NODE_CONT) sh ## β€”β€” Cloudflared πŸ•ΈοΈ β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” cloudflared-tunnel: ## Expose local env through cloudflared tunnel (url must be set to host.docker.internal:3000 on cloudflare tunnel setting) - docker run --rm -it cloudflare/cloudflared:latest tunnel --no-autoupdate run --token $$CLOUDFLARED_TUNNEL + $(CONTAINER_RUNTIME) run --rm -it cloudflare/cloudflared:latest tunnel --no-autoupdate run --token $$CLOUDFLARED_TUNNEL cloudflared-tunnel-free: ## Expose local env through cloudflared tunnel (free version is limited to 200 in-flight request) - docker run --rm -it cloudflare/cloudflared:latest tunnel --no-autoupdate --url http://host.docker.internal:3000 + $(CONTAINER_RUNTIME) run --rm -it cloudflare/cloudflared:latest tunnel --no-autoupdate --url http://host.docker.internal:3000 diff --git a/tests/e2e/utils/db.ts b/tests/e2e/utils/db.ts index 2f4219d7..5d17d808 100644 --- a/tests/e2e/utils/db.ts +++ b/tests/e2e/utils/db.ts @@ -6,6 +6,22 @@ import fs from 'fs'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); +/** + * Detects the available container runtime (podman or docker). + * Supports override via CONTAINER_RUNTIME environment variable. + */ +const getContainerCompose = (): string => { + if (process.env.CONTAINER_RUNTIME) { + return `${process.env.CONTAINER_RUNTIME} compose`; + } + try { + execSync('podman --version', { stdio: 'ignore' }); + return 'podman compose'; + } catch { + return 'docker compose'; + } +}; + /** * Resets the database fixtures to the initial state. * Uses the backend's 'make reload-fixture' command. @@ -13,13 +29,15 @@ const __dirname = path.dirname(__filename); * Assumes the backend repo is located at '../narvik-back' relative to this project root. */ export const resetFixtures = () => { + const compose = getContainerCompose(); + // Check if running in CI if (process.env.CI) { try { console.log('Resetting fixtures in CI environment...'); // In CI, we use the specific e2e compose file and 'backend' service // We use -T because there is no TTY in CI - execSync('docker compose -f docker-compose.e2e.yml exec -T backend composer reload-fixture', { + execSync(`${compose} -f docker-compose.e2e.yml exec -T backend composer reload-fixture`, { stdio: 'inherit', timeout: 60000 }); @@ -46,10 +64,10 @@ export const resetFixtures = () => { } try { - console.log(`Resetting fixtures via backend docker compose (path: ${backendPath})...`); - // Use docker compose directly for consistency, pointing to local backend setup + console.log(`Resetting fixtures via ${compose} (path: ${backendPath})...`); + // Use container compose directly for consistency, pointing to local backend setup // Assuming standard 'php' service name in local dev - execSync('docker compose exec -T php composer reload-fixture', { + execSync(`${compose} exec -T php composer reload-fixture`, { cwd: backendPath, stdio: 'inherit', timeout: 60000