Archived
Add build-stamped version metadata to provider binary
This commit is contained in:
@@ -18,3 +18,12 @@ jobs:
|
|||||||
|
|
||||||
- name: Verify formatting and run quality gate
|
- name: Verify formatting and run quality gate
|
||||||
run: ./scripts/check.sh
|
run: ./scripts/check.sh
|
||||||
|
|
||||||
|
- name: Build provider binary (stamped metadata)
|
||||||
|
run: |
|
||||||
|
VERSION="${GITHUB_REF_NAME:-dev}"
|
||||||
|
COMMIT="$(git rev-parse --short HEAD)"
|
||||||
|
DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
||||||
|
|
||||||
|
go build -o terraform-provider-dynu \
|
||||||
|
-ldflags="-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}"
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ This provider is **not published** to the Terraform Registry yet. For local deve
|
|||||||
go build -o terraform-provider-dynu
|
go build -o terraform-provider-dynu
|
||||||
```
|
```
|
||||||
|
|
||||||
|
By default, local builds use embedded metadata values:
|
||||||
|
- `version=dev`
|
||||||
|
- `commit=none`
|
||||||
|
- `built=unknown`
|
||||||
|
|
||||||
2. Configure `~/.terraformrc`:
|
2. Configure `~/.terraformrc`:
|
||||||
|
|
||||||
```hcl
|
```hcl
|
||||||
@@ -53,6 +58,33 @@ terraform plan
|
|||||||
|
|
||||||
When provider configuration or code changes, rebuild the provider binary first, then re-run `terraform validate` and `terraform plan`.
|
When provider configuration or code changes, rebuild the provider binary first, then re-run `terraform validate` and `terraform plan`.
|
||||||
|
|
||||||
|
### Version metadata in binaries
|
||||||
|
|
||||||
|
The provider embeds build metadata (`version`, `commit`, `date`) in the binary.
|
||||||
|
|
||||||
|
- Local builds (no `-ldflags`) default to:
|
||||||
|
- `version=dev`
|
||||||
|
- `commit=none`
|
||||||
|
- `built=unknown`
|
||||||
|
- You can inspect metadata from the binary with either:
|
||||||
|
- `./terraform-provider-dynu --version`
|
||||||
|
- `./terraform-provider-dynu version`
|
||||||
|
|
||||||
|
Build a stamped binary with standard Go `-ldflags`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
VERSION=${VERSION:-v0.2.0}
|
||||||
|
COMMIT=$(git rev-parse --short HEAD)
|
||||||
|
DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||||
|
|
||||||
|
go build -o terraform-provider-dynu \
|
||||||
|
-ldflags="-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}"
|
||||||
|
```
|
||||||
|
|
||||||
|
Release tag/version mapping:
|
||||||
|
- Git tag `v0.1.0` -> build with `VERSION=v0.1.0`
|
||||||
|
- Git tag `v0.2.0` -> build with `VERSION=v0.2.0`
|
||||||
|
|
||||||
## Copy/paste starter configuration
|
## Copy/paste starter configuration
|
||||||
|
|
||||||
```hcl
|
```hcl
|
||||||
|
|||||||
@@ -2,15 +2,30 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/providerserver"
|
"github.com/hashicorp/terraform-plugin-framework/providerserver"
|
||||||
|
|
||||||
"github.com/dynu/terraform-provider-dynu/internal/provider"
|
"github.com/dynu/terraform-provider-dynu/internal/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
version = "dev"
|
||||||
|
commit = "none"
|
||||||
|
date = "unknown"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := providerserver.Serve(context.Background(), provider.New("dev"), providerserver.ServeOpts{
|
if len(os.Args) == 2 && (os.Args[1] == "--version" || os.Args[1] == "version") {
|
||||||
|
fmt.Printf("terraform-provider-dynu version=%s commit=%s built=%s\n", version, commit, date)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("starting terraform-provider-dynu version=%s commit=%s built=%s", version, commit, date)
|
||||||
|
|
||||||
|
err := providerserver.Serve(context.Background(), provider.New(version), providerserver.ServeOpts{
|
||||||
Address: "registry.terraform.io/dynu/dynu",
|
Address: "registry.terraform.io/dynu/dynu",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user