Skip to content

Commit

Permalink
Build images to work with the BEL autoregistration harness
Browse files Browse the repository at this point in the history
Signed-off-by: Flynn <[email protected]>
  • Loading branch information
kflynn committed May 16, 2024
1 parent 123709f commit 1e9deb2
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 2 deletions.
46 changes: 46 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ version: 1
env:
- REGISTRY={{ if index .Env "REGISTRY" }}{{ .Env.REGISTRY }}{{ else }}ghcr.io/buoyantio{{ end }}
- IMAGE_NAME={{ if index .Env "IMAGE_NAME" }}{{ .Env.IMAGE_NAME }}{{ else }}faces{{ end }}
- EXTERNAL_BASE={{ if index .Env "EXTERNAL_BASE" }}{{ .Env.EXTERNAL_BASE }}{{ else }}ghcr.io/buoyantio/demo-external-base:0.3.0{{ end }}
- BEL_EXTERNAL_BASE={{ if index .Env "BEL_EXTERNAL_BASE" }}{{ .Env.BEL_EXTERNAL_BASE }}{{ else }}ghcr.io/buoyantio/demo-bel-external-base:0.3.0{{ end }}

before:
hooks:
Expand Down Expand Up @@ -121,6 +123,7 @@ dockers:
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}-external-workload:latest-arm64"
build_flag_templates:
- "--platform=linux/arm64"
- "--build-arg=EXTERNAL_BASE={{ .Env.EXTERNAL_BASE }}"
- use: buildx
goos: linux
goarch: amd64
Expand All @@ -132,6 +135,31 @@ dockers:
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}-external-workload:latest-amd64"
build_flag_templates:
- "--platform=linux/amd64"
- "--build-arg=EXTERNAL_BASE={{ .Env.EXTERNAL_BASE }}"
- use: buildx
goos: linux
goarch: arm64
dockerfile: Dockerfiles/Dockerfile.bel-external-workload
ids:
- generic
image_templates:
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}-bel-external-workload:{{ .Version }}-arm64"
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}-bel-external-workload:latest-arm64"
build_flag_templates:
- "--platform=linux/arm64"
- "--build-arg=EXTERNAL_BASE={{ .Env.BEL_EXTERNAL_BASE }}"
- use: buildx
goos: linux
goarch: amd64
dockerfile: Dockerfiles/Dockerfile.bel-external-workload
ids:
- generic
image_templates:
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}-bel-external-workload:{{ .Version }}-amd64"
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}-bel-external-workload:latest-amd64"
build_flag_templates:
- "--platform=linux/amd64"
- "--build-arg=EXTERNAL_BASE={{ .Env.BEL_EXTERNAL_BASE }}"

# For the Pi, we only build an external-workload image for arm64. The Pi itself
# is arm64, so there's no point in building for amd64, and we're not going to try
Expand All @@ -152,6 +180,24 @@ dockers:
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}-pi-workload:latest"
build_flag_templates:
- "--platform=linux/arm64"
- "--build-arg=EXTERNAL_BASE={{ .Env.EXTERNAL_BASE }}"
- use: buildx
goos: linux
goarch: arm64
# Not a typo! We really do use the same Dockerfile as the generic external
# workload, we're just copying in our workload binary from the Pi build
# rather than the generic build.
dockerfile: Dockerfiles/Dockerfile.bel-external-workload
ids:
- pi
image_templates:
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}-bel-pi-workload:{{ .Version }}-arm64"
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}-bel-pi-workload:latest-arm64"
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}-bel-pi-workload:{{ .Version }}"
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}-bel-pi-workload:latest"
build_flag_templates:
- "--platform=linux/arm64"
- "--build-arg=EXTERNAL_BASE={{ .Env.BEL_EXTERNAL_BASE }}"

docker_manifests:
- name_template: "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}-gui:{{ .Version }}"
Expand Down
29 changes: 29 additions & 0 deletions Dockerfiles/Dockerfile.bel-external-workload
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
#
# SPDX-FileCopyrightText: 2022 Buoyant Inc.
# SPDX-License-Identifier: Apache-2.0
#
# Copyright 2022-2024 Buoyant Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

ARG EXTERNAL_BASE=you-must-set-the-external-base-arg

# Build over the external-workload base image.
FROM $EXTERNAL_BASE AS final

# This is associated with the faces-demo repo.
LABEL org.opencontainers.image.source=https://github.com/BuoyantIO/faces-demo

# Copy the compiled binary from the builder stage into the final image
COPY --chmod=0755 workload /workload/start
4 changes: 2 additions & 2 deletions Dockerfiles/Dockerfile.external-workload
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

ARG BASE=ghcr.io/buoyantio/demo-external-base:0.2.0
ARG EXTERNAL_BASE=you-must-set-the-external-base-arg

# Build over the external-workload base image.
FROM $BASE AS final
FROM $EXTERNAL_BASE AS final

# This is associated with the faces-demo repo.
LABEL org.opencontainers.image.source=https://github.com/BuoyantIO/faces-demo
Expand Down
10 changes: 10 additions & 0 deletions pkg/faces/baseserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func (srv *BaseServer) SetupFromEnvironment() {
}

srv.RegisterCustom("/rl", srv.rlGetHandler)
srv.RegisterCustom("/ready", srv.readyHandler)

srv.userHeaderName = utils.StringFromEnv("USER_HEADER_NAME", "X-Faces-User")
srv.hostIP = utils.StringFromEnv("HOST_IP", utils.StringFromEnv("HOSTNAME", "unknown"))
Expand Down Expand Up @@ -350,6 +351,15 @@ func (srv *BaseServer) rlGetHandler(w http.ResponseWriter, r *http.Request) {
})
}

func (srv *BaseServer) readyHandler(w http.ResponseWriter, r *http.Request) {
srv.StandardResponse(w, r, &BaseServerResponse{
StatusCode: http.StatusOK,
Data: map[string]interface{}{
"ready": true,
},
})
}

func (srv *BaseServer) standardGetHandler(w http.ResponseWriter, r *http.Request, userFunc BaseServerHandler) {
start := time.Now()

Expand Down

0 comments on commit 1e9deb2

Please sign in to comment.