Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .containerignore
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 12 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# 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

# 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/'

Expand All @@ -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
26 changes: 22 additions & 4 deletions tests/e2e/utils/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,38 @@ 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.
*
* 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
});
Expand All @@ -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
Expand Down
Loading