Skip to content

Commit

Permalink
Merge pull request #3 from OpenCHAMI/alexlovelltroy/build-improvements
Browse files Browse the repository at this point in the history
Build Improvements (Part 2)
  • Loading branch information
alexlovelltroy authored Nov 7, 2024
2 parents 88339ad + 223f300 commit 049c7b8
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 158 deletions.
File renamed without changes.
13 changes: 9 additions & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ project_name: coredhcp
before:
hooks:
- go install github.com/coredhcp/coredhcp/cmds/coredhcp-generator@latest
- mkdir -p cmd/
- coredhcp-generator -t generator/coredhcp.go.template -f generator/plugins.txt github.com/OpenCHAMI/coresmd/coresmd github.com/OpenCHAMI/coresmd/bootloop -o cmd/coredhcp.go
- coredhcp-generator -t generator/coredhcp.go.template -f generator/plugins.txt github.com/OpenCHAMI/coresmd/coresmd github.com/OpenCHAMI/coresmd/bootloop -o coredhcp/coredhcp.go
- go mod tidy

builds:
- id: coredhcp
main: ./cmd/
main: ./coredhcp/
goos:
- linux
goarch:
Expand All @@ -19,6 +18,7 @@ builds:
goamd64:
- v3

# If you want to build this locally, you can set the following environment variables:
# export GIT_STATE=$(if git diff-index --quiet HEAD --; then echo 'clean'; else echo 'dirty'; fi)
# export BUILD_HOST=$(hostname)
# export GO_VERSION=$(go version | awk '{print $3}')
Expand All @@ -35,7 +35,12 @@ builds:
-X main.BuildUser={{ .Env.BUILD_USER }} "
binary: coredhcp
env:
- CGO_ENABLED=0
# The bootloop plugin uses sqlite3 which requires CGO.
- CGO_ENABLED=1
- >-
CC={{- if eq .Os "linux" -}}
{{- if eq .Arch "amd64" -}}gcc{{- else -}}aarch64-linux-gnu-gcc{{- end -}}
{{- end }}
dockers:
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM chainguard/wolfi-base:latest

RUN apk add --no-cache tini

# Include curl in the final image.
# Include curl and tini in the final image.
RUN set -ex \
&& apk update \
&& apk add --no-cache curl tini \
Expand Down
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright © 2024 Triad National Security, LLC. All rights reserved.
Copyright © 2024 Triad National Security, LLC.

This program was produced under U.S. Government contract 89233218CNA000001
for Los Alamos National Laboratory (LANL), which is operated by Triad
National Security, LLC for the U.S. Department of Energy/National Nuclear
Expand Down
39 changes: 26 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,23 @@ This is meant to be built statically into

## Build/Install with goreleaser

This project uses [GoReleaser](https://goreleaser.com/) to automate releases and include additional build metadata such as commit info, build time, and versioning. Below is a guide on how to set up and build the project locally using GoReleaser.
This project uses [GoReleaser](https://goreleaser.com/) to automate releases and
include additional build metadata such as commit info, build time, and
versioning. Below is a guide on how to set up and build the project locally
using GoReleaser.

### Environment Variables

To include detailed build metadata, ensure the following environment variables are set:
To include detailed build metadata, ensure the following environment variables
are set:

* __GIT_STATE__: Indicates whether there are uncommitted changes in the working directory. Set to clean if the repository is clean, or dirty if there are uncommitted changes.
* __BUILD_HOST__: The hostname of the machine where the build is being performed.
* __GO_VERSION__: The version of Go used for the build. GoReleaser uses this to ensure consistent Go versioning information.
* __GIT_STATE__: Indicates whether there are uncommitted changes in the working
directory. Set to clean if the repository is clean, or dirty if there are
uncommitted changes.
* __BUILD_HOST__: The hostname of the machine where the build is being
performed.
* __GO_VERSION__: The version of Go used for the build. GoReleaser uses this to
ensure consistent Go versioning information.
* __BUILD_USER__: The username of the person or system performing the build.

Set all the environment variables with:
Expand All @@ -56,16 +64,21 @@ export BUILD_USER=$(whoami)

### Building Locally with GoReleaser

Once the environment variables are set, you can build the project locally using GoReleaser in snapshot mode (to avoid publishing).
Once the environment variables are set, you can build the project locally using
GoReleaser in snapshot mode (to avoid publishing).


Follow the installation instructions from [GoReleaser’s documentation](https://goreleaser.com/install/).
Follow the installation instructions from [GoReleaser’s
documentation](https://goreleaser.com/install/).

1. Run GoReleaser in snapshot mode with the --snapshot and --skip-publish flags to create a local build without attempting to release it:
1. Run GoReleaser in snapshot mode with the --snapshot and --skip-publish flags
to create a local build without attempting to release it:
```bash
goreleaser release --snapshot --skip-publish --clean
goreleaser release --snapshot --skip publish --clean
```
2. Check the dist/ directory for the built binaries, which will include the metadata from the environment variables. You can inspect the binary output to confirm that the metadata was correctly embedded.
2. Check the dist/ directory for the built binaries, which will include the
metadata from the environment variables. You can inspect the binary output
to confirm that the metadata was correctly embedded.


### Container
Expand Down Expand Up @@ -183,8 +196,8 @@ You'll now have a `coredhcp` binary in the current directory you can run.
## Configuration

CoreDHCP requires a config file to run. An example `config.yaml` can be found at
`dist/config.example.yaml`. That file contains comments on when/how to use the
coresmd and bootloop plugins, including which arguments to pass.
`resources/config.example.yaml`. That file contains comments on when/how to use
the coresmd and bootloop plugins, including which arguments to pass.

## Usage

Expand All @@ -201,7 +214,7 @@ server is required to be running[^tftp]. The IP address that this server listens
on should match the `server_id` directive in the CoreDHCP config file. This
server should serve the following files:

- `reboot.ipxe` --- This file is located `dist/` in this repository.
- `reboot.ipxe` --- This file is located `resources/` in this repository.
- `ipxe.efi` --- The iPXE x86\_64 EFI bootloader. This can be found
[here](https://boot.ipxe.org/ipxe.efi).
- `undionly.kpxe` --- The iPXE x86 legacy bootloader. This can be found
Expand Down
130 changes: 0 additions & 130 deletions cmd/coredhcp.go

This file was deleted.

3 changes: 3 additions & 0 deletions coredhcp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!README.md
1 change: 1 addition & 0 deletions coredhcp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is where the generated coredhcp.go will be put.
7 changes: 0 additions & 7 deletions gen_version.bash

This file was deleted.

3 changes: 2 additions & 1 deletion generator/coredhcp.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{{/* This file is the template source. The following comment obviously doesn't apply here */ -}}
// This is a generated file, edits should be made in the corresponding source file
// And this file regenerated using `coredhcp-generator --from core-plugins.txt`
// From CoreDHCP commit 576af8676ffaff9c85800fae235f614cb65410bd
package main

import (
Expand Down Expand Up @@ -101,4 +102,4 @@ func main() {
if err := srv.Wait(); err != nil {
log.Error(err)
}
}
}
File renamed without changes.
File renamed without changes.

0 comments on commit 049c7b8

Please sign in to comment.