Skip to content

Commit

Permalink
Update docs reflect gomod generator feature
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Goff <[email protected]>
  • Loading branch information
cpuguy83 committed Apr 11, 2024
1 parent 6f19b9b commit f3d1171
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 20 deletions.
1 change: 1 addition & 0 deletions docs/examples/go-md2man-1.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# syntax=ghcr.io/azure/dalec/frontend:latest
name: go-md2man
version: 2.0.3
revision: "1"
packager: Dalec Example
vendor: Dalec Example
license: MIT
Expand Down
22 changes: 3 additions & 19 deletions docs/examples/go-md2man-2.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# syntax=ghcr.io/azure/dalec/frontend:latest
name: go-md2man
version: 2.0.3
revision: "1"
packager: Dalec Example
vendor: Dalec Example
license: MIT
Expand All @@ -9,27 +10,11 @@ website: https://github.com/cpuguy83/go-md2man

sources:
src:
generators:
- gomod
git:
url: https://github.com/cpuguy83/go-md2man.git
commit: "v2.0.3"
gomods: # This is required when the build environment does not allow network access. This downloads all the go modules.
path: /build/gomodcache # This is the path we will be extracing after running the command below.
image:
ref: mcr.microsoft.com/oss/go/microsoft/golang:1.21
cmd:
dir: /build/src
mounts:
# Mount a source (inline, under `spec`), so our command has access to it.
- dest: /build/src
spec:
git:
url: https://github.com/cpuguy83/go-md2man.git
commit: "v2.0.3"
steps:
- command: go mod download
env:
# This variable controls where the go modules are downloaded to.
GOMODCACHE: /build/gomodcache

dependencies:
build:
Expand All @@ -40,7 +25,6 @@ build:
CGO_ENABLED: "0"
steps:
- command: |
export GOMODCACHE="$(pwd)/gomods"
cd src
go build -o go-md2man .
Expand Down
51 changes: 50 additions & 1 deletion docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ In this examnple wee'll build a virtual package that just installs other package
# syntax=ghcr.io/azure/dalec/frontend:latest
name: my-package
version: 1.0.0
revision: "1"
packager: Contoso
vendor: Contoso
license: MIT
Expand Down Expand Up @@ -61,6 +62,7 @@ as the base image which includes a shell and other tools.
# syntax=ghcr.io/azure/dalec/frontend:latest
name: my-package
version: 1.0.0
revision: "1"
packager: Contoso
vendor: Contoso
license: MIT
Expand Down Expand Up @@ -130,6 +132,7 @@ It will use the `go-md2man` repo and build the `go-md2man` from the v2.0.3 tag i
# syntax=ghcr.io/azure/dalec/frontend:latest
name: go-md2man
version: 2.0.3
revision: "1"
packager: Dalec Example
vendor: Dalec Example
license: MIT
Expand All @@ -151,7 +154,6 @@ build:
CGO_ENABLED: "0"
steps:
- command: |
export GOMODCACHE="$(pwd)/gomods"
cd src
go build -o go-md2man .
Expand Down Expand Up @@ -194,6 +196,7 @@ go modules from the resulting filesystem.
# syntax=ghcr.io/azure/dalec/frontend:latest
name: go-md2man
version: 2.0.3
revision: "1"
packager: Dalec Example
vendor: Dalec Example
license: MIT
Expand Down Expand Up @@ -246,6 +249,52 @@ image:
cmd: --help
```
The nice thing about this is you can see exactly what's being done to generate the go modules.
The downside is its extremely verbose and even requires you to do things outside of the toolchainf or the targeted distribution.
The below example does something similar but in a more concise way:
```yaml
name: go-md2man
version: 2.0.3
revision: "1"
packager: Dalec Example
vendor: Dalec Example
license: MIT
description: A tool to convert markdown into man pages (roff).
website: https://github.com/cpuguy83/go-md2man

sources:
src:
generators:
- gomod
git:
url: https://github.com/cpuguy83/go-md2man.git
commit: "v2.0.3"
dependencies:
build:
golang:

build:
env:
CGO_ENABLED: "0"
steps:
- command: |
cd src
go build -o go-md2man .
artifacts:
binaries:
src/go-md2man:

image:
entrypoint: go-md2man
cmd: --help
```
The above "gomod" generator takes care of fetching the module dependencies for any and all sources that have the generator set.
The module dependencies are managed by Dalec and injected into the build sources.
The neccessary go environment variables are set in the build environment so that the go build toolchain knows where to find the modules.
Finally, we can add a test case to the spec file which helps ensure the package is assembled as expected.
The following test will make sure `/usr/bin/go-md2man` is installed and has the expected permissions.
These tests are automatically executed when building the container image.
Expand Down

0 comments on commit f3d1171

Please sign in to comment.