Skip to content

Commit

Permalink
build: update for multiarchitecture builds
Browse files Browse the repository at this point in the history
updated dockerfile for tools and build workflow to create architecture specfiic images
separated the installation of upx due to package availability

Signed-off-by: Ben Stickel <ben.stickel@elastic.co>
  • Loading branch information
fin09pcap committed Dec 5, 2024
1 parent 94bfd9d commit b46c31d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
19 changes: 10 additions & 9 deletions build/mage/docker/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ RUN set -eux; \
# Compress binaries
RUN set -eux; \
upx -9 bin/* && \
chmod +x bin/*
upx -9 bin/{{.Cmd.Kebab}}-linux-{{.GoArchitecture}} && \
chmod +x bin/{{.Cmd.Kebab}}-linux-{{.GoArchitecture}}
## -------------------------------------------------------------------------------------------------
Expand All @@ -104,9 +104,9 @@ LABEL \
org.opencontainers.image.licences="ASL2"
{{ if .Cmd.HasModule }}
COPY --from=compiler /go/src/workspace/{{.Cmd.Module}}/bin/{{.Cmd.Kebab}}-linux-amd64 /usr/bin/{{.Cmd.Kebab}}
COPY --from=compiler /go/src/workspace/{{.Cmd.Module}}/bin/{{.Cmd.Kebab}}-linux-{{.GoArchitecture}} usr/bin/{{.Cmd.Kebab}}
{{ else }}
COPY --from=compiler /go/src/workspace/bin/{{.Cmd.Kebab}}-linux-amd64 /usr/bin/{{.Cmd.Kebab}}
COPY --from=compiler /go/src/workspace/bin/{{.Cmd.Kebab}}-linux-{{.GoArchitecture}} /usr/bin/{{.Cmd.Kebab}}
{{ end }}
COPY --from=compiler /tmp/group /tmp/passwd /etc/
Expand All @@ -131,11 +131,12 @@ func Build(cmd *artifact.Command) func() error {
}

buf, err := merge(dockerTemplate, map[string]interface{}{
"ToolImageName": toolImageName,
"BuildDate": time.Now().Format(time.RFC3339),
"Version": git.Tag,
"VcsRef": git.Revision,
"Cmd": cmd,
"ToolImageName": toolImageName,
"GoArchitecture": goArchitecture,
"BuildDate": time.Now().Format(time.RFC3339),
"Version": git.Tag,
"VcsRef": git.Revision,
"Cmd": cmd,
})
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions build/mage/docker/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@

package docker

import "runtime"

const (
// Standard build mode
golangImage = "golang:1.23.2"
golangVersion = "1.23.2"
goBoringVersion = "1.17.5b7"
toolImage = "elastic/harp-tools:latest"
goArchitecture = runtime.GOARCH
upxVersion = "4.2.4"
)
14 changes: 10 additions & 4 deletions build/mage/docker/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,19 @@ LABEL \
{{ if .OverrideGoBoringVersion }}
# Override goboring version
RUN wget https://storage.googleapis.com/go-boringcrypto/go{{ .GoBoringVersion }}.linux-amd64.tar.gz \
&& rm -rf /usr/local/go && tar -C /usr/local -xzf go{{ .GoBoringVersion }}.linux-amd64.tar.gz \
&& rm go{{ .GoBoringVersion }}.linux-amd64.tar.gz
RUN wget https://storage.googleapis.com/go-boringcrypto/go{{ .GoBoringVersion }}.linux-{{.GoArchitecture}}.tar.gz \
&& rm -rf /usr/local/go && tar -C /usr/local -xzf go{{ .GoBoringVersion }}.linux-{{.GoArchitecture}}.tar.gz \
&& rm go{{ .GoBoringVersion }}.linux-{{.GoArchitecture}}.tar.gz
{{ end }}
# hadolint ignore=DL3008
RUN set -eux; \
apt-get update -y && \
apt-get install -y --no-install-recommends apt-utils bzr upx zip unzip;
apt-get install -y --no-install-recommends apt-utils bzr zip unzip xz-utils;
RUN wget https://github.com/upx/upx/releases/download/v{{.UpxVersion}}/upx-{{.UpxVersion}}-{{.GoArchitecture}}_linux.tar.xz -o - \
&& tar -xJf upx-{{.UpxVersion}}-{{.GoArchitecture}}_linux.tar.xz \
&& mv upx-{{.UpxVersion}}-{{.GoArchitecture}}_linux/upx /usr/local/bin/upx
RUN go version
Expand Down Expand Up @@ -174,9 +178,11 @@ func Tools() error {
"VcsRef": git.Revision,
"GolangImage": golangBaseImage,
"GolangVersion": golangVersion,
"GoArchitecture": goArchitecture,
"OverrideGoBoringVersion": overrideGoBoringVersion,
"GoBoringVersion": goBoringVersion,
"FIPSMode": fipsMode,
"UpxVersion": upxVersion,
})
if err != nil {
return err
Expand Down

0 comments on commit b46c31d

Please sign in to comment.