|
1 | | -# LuaShip |
2 | | -A Lua Container Wrapper |
| 1 | +# LuaShip Documentation |
| 2 | + |
| 3 | +LuaShip is a Lua library for managing containerized build environments. It provides a simple interface for creating and managing container images, executing commands, and handling file operations. |
| 4 | + |
| 5 | +## Core Features |
| 6 | + |
| 7 | +- Container image management with support for Docker and Podman |
| 8 | +- File copying between host and container |
| 9 | +- Environment variable configuration |
| 10 | +- Build-time command execution |
| 11 | +- Flexible container start options |
| 12 | + |
| 13 | +## API Reference |
| 14 | + |
| 15 | +### LuaShip Module |
| 16 | + |
| 17 | +#### `create_machine(distro: string): LuaShipMachine` |
| 18 | +Creates a new container machine instance based on the specified distribution. |
| 19 | + |
| 20 | +**Parameters:** |
| 21 | +- `distro`: Base container image (e.g., "alpine:latest") |
| 22 | + |
| 23 | +**Returns:** |
| 24 | +- A new `LuaShipMachine` instance |
| 25 | + |
| 26 | +### LuaShipMachine |
| 27 | +#### Properties |
| 28 | + |
| 29 | +##### `provider: "podman" | "docker"` |
| 30 | +Specifies the container runtime to use. Must be either "podman" or "docker". |
| 31 | + |
| 32 | +##### `docker_file: string` |
| 33 | +Reference to the generated Dockerfile string. |
| 34 | + |
| 35 | +#### Methods |
| 36 | + |
| 37 | +##### `add_comptime_command(command: string)` |
| 38 | +Adds a command to be executed during image build time. |
| 39 | + |
| 40 | +**Parameters:** |
| 41 | +- `command`: Shell command to execute |
| 42 | + |
| 43 | +##### `copy(host_data: string, dest_data: string)` |
| 44 | +Copies files from host to container. |
| 45 | + |
| 46 | +**Parameters:** |
| 47 | +- `host_data`: Source path on host |
| 48 | +- `dest_data`: Destination path in container |
| 49 | + |
| 50 | +##### `env(name: string, value: string)` |
| 51 | +Sets an environment variable in the container. |
| 52 | + |
| 53 | +**Parameters:** |
| 54 | +- `name`: Environment variable name |
| 55 | +- `value`: Environment variable value |
| 56 | + |
| 57 | +##### `save_to_file(filename: string)` |
| 58 | +Saves the Dockerfile configuration to a file. |
| 59 | + |
| 60 | +**Parameters:** |
| 61 | +- `filename`: Target filename for the Dockerfile |
| 62 | + |
| 63 | +##### `start(props: LuaShipStartProps)` |
| 64 | +Starts the container with the specified configuration. |
| 65 | + |
| 66 | +**Parameters:** |
| 67 | +- `props`: Configuration object with the following properties: |
| 68 | + - `flags`: Array of container runtime flags (e.g., `["--memory=200m"]`) |
| 69 | + - `volumes`: Array of volume mappings `[["host_path", "container_path"]]` |
| 70 | + - `command`: Command to execute when starting the container |
| 71 | + |
| 72 | +## Example Usage |
| 73 | + |
| 74 | +```lua |
| 75 | +local ship = require("LuaShip") |
| 76 | + |
| 77 | +-- Create a new container machine |
| 78 | +local image = ship.create_machine("alpine:latest") |
| 79 | + |
| 80 | +-- Configure container runtime |
| 81 | +image.provider = "podman" |
| 82 | + |
| 83 | +-- Add build-time commands |
| 84 | +image.add_comptime_command("apk update") |
| 85 | +image.add_comptime_command("apk add --no-cache gcc musl-dev curl") |
| 86 | + |
| 87 | +-- Copy files |
| 88 | +image.copy("source.c", "source.c") |
| 89 | + |
| 90 | +-- Start container with specific configuration |
| 91 | +image.start({ |
| 92 | + flags = { |
| 93 | + "--memory=200m", |
| 94 | + "--network=host" |
| 95 | + }, |
| 96 | + volumes = { |
| 97 | + { ".", "/output" } |
| 98 | + }, |
| 99 | + command = "gcc --static source.c -o /output/binary" |
| 100 | +}) |
| 101 | +``` |
| 102 | + |
| 103 | +## Configuration |
| 104 | + |
| 105 | +The following functions can be configured by the user to customize behavior: |
| 106 | + |
| 107 | +- `LuaShip.open`: Customize file opening operations |
| 108 | +- `LuaShip.os_execute`: Customize system command execution |
| 109 | +- `LuaShip.os_remove`: Customize file removal operations |
| 110 | +- `LuaShip.error`: Customize error handling |
| 111 | + |
| 112 | +These functions can be overridden to implement custom logging, error handling, or system interaction behaviors. |
0 commit comments