From 63c14e4649412b875fec6f91ee624cb8a919381d Mon Sep 17 00:00:00 2001 From: Alex Lovell-Troy Date: Wed, 30 Oct 2024 15:05:37 -0600 Subject: [PATCH 01/17] minor fixups of existing PR --- .../workflows/{Realease.yaml => Release.yaml} | 0 .goreleaser.yml | 1 + Dockerfile | 3 +- LICENSE | 3 +- README.md | 2 +- dist/config.example.yaml | 91 ------------------- dist/reboot.ipxe | 2 - 7 files changed, 5 insertions(+), 97 deletions(-) rename .github/workflows/{Realease.yaml => Release.yaml} (100%) delete mode 100644 dist/config.example.yaml delete mode 100644 dist/reboot.ipxe 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..c63d95d 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -19,6 +19,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}') 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..39544c5 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Follow the installation instructions from [GoReleaser’s documentation](https:/ 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. diff --git a/dist/config.example.yaml b/dist/config.example.yaml deleted file mode 100644 index fcccb3f..0000000 --- a/dist/config.example.yaml +++ /dev/null @@ -1,91 +0,0 @@ ---- -server4: - plugins: - ############################################################################ - # - # NORMAL COREDHCP PLUGIN CONFIGURATION - # - ############################################################################ - - # REQUIRED: server_id configures the identity/IP of the DHCP server. This - # is necessary to distinguish it from possible other DHCP servers on the - # network. - - server_id: 172.16.0.253 - - # OPTIONAL: dns provides a list of DNS servers to use for names. - - dns: 1.1.1.1 8.8.8.8 - - # REQUIRED: router specifies the IP of the gateway of the network. This can - # be the same as server_id if the router is at the same IP. - - router: 172.16.0.254 - - # REQUIRED: netmask specifies the network mask to be used with IP addresses - # served by DHCP. - - netmask: 255.255.255.0 - - ############################################################################ - # - # CORESMD CONFIGURATION - # - ############################################################################ - - # REQUIRED: coresmd communicates with SMD and tries to match any MAC it - # receives to EthernetInterfaces in SMD. If one if found, the corresponding - # IP is leased to the requesting machine and packet processing terminates - # here. Otherwise, the packet processing continues to any plugins after - # this. - # - # ARGUMENTS: - # 1. Base URL used to communicate with SMD. - # 2. Base URL used to retrieve boot scripts. This is usually an HTTP URL - # that BSS is listening on, since the iPXE bootloader doesn't have the - # OpenCHAMI CA certificate to do proper TLS. It may also be an IP - # address if name servers are not configured. - # 3. (OPTIONAL) Path to CA cert used for TLS with the SMD base URL. If - # there is already a trusted certificate, this can be blank (""). - # 4. Cache validity duration. Coresmd uses a pull-through cache to store - # network information and this is the duration to refresh that cache. - # 5. Lease duration. - - coresmd: https://foobar.openchami.cluster http://172.16.0.253:8081 /root_ca/root_ca.crt 30s 1h - - # Any requests reaching this point are unknown to SMD and it is up to the - # administrator to decide how to handle unknown packets. - - # OPTIONAL: If the administrator cares about which IP addresses are - # assigned to which MAC addresses (e.g. the hosts file matches names to BMC - # IPs), CoreDHCP provides the file plugin for this purpose. - # - # The administrator will want to set lease_time to how long caught-all IP - # addresses should last. This could be long or short depending on the need. - - lease_time: 10m - # - # The file reads a file on the filesystem that maps MAC addresses to IP - # addresses. Its format is similar to a hosts file, e.g: - # - # - # - # ... - # - - file: /etc/coredhcp/hostsfile - - # OPTIONAL: If the administrator does not care about which IP addresses are - # assigned to which MAC addresses (or wants a catch-all after mapping - # relevant IPs to MACs using the file plugin above), coresmd provides the - # bootloop plugin. - # - # This plugin serves temporary IP addresses defined by a range with the - # given leas time, which should be short. Once the IP expires and the - # machine tries to renew its lease, a DHCPNAK is sent to make the device - # send a DHCPDISCOVER to re-perform the entire DHCP handshake. An iPXE boot - # script that reboots is served to all devices requesting an IP so that - # devices that can reboot will do so (to force it to redo the entire DHCP - # handshake). - # - # ARGUMENTS: - # 1. Path to database file that keeps track of leased IPs. This will be - # created if it does not already exist. - # 2. Lease duration. - # 3. IP address beginning range. - # 4. IP address ending range. - # - - bootloop: /tmp/coredhcp.db 5m 172.16.0.156 172.16.0.200 diff --git a/dist/reboot.ipxe b/dist/reboot.ipxe deleted file mode 100644 index 3adf24b..0000000 --- a/dist/reboot.ipxe +++ /dev/null @@ -1,2 +0,0 @@ -#!ipxe -reboot From 1499781ec4d0d9a8c6162a37aebb408c7ecae58b Mon Sep 17 00:00:00 2001 From: Devon Bautista Date: Wed, 30 Oct 2024 09:58:21 -0600 Subject: [PATCH 02/17] chore(coredhcp): comment CoreDHCP commit file was generated from --- cmd/coredhcp.go | 2 +- generator/coredhcp.go.template | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/coredhcp.go b/cmd/coredhcp.go index 69d3646..0f52dac 100644 --- a/cmd/coredhcp.go +++ b/cmd/coredhcp.go @@ -127,4 +127,4 @@ func main() { if err := srv.Wait(); err != nil { log.Error(err) } -} \ No newline at end of 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 +} From 718e8ee43293bbf73e3188f735ed4b6ddb954570 Mon Sep 17 00:00:00 2001 From: Devon Bautista Date: Wed, 30 Oct 2024 10:14:08 -0600 Subject: [PATCH 03/17] docs(README.md): make new material match format of rest of file --- README.md | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 39544c5..5644fc5 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 ``` -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 From 044611a0b618277a93a4d952b05a36b14a8e2621 Mon Sep 17 00:00:00 2001 From: Devon Bautista Date: Wed, 30 Oct 2024 12:52:28 -0600 Subject: [PATCH 04/17] build: differentiate goreleaser and local dockerfiles --- .goreleaser.yml | 2 ++ Dockerfile | 55 ++++++++++++++++++++++++++++++++++++++----- goreleaser.dockerfile | 20 ++++++++++++++++ 3 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 goreleaser.dockerfile diff --git a/.goreleaser.yml b/.goreleaser.yml index c63d95d..1ece476 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -45,6 +45,7 @@ dockers: - ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}-amd64 - ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}-amd64 use: buildx + dockerfile: goreleaser.dockerfile build_flag_templates: - "--pull" - "--platform=linux/amd64" @@ -63,6 +64,7 @@ dockers: - ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}-arm64 - ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}-arm64 use: buildx + dockerfile: goreleaser.dockerfile build_flag_templates: - "--pull" - "--platform=linux/arm64" diff --git a/Dockerfile b/Dockerfile index f57ee16..391bf13 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,46 @@ -FROM chainguard/wolfi-base:latest +################################################################################ +# STAGE 1: Generate CoreDHCP binary from sources +################################################################################ +FROM golang:1.21 AS builder +ARG CGO_ENABLED=1 + +RUN go install github.com/coredhcp/coredhcp/cmds/coredhcp-generator@latest + +WORKDIR /coresmd +COPY go.mod go.sum ./ +RUN go mod edit -replace=github.com/OpenCHAMI/coresmd=/coresmd +RUN go mod tidy +COPY . . + +RUN mkdir /coredhcp +WORKDIR /coredhcp + +# +# STEP 1: Generate coredhcp.go source file +# + +RUN coredhcp-generator \ + -t /coresmd/generator/coredhcp.go.template \ + -f /coresmd/generator/plugins.txt \ + -o /coredhcp/cmdscoredhcp.go \ + github.com/OpenCHAMI/coresmd/coresmd \ + github.com/OpenCHAMI/coresmd/bootloop + +# +# STEP 2: Build CoreDHCP +# + +RUN go mod init coredhcp +RUN go mod edit -replace=github.com/OpenCHAMI/coresmd=/coresmd +RUN go mod tidy +RUN go build -o coredhcp + +################################################################################ +# STAGE 2: Copy CoreDHCP to final location +################################################################################ + +FROM cgr.dev/chainguard/wolfi-base # Include curl and tini in the final image. RUN set -ex \ @@ -8,12 +49,14 @@ RUN set -ex \ && rm -rf /var/cache/apk/* \ && rm -rf /tmp/* -COPY coredhcp /coredhcp +COPY --from=builder /coredhcp/coredhcp /bin/coredhcp +EXPOSE 67 67/udp -# nobody 65534:65534 -USER 65534:65534 +# Make dir for config file +RUN mkdir -p /etc/coredhcp +VOLUME /etc/coredhcp -CMD [ "/coredhcp" ] +CMD [ "/bin/coredhcp" ] -ENTRYPOINT [ "/sbin/tini", "--" ] \ No newline at end of file +ENTRYPOINT [ "/sbin/tini", "--" ] diff --git a/goreleaser.dockerfile b/goreleaser.dockerfile new file mode 100644 index 0000000..3a9783e --- /dev/null +++ b/goreleaser.dockerfile @@ -0,0 +1,20 @@ +FROM chainguard/wolfi-base:latest + +RUN apk add --no-cache tini + +# Include curl in the final image. +RUN set -ex \ + && apk update \ + && apk add --no-cache curl tini \ + && rm -rf /var/cache/apk/* \ + && rm -rf /tmp/* + +COPY coredhcp /coredhcp + + +# nobody 65534:65534 +USER 65534:65534 + +CMD [ "/coredhcp" ] + +ENTRYPOINT [ "/sbin/tini", "--" ] \ No newline at end of file From 755efc647e1d4d21b2f24b142ed0e5a3a251b3e7 Mon Sep 17 00:00:00 2001 From: Devon Bautista Date: Wed, 30 Oct 2024 12:55:11 -0600 Subject: [PATCH 05/17] docs(README.md): differentiate dockerfiles --- README.md | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5644fc5..cee8107 100644 --- a/README.md +++ b/README.md @@ -83,11 +83,26 @@ documentation](https://goreleaser.com/install/). ### Container -This repository includes a Dockerfile that builds CoreDHCP with its core plugins -as well as this plugin. +**goreleaser.dockerfile** + +This dockerfile is what is used by Goreleaser to build containers. It assumes +the binary build from cmds/coredhcp.go has already been built. This dockerfile +is meant to be used for automated container releases, but can be used for local +builds as well. Run this using the `goreleaser` command above or with: + +``` +docker build -f goreleaser.dockerfile -t ghcr.io/openchami/coredhcp:latest . +``` + +**Dockerfile** + +This dockerfile uses the CoreDHCP generator to generate coredhcp.go using the +coresmd sources. It is meant to be used to be friendly for building a local +CoreDHCP container. The resulting CoreDHCP contains all of the core plugins plus +`coresmd` and `bootloop`. Build with: ``` -docker build . --tag coresmd:latest +docker build . --tag ghcr.io/openchami/coresmd:latest ``` ### Bare Metal From f4ca99349ea7f9e3ca1350411ec6a3b9c5e6e62d Mon Sep 17 00:00:00 2001 From: Devon Bautista Date: Wed, 30 Oct 2024 13:00:03 -0600 Subject: [PATCH 06/17] chore: move permanent resources from dist/ to resources/ --- README.md | 6 +-- resources/config.example.yaml | 91 +++++++++++++++++++++++++++++++++++ resources/reboot.ipxe | 2 + 3 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 resources/config.example.yaml create mode 100644 resources/reboot.ipxe diff --git a/README.md b/README.md index cee8107..c78ed41 100644 --- a/README.md +++ b/README.md @@ -211,8 +211,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 @@ -229,7 +229,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/resources/config.example.yaml b/resources/config.example.yaml new file mode 100644 index 0000000..fcccb3f --- /dev/null +++ b/resources/config.example.yaml @@ -0,0 +1,91 @@ +--- +server4: + plugins: + ############################################################################ + # + # NORMAL COREDHCP PLUGIN CONFIGURATION + # + ############################################################################ + + # REQUIRED: server_id configures the identity/IP of the DHCP server. This + # is necessary to distinguish it from possible other DHCP servers on the + # network. + - server_id: 172.16.0.253 + + # OPTIONAL: dns provides a list of DNS servers to use for names. + - dns: 1.1.1.1 8.8.8.8 + + # REQUIRED: router specifies the IP of the gateway of the network. This can + # be the same as server_id if the router is at the same IP. + - router: 172.16.0.254 + + # REQUIRED: netmask specifies the network mask to be used with IP addresses + # served by DHCP. + - netmask: 255.255.255.0 + + ############################################################################ + # + # CORESMD CONFIGURATION + # + ############################################################################ + + # REQUIRED: coresmd communicates with SMD and tries to match any MAC it + # receives to EthernetInterfaces in SMD. If one if found, the corresponding + # IP is leased to the requesting machine and packet processing terminates + # here. Otherwise, the packet processing continues to any plugins after + # this. + # + # ARGUMENTS: + # 1. Base URL used to communicate with SMD. + # 2. Base URL used to retrieve boot scripts. This is usually an HTTP URL + # that BSS is listening on, since the iPXE bootloader doesn't have the + # OpenCHAMI CA certificate to do proper TLS. It may also be an IP + # address if name servers are not configured. + # 3. (OPTIONAL) Path to CA cert used for TLS with the SMD base URL. If + # there is already a trusted certificate, this can be blank (""). + # 4. Cache validity duration. Coresmd uses a pull-through cache to store + # network information and this is the duration to refresh that cache. + # 5. Lease duration. + - coresmd: https://foobar.openchami.cluster http://172.16.0.253:8081 /root_ca/root_ca.crt 30s 1h + + # Any requests reaching this point are unknown to SMD and it is up to the + # administrator to decide how to handle unknown packets. + + # OPTIONAL: If the administrator cares about which IP addresses are + # assigned to which MAC addresses (e.g. the hosts file matches names to BMC + # IPs), CoreDHCP provides the file plugin for this purpose. + # + # The administrator will want to set lease_time to how long caught-all IP + # addresses should last. This could be long or short depending on the need. + - lease_time: 10m + # + # The file reads a file on the filesystem that maps MAC addresses to IP + # addresses. Its format is similar to a hosts file, e.g: + # + # + # + # ... + # + - file: /etc/coredhcp/hostsfile + + # OPTIONAL: If the administrator does not care about which IP addresses are + # assigned to which MAC addresses (or wants a catch-all after mapping + # relevant IPs to MACs using the file plugin above), coresmd provides the + # bootloop plugin. + # + # This plugin serves temporary IP addresses defined by a range with the + # given leas time, which should be short. Once the IP expires and the + # machine tries to renew its lease, a DHCPNAK is sent to make the device + # send a DHCPDISCOVER to re-perform the entire DHCP handshake. An iPXE boot + # script that reboots is served to all devices requesting an IP so that + # devices that can reboot will do so (to force it to redo the entire DHCP + # handshake). + # + # ARGUMENTS: + # 1. Path to database file that keeps track of leased IPs. This will be + # created if it does not already exist. + # 2. Lease duration. + # 3. IP address beginning range. + # 4. IP address ending range. + # + - bootloop: /tmp/coredhcp.db 5m 172.16.0.156 172.16.0.200 diff --git a/resources/reboot.ipxe b/resources/reboot.ipxe new file mode 100644 index 0000000..3adf24b --- /dev/null +++ b/resources/reboot.ipxe @@ -0,0 +1,2 @@ +#!ipxe +reboot From 834548b80cf613f72bbb38dd7c10d2f7f2f2a321 Mon Sep 17 00:00:00 2001 From: Devon Bautista Date: Wed, 30 Oct 2024 14:35:40 -0600 Subject: [PATCH 07/17] chore(docker): fix comment referencing curl (should be tini) --- goreleaser.dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/goreleaser.dockerfile b/goreleaser.dockerfile index 3a9783e..8517c75 100644 --- a/goreleaser.dockerfile +++ b/goreleaser.dockerfile @@ -2,7 +2,7 @@ FROM chainguard/wolfi-base:latest RUN apk add --no-cache tini -# Include curl in the final image. +# Include tini in the final image. RUN set -ex \ && apk update \ && apk add --no-cache curl tini \ @@ -17,4 +17,4 @@ USER 65534:65534 CMD [ "/coredhcp" ] -ENTRYPOINT [ "/sbin/tini", "--" ] \ No newline at end of file +ENTRYPOINT [ "/sbin/tini", "--" ] From 02464d45c7111601d3e88d9f073674c31af7e968 Mon Sep 17 00:00:00 2001 From: Devon Bautista Date: Wed, 30 Oct 2024 15:07:44 -0600 Subject: [PATCH 08/17] build(docker): add version setting to Dockerfile --- Dockerfile | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 391bf13..b3b7e7d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,7 @@ FROM golang:1.21 AS builder ARG CGO_ENABLED=1 +ARG CORESMD_IMPORT=github.com/OpenCHAMI/coresmd RUN go install github.com/coredhcp/coredhcp/cmds/coredhcp-generator@latest @@ -24,17 +25,25 @@ RUN coredhcp-generator \ -t /coresmd/generator/coredhcp.go.template \ -f /coresmd/generator/plugins.txt \ -o /coredhcp/cmdscoredhcp.go \ - github.com/OpenCHAMI/coresmd/coresmd \ - github.com/OpenCHAMI/coresmd/bootloop + "${CORESMD_IMPORT}"/coresmd \ + "${CORESMD_IMPORT}"/bootloop # # STEP 2: Build CoreDHCP # RUN go mod init coredhcp -RUN go mod edit -replace=github.com/OpenCHAMI/coresmd=/coresmd +RUN go mod edit -replace="${CORESMD_IMPORT}"=/coresmd RUN go mod tidy -RUN go build -o coredhcp +RUN go build -o coredhcp -ldflags "\ + -X '${CORESMD_IMPORT}/internal/version.GitCommit=$(cd /coresmd && git rev-parse HEAD)' \ + -X '${CORESMD_IMPORT}/internal/version.BuildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ)' \ + -X '${CORESMD_IMPORT}/internal/version.Version=$(cd /coresmd && git describe --tags --always --abbrev=0)' \ + -X '${CORESMD_IMPORT}/internal/version.GitTag=$(cd /coresmd && git describe --tags --always --abbrev=0)' \ + -X '${CORESMD_IMPORT}/internal/version.GitState=$(cd /coresmd && if git diff-index --quiet HEAD --; then echo clean; else echo dirty; fi)' \ + -X '${CORESMD_IMPORT}/internal/version.BuildHost=$(hostname)' \ + -X '${CORESMD_IMPORT}/internal/version.GoVersion=$(go version | awk '{print $3}')' \ + -X '${CORESMD_IMPORT}/internal/version.BuildUser=$(whoami)'" ################################################################################ # STAGE 2: Copy CoreDHCP to final location From 8e329931788d4bdca37fcd367db45b3e8003cba4 Mon Sep 17 00:00:00 2001 From: Devon Bautista Date: Wed, 30 Oct 2024 21:44:42 -0600 Subject: [PATCH 09/17] build: delete gen_version.bash --- gen_version.bash | 7 ------- 1 file changed, 7 deletions(-) delete mode 100755 gen_version.bash 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 From 3d2a6baee58a0f6cb7c1ef9d40df6e9579db9b46 Mon Sep 17 00:00:00 2001 From: Devon Bautista Date: Wed, 30 Oct 2024 21:45:01 -0600 Subject: [PATCH 10/17] build: add basic Makefile --- Makefile | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1a54d0d --- /dev/null +++ b/Makefile @@ -0,0 +1,45 @@ +BIN ?= coredhcp +GO ?= go +GOPATH ?= $(shell $(GO) env GOPATH) +COREDHCP_IMPORT ?= github.com/coredhcp/coredhcp +COREDHCP_GENERATOR ?= $(GOPATH)/bin/coredhcp-generator +CORESMD_IMPORT ?= github.com/OpenCHAMI/coresmd + +GIT_COMMIT = $(shell git rev-parse HEAD) +BUILD_TIME = $(shell date -u +%Y-%m-%dT%H:%M:%SZ) +VERSION = $(shell git describe --tags --always --abbrev=0) +GIT_TAG = $(shell git describe --tags --always --abbrev=0) +GIT_STATE = $(shell if git diff-index --quiet HEAD --; then echo clean; else echo dirty; fi) +BUILD_HOST = $(shell hostname) +GO_VERSION = $(shell go version | awk '{print $3}') +BUILD_USER = $(shell whoami) + +all: $(BIN) + +$(COREDHCP_GENERATOR): + GOPATH=$(GOPATH) $(GO) install $(GOREDHCP_IMPORT)/cmds/coredhcp-generator + +cmd/coredhcp.go: $(COREDHCP_GENERATOR) generator/coredhcp.go.template generator/plugins.txt + $(COREDHCP_GENERATOR) \ + -t generator/coredhcp.go.template \ + -f generator/plugins.txt \ + -o $@ \ + $(CORESMD_IMPORT)/coresmd \ + $(CORESMD_IMPORT)/bootloop + +$(BIN): cmd/coredhcp.go + $(GO) build -o $@ -ldflags " -s -w \ + -X '$(CORESMD_IMPORT)/internal/version.GitCommit=$(GIT_COMMIT)' \ + -X '$(CORESMD_IMPORT)/internal/version.BuildTime=$(BUILD_TIME)' \ + -X '$(CORESMD_IMPORT)/internal/version.Version=$(VERSION)' \ + -X '$(CORESMD_IMPORT)/internal/version.GitTag=$(GIT_TAG)' \ + -X '$(CORESMD_IMPORT)/internal/version.GitState=$(GIT_STATE)' \ + -X '$(CORESMD_IMPORT)/internal/version.BuildHost=$(BUILD_HOST)' \ + -X '$(CORESMD_IMPORT)/internal/version.GoVersion=$(GO_VERSION)' \ + -X '$(CORESMD_IMPORT)/internal/version.BuildUser=$(BUILD_USER)'" \ + $^ + +clean: + $(GO) clean -i -x ./cmd + rm -f coredhcp + rm -f cmd/coredhcp.go From 923dd8c80b67d7e5336a18a2b3c8a4a5454a05da Mon Sep 17 00:00:00 2001 From: Devon Bautista Date: Wed, 30 Oct 2024 22:07:34 -0600 Subject: [PATCH 11/17] build: move cmd/ to coredhcp/ and delete coredhcp.go --- .goreleaser.yml | 5 +- cmd/coredhcp.go | 130 -------------------------------------------- coredhcp/.gitignore | 3 + coredhcp/README.md | 1 + 4 files changed, 6 insertions(+), 133 deletions(-) delete mode 100644 cmd/coredhcp.go create mode 100644 coredhcp/.gitignore create mode 100644 coredhcp/README.md diff --git a/.goreleaser.yml b/.goreleaser.yml index 1ece476..2901169 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: diff --git a/cmd/coredhcp.go b/cmd/coredhcp.go deleted file mode 100644 index 0f52dac..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) - } -} 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. From 6d2b0a7a384fa338598c6f9dd4f58b42d6a23166 Mon Sep 17 00:00:00 2001 From: Devon Bautista Date: Thu, 31 Oct 2024 10:42:41 -0600 Subject: [PATCH 12/17] Revert "build: add basic Makefile" This reverts commit 3d2a6baee58a0f6cb7c1ef9d40df6e9579db9b46. --- Makefile | 45 --------------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index 1a54d0d..0000000 --- a/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -BIN ?= coredhcp -GO ?= go -GOPATH ?= $(shell $(GO) env GOPATH) -COREDHCP_IMPORT ?= github.com/coredhcp/coredhcp -COREDHCP_GENERATOR ?= $(GOPATH)/bin/coredhcp-generator -CORESMD_IMPORT ?= github.com/OpenCHAMI/coresmd - -GIT_COMMIT = $(shell git rev-parse HEAD) -BUILD_TIME = $(shell date -u +%Y-%m-%dT%H:%M:%SZ) -VERSION = $(shell git describe --tags --always --abbrev=0) -GIT_TAG = $(shell git describe --tags --always --abbrev=0) -GIT_STATE = $(shell if git diff-index --quiet HEAD --; then echo clean; else echo dirty; fi) -BUILD_HOST = $(shell hostname) -GO_VERSION = $(shell go version | awk '{print $3}') -BUILD_USER = $(shell whoami) - -all: $(BIN) - -$(COREDHCP_GENERATOR): - GOPATH=$(GOPATH) $(GO) install $(GOREDHCP_IMPORT)/cmds/coredhcp-generator - -cmd/coredhcp.go: $(COREDHCP_GENERATOR) generator/coredhcp.go.template generator/plugins.txt - $(COREDHCP_GENERATOR) \ - -t generator/coredhcp.go.template \ - -f generator/plugins.txt \ - -o $@ \ - $(CORESMD_IMPORT)/coresmd \ - $(CORESMD_IMPORT)/bootloop - -$(BIN): cmd/coredhcp.go - $(GO) build -o $@ -ldflags " -s -w \ - -X '$(CORESMD_IMPORT)/internal/version.GitCommit=$(GIT_COMMIT)' \ - -X '$(CORESMD_IMPORT)/internal/version.BuildTime=$(BUILD_TIME)' \ - -X '$(CORESMD_IMPORT)/internal/version.Version=$(VERSION)' \ - -X '$(CORESMD_IMPORT)/internal/version.GitTag=$(GIT_TAG)' \ - -X '$(CORESMD_IMPORT)/internal/version.GitState=$(GIT_STATE)' \ - -X '$(CORESMD_IMPORT)/internal/version.BuildHost=$(BUILD_HOST)' \ - -X '$(CORESMD_IMPORT)/internal/version.GoVersion=$(GO_VERSION)' \ - -X '$(CORESMD_IMPORT)/internal/version.BuildUser=$(BUILD_USER)'" \ - $^ - -clean: - $(GO) clean -i -x ./cmd - rm -f coredhcp - rm -f cmd/coredhcp.go From 2d40aae92185856822d21755835fd74a7fb556ba Mon Sep 17 00:00:00 2001 From: Devon Bautista Date: Thu, 31 Oct 2024 10:42:45 -0600 Subject: [PATCH 13/17] Revert "build(docker): add version setting to Dockerfile" This reverts commit 02464d45c7111601d3e88d9f073674c31af7e968. --- Dockerfile | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index b3b7e7d..391bf13 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,6 @@ FROM golang:1.21 AS builder ARG CGO_ENABLED=1 -ARG CORESMD_IMPORT=github.com/OpenCHAMI/coresmd RUN go install github.com/coredhcp/coredhcp/cmds/coredhcp-generator@latest @@ -25,25 +24,17 @@ RUN coredhcp-generator \ -t /coresmd/generator/coredhcp.go.template \ -f /coresmd/generator/plugins.txt \ -o /coredhcp/cmdscoredhcp.go \ - "${CORESMD_IMPORT}"/coresmd \ - "${CORESMD_IMPORT}"/bootloop + github.com/OpenCHAMI/coresmd/coresmd \ + github.com/OpenCHAMI/coresmd/bootloop # # STEP 2: Build CoreDHCP # RUN go mod init coredhcp -RUN go mod edit -replace="${CORESMD_IMPORT}"=/coresmd +RUN go mod edit -replace=github.com/OpenCHAMI/coresmd=/coresmd RUN go mod tidy -RUN go build -o coredhcp -ldflags "\ - -X '${CORESMD_IMPORT}/internal/version.GitCommit=$(cd /coresmd && git rev-parse HEAD)' \ - -X '${CORESMD_IMPORT}/internal/version.BuildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ)' \ - -X '${CORESMD_IMPORT}/internal/version.Version=$(cd /coresmd && git describe --tags --always --abbrev=0)' \ - -X '${CORESMD_IMPORT}/internal/version.GitTag=$(cd /coresmd && git describe --tags --always --abbrev=0)' \ - -X '${CORESMD_IMPORT}/internal/version.GitState=$(cd /coresmd && if git diff-index --quiet HEAD --; then echo clean; else echo dirty; fi)' \ - -X '${CORESMD_IMPORT}/internal/version.BuildHost=$(hostname)' \ - -X '${CORESMD_IMPORT}/internal/version.GoVersion=$(go version | awk '{print $3}')' \ - -X '${CORESMD_IMPORT}/internal/version.BuildUser=$(whoami)'" +RUN go build -o coredhcp ################################################################################ # STAGE 2: Copy CoreDHCP to final location From 8e8666ea8bf98d5071e9541a49626e696766d0de Mon Sep 17 00:00:00 2001 From: Devon Bautista Date: Thu, 31 Oct 2024 10:42:47 -0600 Subject: [PATCH 14/17] Revert "chore(docker): fix comment referencing curl (should be tini)" This reverts commit 834548b80cf613f72bbb38dd7c10d2f7f2f2a321. --- goreleaser.dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/goreleaser.dockerfile b/goreleaser.dockerfile index 8517c75..3a9783e 100644 --- a/goreleaser.dockerfile +++ b/goreleaser.dockerfile @@ -2,7 +2,7 @@ FROM chainguard/wolfi-base:latest RUN apk add --no-cache tini -# Include tini in the final image. +# Include curl in the final image. RUN set -ex \ && apk update \ && apk add --no-cache curl tini \ @@ -17,4 +17,4 @@ USER 65534:65534 CMD [ "/coredhcp" ] -ENTRYPOINT [ "/sbin/tini", "--" ] +ENTRYPOINT [ "/sbin/tini", "--" ] \ No newline at end of file From ee60e217cb3ff8aa1404882f6aac5950f7d40676 Mon Sep 17 00:00:00 2001 From: Devon Bautista Date: Thu, 31 Oct 2024 10:42:48 -0600 Subject: [PATCH 15/17] Revert "docs(README.md): differentiate dockerfiles" This reverts commit 755efc647e1d4d21b2f24b142ed0e5a3a251b3e7. --- README.md | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index c78ed41..b9f46e6 100644 --- a/README.md +++ b/README.md @@ -83,26 +83,11 @@ documentation](https://goreleaser.com/install/). ### Container -**goreleaser.dockerfile** - -This dockerfile is what is used by Goreleaser to build containers. It assumes -the binary build from cmds/coredhcp.go has already been built. This dockerfile -is meant to be used for automated container releases, but can be used for local -builds as well. Run this using the `goreleaser` command above or with: - -``` -docker build -f goreleaser.dockerfile -t ghcr.io/openchami/coredhcp:latest . -``` - -**Dockerfile** - -This dockerfile uses the CoreDHCP generator to generate coredhcp.go using the -coresmd sources. It is meant to be used to be friendly for building a local -CoreDHCP container. The resulting CoreDHCP contains all of the core plugins plus -`coresmd` and `bootloop`. Build with: +This repository includes a Dockerfile that builds CoreDHCP with its core plugins +as well as this plugin. ``` -docker build . --tag ghcr.io/openchami/coresmd:latest +docker build . --tag coresmd:latest ``` ### Bare Metal From 2e4e5d81cd63efa5962d6853050480af818da045 Mon Sep 17 00:00:00 2001 From: Devon Bautista Date: Thu, 31 Oct 2024 10:44:51 -0600 Subject: [PATCH 16/17] Revert "build: differentiate goreleaser and local dockerfiles" This reverts commit 044611a0b618277a93a4d952b05a36b14a8e2621. --- .goreleaser.yml | 2 -- Dockerfile | 55 +++++-------------------------------------- goreleaser.dockerfile | 20 ---------------- 3 files changed, 6 insertions(+), 71 deletions(-) delete mode 100644 goreleaser.dockerfile diff --git a/.goreleaser.yml b/.goreleaser.yml index 2901169..7c28e04 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -44,7 +44,6 @@ dockers: - ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}-amd64 - ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}-amd64 use: buildx - dockerfile: goreleaser.dockerfile build_flag_templates: - "--pull" - "--platform=linux/amd64" @@ -63,7 +62,6 @@ dockers: - ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}-arm64 - ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}-arm64 use: buildx - dockerfile: goreleaser.dockerfile build_flag_templates: - "--pull" - "--platform=linux/arm64" diff --git a/Dockerfile b/Dockerfile index 391bf13..f57ee16 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,46 +1,5 @@ -################################################################################ -# STAGE 1: Generate CoreDHCP binary from sources -################################################################################ +FROM chainguard/wolfi-base:latest -FROM golang:1.21 AS builder -ARG CGO_ENABLED=1 - -RUN go install github.com/coredhcp/coredhcp/cmds/coredhcp-generator@latest - -WORKDIR /coresmd -COPY go.mod go.sum ./ -RUN go mod edit -replace=github.com/OpenCHAMI/coresmd=/coresmd -RUN go mod tidy -COPY . . - -RUN mkdir /coredhcp -WORKDIR /coredhcp - -# -# STEP 1: Generate coredhcp.go source file -# - -RUN coredhcp-generator \ - -t /coresmd/generator/coredhcp.go.template \ - -f /coresmd/generator/plugins.txt \ - -o /coredhcp/cmdscoredhcp.go \ - github.com/OpenCHAMI/coresmd/coresmd \ - github.com/OpenCHAMI/coresmd/bootloop - -# -# STEP 2: Build CoreDHCP -# - -RUN go mod init coredhcp -RUN go mod edit -replace=github.com/OpenCHAMI/coresmd=/coresmd -RUN go mod tidy -RUN go build -o coredhcp - -################################################################################ -# STAGE 2: Copy CoreDHCP to final location -################################################################################ - -FROM cgr.dev/chainguard/wolfi-base # Include curl and tini in the final image. RUN set -ex \ @@ -49,14 +8,12 @@ RUN set -ex \ && rm -rf /var/cache/apk/* \ && rm -rf /tmp/* -COPY --from=builder /coredhcp/coredhcp /bin/coredhcp +COPY coredhcp /coredhcp -EXPOSE 67 67/udp -# Make dir for config file -RUN mkdir -p /etc/coredhcp -VOLUME /etc/coredhcp +# nobody 65534:65534 +USER 65534:65534 -CMD [ "/bin/coredhcp" ] +CMD [ "/coredhcp" ] -ENTRYPOINT [ "/sbin/tini", "--" ] +ENTRYPOINT [ "/sbin/tini", "--" ] \ No newline at end of file diff --git a/goreleaser.dockerfile b/goreleaser.dockerfile deleted file mode 100644 index 3a9783e..0000000 --- a/goreleaser.dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -FROM chainguard/wolfi-base:latest - -RUN apk add --no-cache tini - -# Include curl in the final image. -RUN set -ex \ - && apk update \ - && apk add --no-cache curl tini \ - && rm -rf /var/cache/apk/* \ - && rm -rf /tmp/* - -COPY coredhcp /coredhcp - - -# nobody 65534:65534 -USER 65534:65534 - -CMD [ "/coredhcp" ] - -ENTRYPOINT [ "/sbin/tini", "--" ] \ No newline at end of file From 223f30028f6ac23cb9dcd2937fef51c1613c03ba Mon Sep 17 00:00:00 2001 From: Devon Bautista Date: Thu, 31 Oct 2024 11:32:08 -0600 Subject: [PATCH 17/17] build(goreleaser): enable CGO This is required for sqlite3, which is used as the storage backend for bootloop. --- .goreleaser.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 7c28e04..8e92342 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -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: