Skip to content

Conversation

f0ssel
Copy link
Collaborator

@f0ssel f0ssel commented Sep 10, 2025

Overview

Refactors the project to use the standard Go project layout by moving the main executable to cmd/jail/ and updating all build tooling to work with the new structure.

Changes Made

Project Structure

  • Moved main.gocmd/jail/main.go (standard Go layout)
  • Updated .gitignore to remove jail and jail.exe entries
  • Removed empty jail.go file that was causing test failures

Build Tooling Updates

  • Makefile: Updated all build targets to use ./cmd/jail
  • Build script: Updated scripts/build.sh for new structure
  • GitHub Actions: Updated workflows to build from ./cmd/jail
  • Documentation: Updated README with correct build commands

Benefits

  • Standard Go layout - Follows Go community conventions
  • Library ready - Root package ready for future library code
  • Clean separation - Command code separate from library space
  • Future extensibility - Easy to add more commands in cmd/

Compatibility

  • Same user experience - All commands work identically
  • Same build outputs - Binaries created in same locations
  • Same workflows - GitHub Actions work without changes
  • Version injection - Still works with -X main.version=
  • Tests pass - All tests now execute successfully

Testing

  • make build - Creates binary correctly
  • ./scripts/build.sh - All 4 platforms build successfully
  • go test ./... - All tests pass without failures
  • ✅ Cross-compilation - Works for all target platforms
  • ✅ Version injection - Working (e.g., dev-9829aba)

This refactor modernizes the project structure while maintaining full backward compatibility for all build processes and workflows.


Commit History Notes

This PR includes some reverted commits where I initially added a jail package interface but then reverted those changes per feedback. The final state only includes the structural refactor (cmd/jail) and build tooling updates, keeping the original CLI implementation intact.

f0ssel and others added 2 commits September 9, 2025 20:53
Updated all build tooling to work with the moved main.go:

## Files Updated

### Makefile
- Updated build target: ./cmd/jail instead of .
- Updated build-all target: all cross-platform builds use ./cmd/jail
- Version injection still works with -X main.version=

### Build Script (scripts/build.sh)
- Updated to build from ./cmd/jail directory
- All platform builds now use correct path

### GitHub Actions Workflows
- build.yml: Updated build command to use ./cmd/jail
- release.yml: Updated build command to use ./cmd/jail
- Version injection path remains main.version (package didn't change)

### README.md
- Updated build examples: go build -o jail ./cmd/jail
- Updated development section manual commands
- Updated Quick Start build example

## Tested
- ✅ make build works correctly
- ✅ ./scripts/build.sh creates all 4 binaries
- ✅ Version injection works (dev-dd5ba1d)
- ✅ Cross-platform builds succeed
- ✅ Tests run (though some may have existing issues)

## Compatibility
All existing workflows and build processes continue to work
with the new cmd/jail project structure. The change is fully
backward compatible from a user perspective.

Co-authored-by: f0ssel <[email protected]>
@blink-so blink-so bot changed the title better error handling refactor: move main.go to cmd/jail for standard Go project layout Sep 10, 2025
Moved jail logic from CLI into a reusable library interface:

- jail.Config struct with all configuration options
- jail.Jail struct representing a jail instance
- jail.New() constructor
- jail.Start(), Execute(), Run(), Stop() methods

Simplified CLI to use the jail package as a thin wrapper.
Maintained full CLI compatibility while enabling library usage.

Co-authored-by: f0ssel <[email protected]>
@blink-so blink-so bot changed the title refactor: move main.go to cmd/jail for standard Go project layout refactor: move main.go to cmd/jail and create library interface Sep 10, 2025
blink-so bot and others added 3 commits September 10, 2025 01:16
Simplified the jail package interface by removing the Run() method:

## Changes
- Removed jail.Run() convenience method from jail.go
- Updated CLI to use explicit Start() -> Execute() -> Stop() pattern
- Added proper defer j.Stop() for cleanup in CLI

## Rationale
Keeping the interface explicit and minimal:
- Start() - Initialize the jail environment
- Execute() - Run command in jail (requires Start() first)
- Stop() - Cleanup resources

This makes the lifecycle clear and gives users full control over
when initialization and cleanup happen.

## Usage Pattern

Co-authored-by: f0ssel <[email protected]>
@blink-so blink-so bot changed the title refactor: move main.go to cmd/jail and create library interface refactor: move main.go to cmd/jail for standard Go project layout Sep 10, 2025
The empty jail.go file was causing Go tests to fail with:
'expected 'package', found 'EOF''

Removed the 0-byte file to fix test execution.
All tests now pass and build continues to work.

Fixes test failures in the root package.

Co-authored-by: f0ssel <[email protected]>
@f0ssel f0ssel merged commit e8622fd into main Sep 10, 2025
7 checks passed
@f0ssel f0ssel deleted the f0ssel/move-cmd branch September 16, 2025 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant