Skip to content

Commit 0770484

Browse files
authored
docs: Clarify version information behavior for different build methods (#283)
1 parent a2f2d81 commit 0770484

1 file changed

Lines changed: 34 additions & 3 deletions

File tree

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,43 @@ The initial release of the OS Image Composer tool has been tested and validated
1919

2020
Build the OS Image Composer command-line utility by using Go directly or by using the Earthly framework:
2121

22+
#### Development Build (Go)
23+
24+
For development and testing purposes, you can use Go directly:
25+
2226
```bash
2327
# Build the tool:
2428
go build -buildmode=pie -ldflags "-s -w" ./cmd/os-image-composer
2529

2630
# Or run it directly:
2731
go run ./cmd/os-image-composer --help
2832
```
29-
Using the Earthly framework produces a reproducible build that automatically includes the version number (from the `--version` parameter), the build date (the current UTC date), and the Git commit SHA (current repository commit).
33+
34+
**Note**: Development builds using `go build` will show default version information (e.g., `Version: 0.1.0`, `Build Date: unknown`). This is expected during development.
35+
36+
To include version information in a development build, use ldflags with git commands:
3037

3138
```bash
32-
# Default build
39+
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev")
40+
COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
41+
BUILD_DATE=$(date -u '+%Y-%m-%d')
42+
43+
go build -buildmode=pie \
44+
-ldflags "-s -w \
45+
-X 'github.com/open-edge-platform/os-image-composer/internal/config/version.Version=$VERSION' \
46+
-X 'github.com/open-edge-platform/os-image-composer/internal/config/version.Toolname=Image-Composer' \
47+
-X 'github.com/open-edge-platform/os-image-composer/internal/config/version.Organization=Open Edge Platform' \
48+
-X 'github.com/open-edge-platform/os-image-composer/internal/config/version.BuildDate=$BUILD_DATE' \
49+
-X 'github.com/open-edge-platform/os-image-composer/internal/config/version.CommitSHA=$COMMIT'" \
50+
./cmd/os-image-composer
51+
```
52+
53+
#### Production Build (Earthly)
54+
55+
For production and release builds, use the Earthly framework, which produces a reproducible build that automatically includes the version number (from git tags), the build date (the current UTC date), and the Git commit SHA:
56+
57+
```bash
58+
# Default build (uses latest git tag for version)
3359
earthly +build
3460

3561
# Build with specific version:
@@ -328,12 +354,17 @@ The `os-image-composer validate` command is useful for verifying template config
328354

329355
#### version
330356

331-
Displays the tools version number, build date, and Git commit SHA:
357+
Displays the tool's version number, build date, and Git commit SHA:
332358

333359
```bash
334360
./os-image-composer version
335361
```
336362

363+
**Note**: The version information depends on how the binary was built:
364+
- **Earthly build** (`earthly +build`): Shows actual version from git tags, build date, and commit SHA
365+
- **Simple Go build** (`go build`): Shows default development values unless ldflags are used
366+
- For production releases, always use the Earthly build or equivalent build system that injects version information
367+
337368
#### install-completion
338369

339370
Installs the shell completion feature for your current shell or a specified shell:

0 commit comments

Comments
 (0)