Skip to content

Commit

Permalink
Merge branch 'goreleaser'
Browse files Browse the repository at this point in the history
  • Loading branch information
synackd committed Oct 31, 2023
2 parents 1847f88 + 782f278 commit 0da5f71
Show file tree
Hide file tree
Showing 1,446 changed files with 7,946 additions and 516,434 deletions.
72 changes: 72 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

project_name: hms-bss
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy

builds:
- id: hms-bss
main: ./cmd/boot-script-service
binary: boot-script-service
goos:
- linux
goarch:
- amd64
no_unique_dist_dir: true
tags:
- dynamic

dockers:
-
image_templates:
- bikeshack/{{.ProjectName}}:latest
- bikeshack/{{.ProjectName}}:{{ .Tag }}
- bikeshack/{{.ProjectName}}:{{ .Major }}
- bikeshack/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
extra_files:
- LICENSE
- CHANGELOG.md
- README.md
- .version

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
files:
- LICENSE
- CHANGELOG.md
- README.md


checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'


# The lines beneath this are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
67 changes: 18 additions & 49 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,65 +20,26 @@
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

# Dockerfile for building HMS bss.

### build-base stage ###
# Build base just has the packages installed we need.
FROM artifactory.algol60.net/docker.io/library/golang:1.16-alpine AS build-base

RUN set -ex \
&& apk -U upgrade \
&& apk add build-base

### base stage ###
# Base copies in the files we need to test/build.
FROM build-base AS base

RUN go env -w GO111MODULE=auto

# Copy all the necessary files to the image.
COPY cmd $GOPATH/src/github.com/Cray-HPE/hms-bss/cmd
COPY pkg $GOPATH/src/github.com/Cray-HPE/hms-bss/pkg
COPY vendor $GOPATH/src/github.com/Cray-HPE/hms-bss/vendor
COPY .version $GOPATH/src/github.com/Cray-HPE/hms-bss/.version

### Build Stage ###
FROM base AS builder

RUN set -ex && go build -v -i -o /usr/local/bin/boot-script-service github.com/Cray-HPE/hms-bss/cmd/boot-script-service

### Final Stage ###
FROM artifactory.algol60.net/docker.io/alpine:3.15
LABEL maintainer="Hewlett Packard Enterprise"
FROM cgr.dev/chainguard/wolfi-base
EXPOSE 27778
STOPSIGNAL SIGTERM

RUN apk add --no-cache tini

# Setup environment variables.
ENV HSM_URL=http://cray-smd
ENV HSM_URL=http://smd:27779
ENV NFD_URL=http://cray-hmnfd

# Set up default path to the Datastore service.
#ENV DATASTORE_URL=https://$ETCD_HOST:$ETCD_PORT
# The datastore is now etcd. We would like to set the URL to the above, as
# the etcd operator sets up those two env variables. Unfortunately, env
# vars do not get interpretted in a Dockerfile. Therefore, bss is set up to
# look for those environment variables. So we no longer set the DATASTORE_URL
# environment variable. We still allow it, however, so this setting can be
# controlled from the outside more easily. Note the special handling below.

# WARNING: Our containers currently do not have certificates set up correctly
# to allow for https connections to other containers. Therefore, we
# will use an insecure connection. This needs to be corrected before
# release. Once the certificates are properly set up, the --insecure
# option needs to be removed.
ENV BSS_OPTS="--insecure"
ENV BSS_OPTS="--insecure --postgres-insecure"

ENV BSS_RETRY_DELAY=30
ENV BSS_HSM_RETRIEVAL_DELAY=10

ENV ETCD_HOST "etcd"
ENV ETCD_PORT "2379"

# Other potentially useful env variables:
# BSS_IPXE_SERVER defaults to "api-gw-service-nmn.local"
# BSS_CHAIN_PROTO defaults to "https"
Expand All @@ -90,12 +51,20 @@ RUN set -ex \
&& apk add --no-cache curl

# Get the boot-script-service from the builder stage.
COPY --from=builder /usr/local/bin/boot-script-service /usr/local/bin/.

COPY boot-script-service /usr/local/bin/
COPY .version /

# noboby 65534:65534
# nobody 65534:65534
USER 65534:65534

# Set up the command to start the service, the run the init script.
CMD boot-script-service $BSS_OPTS --hsm=$HSM_URL ${DATASTORE_URL:+--datastore=}$DATASTORE_URL --retry-delay=$BSS_RETRY_DELAY --hsm-retrieval-delay=$BSS_HSM_RETRIEVAL_DELAY
# Set up the command to start the service.
CMD /usr/local/bin/boot-script-service $BSS_OPTS \
--cloud-init-address localhost \
--postgres \
--postgres-host $POSTGRES_HOST \
--postgres-port $POSTGRES_PORT \
--retry-delay=$BSS_RETRY_DELAY \
--hsm $HSM_URL \
--hsm-retrieval-delay=$BSS_HSM_RETRIEVAL_DELAY

ENTRYPOINT ["/sbin/tini", "--"]
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env bash
# MIT License
#
# (C) Copyright [2021] Hewlett Packard Enterprise Development LP
Expand All @@ -21,7 +20,12 @@
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

# Build the build base image
docker build -t cray/hms-base-build-base -f Dockerfile.build-base .
# Dockerfile for running postgres integration tests.

docker build -t cray/hms-base-coverage -f Dockerfile.coverage .
### build-base stage ###
# Build base just has the packages installed we need.
FROM alpine:latest

RUN apk add curl

