Skip to content

Commit 3ed3924

Browse files
committed
Add Podman support to Testcontainers spike
Testcontainers Go automatically works with Podman without special configuration. Updated spike document to include: - Podman benefits (rootless, daemonless, better security) - Automatic detection (works transparently) - Configuration options (CONTAINER_HOST env var) - Podman-specific considerations for TiDB (use manual multi-container instead of Compose module) - Testing Podman compatibility Podman is a drop-in replacement for Docker, so tests should work without code changes when Podman is available.
1 parent 81e417a commit 3ed3924

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

TESTCONTAINERS_SPIKE.md

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Makefile target → Docker run → Wait loop → Set env vars → Run tests →
3333
6. **Better Error Messages**: Container logs automatically captured on failure
3434
7. **Type Safety**: Compile-time checks instead of runtime shell errors
3535
8. **Simpler CI/CD**: Just run `go test` - no Makefile coordination needed
36+
9. **Podman Support**: Works with Podman without special configuration (daemonless, rootless)
3637

3738
## Proof of Concept
3839

@@ -426,7 +427,7 @@ func TestAccDatabase_MultipleVersions(t *testing.T) {
426427

427428
1. **TiDB Complexity**: Multi-container setup still complex, but better than shell scripts
428429
2. **Learning Curve**: Team needs to learn Testcontainers API
429-
3. **Docker Dependency**: Still requires Docker (same as current approach)
430+
3. **Container Runtime Dependency**: Requires Docker or Podman (same as current approach)
430431
4. **Migration Effort**: Need to convert all tests
431432

432433
### Potential Issues
@@ -440,6 +441,38 @@ func TestAccDatabase_MultipleVersions(t *testing.T) {
440441
3. **Network Issues**: Docker networking complexity
441442
- **Mitigation**: Testcontainers handles this automatically
442443

444+
## Podman Support
445+
446+
Testcontainers Go automatically detects and works with Podman when Docker is not available or when `TESTCONTAINERS_RYUK_DISABLED=true` is set. Podman support is transparent - no code changes needed.
447+
448+
### Podman Benefits
449+
450+
1. **Rootless**: Can run without root privileges
451+
2. **Daemonless**: No background daemon required
452+
3. **Drop-in Replacement**: API-compatible with Docker
453+
4. **Better Security**: Uses user namespaces
454+
455+
### Podman Configuration
456+
457+
Testcontainers will automatically use Podman if:
458+
- Docker is not available, OR
459+
- `CONTAINER_HOST` environment variable points to Podman socket
460+
461+
Example:
462+
```bash
463+
# Use Podman explicitly
464+
export CONTAINER_HOST=unix://$HOME/.local/share/containers/podman/machine/podman-machine-default/podman.sock
465+
466+
# Or let Testcontainers auto-detect
467+
# (it will try Docker first, then Podman)
468+
```
469+
470+
### Podman Considerations
471+
472+
- **Socket Path**: Podman socket location varies by installation
473+
- **Rootless Mode**: May have different networking behavior
474+
- **Compose Support**: Docker Compose module may not work with Podman (use manual multi-container setup for TiDB)
475+
443476
## Implementation Plan
444477

445478
### Step 1: Add Dependencies
@@ -450,6 +483,15 @@ go get github.com/testcontainers/testcontainers-go/modules/mysql
450483
go get github.com/testcontainers/testcontainers-go/modules/compose
451484
```
452485

486+
### Step 1.5: Verify Podman Support (Optional)
487+
488+
Test Podman compatibility:
489+
```bash
490+
# With Podman installed
491+
export CONTAINER_HOST=unix://$HOME/.local/share/containers/podman/machine/podman-machine-default/podman.sock
492+
go test -tags=spike ./mysql/... -run ExampleTestAccDatabase_WithTestcontainers
493+
```
494+
453495
### Step 2: Create Helper Package
454496

455497
Create `mysql/testcontainers_helper.go` with:
@@ -499,9 +541,43 @@ Convert tests file-by-file:
499541
4. **Decide on migration strategy** (gradual vs. all-at-once)
500542
5. **Create migration tickets** if approved
501543

544+
## Podman-Specific Implementation Notes
545+
546+
### TiDB with Podman
547+
548+
Since Docker Compose may not work with Podman, use manual multi-container setup:
549+
550+
```go
551+
func startTiDBClusterPodman(ctx context.Context, t *testing.T, version string) *MySQLTestContainer {
552+
// Use GenericContainer instead of Compose module
553+
// This works with both Docker and Podman
554+
return startTiDBClusterManual(ctx, t, version)
555+
}
556+
```
557+
558+
### Testing Podman Compatibility
559+
560+
Add a build tag to test Podman specifically:
561+
562+
```go
563+
// +build podman
564+
565+
// Test with Podman
566+
func TestPodmanCompatibility(t *testing.T) {
567+
// Verify Testcontainers detects Podman
568+
// Run subset of tests to verify compatibility
569+
}
570+
```
571+
572+
Run with:
573+
```bash
574+
go test -tags=podman ./mysql/...
575+
```
576+
502577
## References
503578

504579
- [Testcontainers Go Documentation](https://golang.testcontainers.org/)
505580
- [Testcontainers MySQL Module](https://golang.testcontainers.org/modules/mysql/)
506581
- [Testcontainers Compose Module](https://golang.testcontainers.org/modules/compose/)
582+
- [Testcontainers Podman Support](https://golang.testcontainers.org/features/container_daemons/)
507583
- [Example: Terraform Provider Testing](https://github.com/testcontainers/testcontainers-go/tree/main/examples)

0 commit comments

Comments
 (0)