diff --git a/.github/workflows/Realease.yaml b/.github/workflows/Release.yaml similarity index 100% rename from .github/workflows/Realease.yaml rename to .github/workflows/Release.yaml diff --git a/.goreleaser.yml b/.goreleaser.yml index c8e098d..8e92342 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -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: @@ -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}') @@ -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: diff --git a/Dockerfile b/Dockerfile index 3a9783e..f57ee16 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ diff --git a/LICENSE b/LICENSE index 9dc5f7c..db567ce 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.md b/README.md index 206eb66..b9f46e6 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 @@ -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 @@ -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 diff --git a/cmd/coredhcp.go b/cmd/coredhcp.go deleted file mode 100644 index 69d3646..0000000 --- a/cmd/coredhcp.go +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2018-present the CoreDHCP Authors. All rights reserved -// This source code is licensed under the MIT license found in the -// LICENSE file in the root directory of this source tree. - -// 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` -package main - -import ( - "fmt" - "io" - "os" - - "github.com/coredhcp/coredhcp/config" - "github.com/coredhcp/coredhcp/logger" - "github.com/coredhcp/coredhcp/server" - - "github.com/coredhcp/coredhcp/plugins" - pl_bootloop "github.com/OpenCHAMI/coresmd/bootloop" - pl_coresmd "github.com/OpenCHAMI/coresmd/coresmd" - pl_autoconfigure "github.com/coredhcp/coredhcp/plugins/autoconfigure" - pl_dns "github.com/coredhcp/coredhcp/plugins/dns" - pl_file "github.com/coredhcp/coredhcp/plugins/file" - pl_ipv6only "github.com/coredhcp/coredhcp/plugins/ipv6only" - pl_leasetime "github.com/coredhcp/coredhcp/plugins/leasetime" - pl_mtu "github.com/coredhcp/coredhcp/plugins/mtu" - pl_nbp "github.com/coredhcp/coredhcp/plugins/nbp" - pl_netmask "github.com/coredhcp/coredhcp/plugins/netmask" - pl_prefix "github.com/coredhcp/coredhcp/plugins/prefix" - pl_range "github.com/coredhcp/coredhcp/plugins/range" - pl_router "github.com/coredhcp/coredhcp/plugins/router" - pl_searchdomains "github.com/coredhcp/coredhcp/plugins/searchdomains" - pl_serverid "github.com/coredhcp/coredhcp/plugins/serverid" - pl_sleep "github.com/coredhcp/coredhcp/plugins/sleep" - pl_staticroute "github.com/coredhcp/coredhcp/plugins/staticroute" - - "github.com/sirupsen/logrus" - flag "github.com/spf13/pflag" -) - -var ( - flagLogFile = flag.StringP("logfile", "l", "", "Name of the log file to append to. Default: stdout/stderr only") - flagLogNoStdout = flag.BoolP("nostdout", "N", false, "Disable logging to stdout/stderr") - flagLogLevel = flag.StringP("loglevel", "L", "info", fmt.Sprintf("Log level. One of %v", getLogLevels())) - flagConfig = flag.StringP("conf", "c", "", "Use this configuration file instead of the default location") - flagPlugins = flag.BoolP("plugins", "P", false, "list plugins") -) - -var logLevels = map[string]func(*logrus.Logger){ - "none": func(l *logrus.Logger) { l.SetOutput(io.Discard) }, - "debug": func(l *logrus.Logger) { l.SetLevel(logrus.DebugLevel) }, - "info": func(l *logrus.Logger) { l.SetLevel(logrus.InfoLevel) }, - "warning": func(l *logrus.Logger) { l.SetLevel(logrus.WarnLevel) }, - "error": func(l *logrus.Logger) { l.SetLevel(logrus.ErrorLevel) }, - "fatal": func(l *logrus.Logger) { l.SetLevel(logrus.FatalLevel) }, -} - -func getLogLevels() []string { - var levels []string - for k := range logLevels { - levels = append(levels, k) - } - return levels -} - -var desiredPlugins = []*plugins.Plugin{ - &pl_bootloop.Plugin, - &pl_coresmd.Plugin, - &pl_autoconfigure.Plugin, - &pl_dns.Plugin, - &pl_file.Plugin, - &pl_ipv6only.Plugin, - &pl_leasetime.Plugin, - &pl_mtu.Plugin, - &pl_nbp.Plugin, - &pl_netmask.Plugin, - &pl_prefix.Plugin, - &pl_range.Plugin, - &pl_router.Plugin, - &pl_searchdomains.Plugin, - &pl_serverid.Plugin, - &pl_sleep.Plugin, - &pl_staticroute.Plugin, -} - -func main() { - flag.Parse() - - if *flagPlugins { - for _, p := range desiredPlugins { - fmt.Println(p.Name) - } - os.Exit(0) - } - - log := logger.GetLogger("main") - fn, ok := logLevels[*flagLogLevel] - if !ok { - log.Fatalf("Invalid log level '%s'. Valid log levels are %v", *flagLogLevel, getLogLevels()) - } - fn(log.Logger) - log.Infof("Setting log level to '%s'", *flagLogLevel) - if *flagLogFile != "" { - log.Infof("Logging to file %s", *flagLogFile) - logger.WithFile(log, *flagLogFile) - } - if *flagLogNoStdout { - log.Infof("Disabling logging to stdout/stderr") - logger.WithNoStdOutErr(log) - } - config, err := config.Load(*flagConfig) - if err != nil { - log.Fatalf("Failed to load configuration: %v", err) - } - // register plugins - for _, plugin := range desiredPlugins { - if err := plugins.RegisterPlugin(plugin); err != nil { - log.Fatalf("Failed to register plugin '%s': %v", plugin.Name, err) - } - } - - // start server - srv, err := server.Start(config) - if err != nil { - log.Fatal(err) - } - if err := srv.Wait(); err != nil { - log.Error(err) - } -} \ No newline at end of file diff --git a/coredhcp/.gitignore b/coredhcp/.gitignore new file mode 100644 index 0000000..7c9d611 --- /dev/null +++ b/coredhcp/.gitignore @@ -0,0 +1,3 @@ +* +!.gitignore +!README.md diff --git a/coredhcp/README.md b/coredhcp/README.md new file mode 100644 index 0000000..2b5f2c2 --- /dev/null +++ b/coredhcp/README.md @@ -0,0 +1 @@ +This is where the generated coredhcp.go will be put. diff --git a/gen_version.bash b/gen_version.bash deleted file mode 100755 index 318efd6..0000000 --- a/gen_version.bash +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -base_dir="$(readlink -f $(dirname ${BASH_SOURCE[0]}))" -version_file=internal/version/version.go -cd "$base_dir" -sed -i "s/v0.0.0/$(git describe --tags --always --dirty --broken --abbrev=0)/" $version_file -sed -i "s/0000000/$(git rev-parse --short HEAD)/" $version_file -sed -i "s/0000-00-00:00:00:00/$(date -Iseconds)/" $version_file diff --git a/generator/coredhcp.go.template b/generator/coredhcp.go.template index 6cd4086..5cf675a 100644 --- a/generator/coredhcp.go.template +++ b/generator/coredhcp.go.template @@ -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 ( @@ -101,4 +102,4 @@ func main() { if err := srv.Wait(); err != nil { log.Error(err) } -} \ No newline at end of file +} diff --git a/dist/config.example.yaml b/resources/config.example.yaml similarity index 100% rename from dist/config.example.yaml rename to resources/config.example.yaml diff --git a/dist/reboot.ipxe b/resources/reboot.ipxe similarity index 100% rename from dist/reboot.ipxe rename to resources/reboot.ipxe