ENTRYPOINT ["/bin/sh"]
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env bash
# MIT License
#
# (C) Copyright [2021] Hewlett Packard Enterprise Development LP
Expand All @@ -21,7 +20,16 @@
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

# Build the build base image
docker build -t cray/hms-hmetcd-build-base -f Dockerfile.build-base .
# Dockerfile for running postgres integration tests.

docker build -t cray/hms-hmetcd-testing -f Dockerfile.testing .
### build-base stage ###
# Build base just has the packages installed we need.
FROM ghcr.io/orange-opensource/hurl:latest

# Copy all the necessary files to the image.
COPY test/ct/postgres /postgres

WORKDIR /postgres

# Run unit tests.
ENTRYPOINT ["/postgres/run.sh"]
92 changes: 92 additions & 0 deletions cmd/boot-script-service/boot_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,19 @@ func nidName(nid int) string {
func Remove(bp bssTypes.BootParams) error {
debugf("Remove(): Ready to remove %v\n", bp)
var err error
if useSQL {
var (
nodesDeleted []string
bcsDeleted []string
)
nodesDeleted, bcsDeleted, err = bssdb.Delete(bp)
if err != nil {
return err
}
debugf("Node IDs deleted: %v", nodesDeleted)
debugf("Boot Config IDs deleted: %v", bcsDeleted)
return err
}
for _, h := range bp.Hosts {
e := removeHost(h)
if err == nil {
Expand Down Expand Up @@ -340,6 +353,12 @@ func extractParamName(x hmetcd.Kvi_KV) (ret string) {
}

func StoreNew(bp bssTypes.BootParams) (error, string) {
// postgres.Add will handle duplicates, and it is called in New().
// Therefore, if Postgres is enabled, simply call Store().
if useSQL {
return Store(bp)
}

item := ""
// Go through the entire struct. We must be storing to new hosts or this
// request must fail.
Expand Down Expand Up @@ -393,6 +412,16 @@ func StoreNew(bp bssTypes.BootParams) (error, string) {
func Store(bp bssTypes.BootParams) (error, string) {
debugf("Store(%v)\n", bp)

if useSQL {
debugf("postgres.Add(%v)\n", bp)
result, err := bssdb.Add(bp)
if err != nil {
return err, ""
}
debugf("postgres.Add result: %v\n", result)
return err, uuid.New().String()
}

var kernel_id, initrd_id string
if bp.Kernel != "" {
kernel_id = imageStore(bp.Kernel, kernelImageType)
Expand Down Expand Up @@ -925,6 +954,27 @@ func LookupByName(name string) (BootData, SMComponent) {
comp_name = comp.ID
role = comp.Role
}
if useSQL {
var result BootData
bps, err := bssdb.GetBootParamsByName([]string{name})
if err != nil {
err = fmt.Errorf("Could not retrieve boot parameters with name %q: %v", name, err)
log.Printf("ERROR: %v", err)
return result, comp
}
if len(bps) == 0 {
// Not found.
log.Printf("WARNING: Name %q did not return any results.", name)
return result, comp
} else if len(bps) > 1 {
debugf("BootParams returned: %v", bps)
log.Printf("WARNING: More than 1 node found for name %q, taking first one: %v", name, bps[0])
}
result.Kernel = ImageData{bps[0].Kernel, ""}
result.Initrd = ImageData{bps[0].Initrd, ""}
result.Params = bps[0].Params
return result, comp
}
return lookup(comp_name, name, role, DefaultTag), comp
}

Expand All @@ -936,6 +986,27 @@ func LookupByMAC(mac string) (BootData, SMComponent) {
comp_name = comp.ID
role = comp.Role
}
if useSQL {
var result BootData
bps, err := bssdb.GetBootParamsByMac([]string{mac})
if err != nil {
err = fmt.Errorf("Could not retrieve boot parameters with mac %q: %v", mac, err)
log.Printf("ERROR: %v", err)
return result, comp
}
if len(bps) == 0 {
// Not found.
log.Printf("WARNING: MAC %q did not return any results.", mac)
return result, comp
} else if len(bps) > 1 {
debugf("BootParams returned: %v", bps)
log.Printf("WARNING: More than 1 node found for MAC %q, taking first one: %v", mac, bps[0])
}
result.Kernel = ImageData{bps[0].Kernel, ""}
result.Initrd = ImageData{bps[0].Initrd, ""}
result.Params = bps[0].Params
return result, comp
}
return lookup(comp_name, mac, role, DefaultTag), comp
}

Expand All @@ -948,6 +1019,27 @@ func LookupByNid(nid int) (BootData, SMComponent) {
comp_name = comp.ID
role = comp.Role
}
if useSQL {
var result BootData
bps, err := bssdb.GetBootParamsByNid([]int32{int32(nid)})
if err != nil {
err = fmt.Errorf("Could not retrieve boot parameters with NID %d: %v", nid, err)
log.Printf("ERROR: %v", err)
return result, comp
}
if len(bps) == 0 {
// Not found.
log.Printf("WARNING: NID %d did not return any results.", nid)
return result, comp
} else if len(bps) > 1 {
debugf("BootParams returned: %v", bps)
log.Printf("WARNING: More than 1 node found for NID %d, taking first one: %v", nid, bps[0])
}
result.Kernel = ImageData{bps[0].Kernel, ""}
result.Initrd = ImageData{bps[0].Initrd, ""}
result.Params = bps[0].Params
return result, comp
}
return lookup(comp_name, nid_str, role, DefaultTag), comp
}

Expand Down
Loading

0 comments on commit 0da5f71

Please sign in to comment.