-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #352 from spotahome/build
Add cross architecture docker builds
- Loading branch information
Showing
3 changed files
with
57 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
FROM golang:1.17-alpine | ||
FROM --platform=$BUILDPLATFORM golang:1.17-alpine AS build | ||
RUN apk --no-cache add \ | ||
bash | ||
|
||
WORKDIR /go/src/github.com/spotahome/redis-operator | ||
WORKDIR /src | ||
COPY . . | ||
RUN ./scripts/build.sh | ||
|
||
ARG TARGETOS TARGETARCH VERSION | ||
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH VERSION=$VERSION ./scripts/build.sh | ||
|
||
FROM alpine:latest | ||
RUN apk --no-cache add \ | ||
ca-certificates | ||
COPY --from=0 /go/src/github.com/spotahome/redis-operator/bin/linux/redis-operator /usr/local/bin | ||
COPY --from=build /src/bin/redis-operator /usr/local/bin | ||
RUN addgroup -g 1000 rf && \ | ||
adduser -D -u 1000 -G rf rf && \ | ||
chown rf:rf /usr/local/bin/redis-operator | ||
adduser -D -u 1000 -G rf rf && \ | ||
chown rf:rf /usr/local/bin/redis-operator | ||
USER rf | ||
|
||
ENTRYPOINT ["/usr/local/bin/redis-operator"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
#!/bin/sh | ||
#!/usr/bin/env bash | ||
|
||
export CGO_ENABLED=0 | ||
export GOOS=linux | ||
export GO111MODULE=on | ||
set -o errexit | ||
set -o nounset | ||
|
||
go build -ldflags '-extldflags "-static"' -a -v -o bin/linux/redis-operator ./cmd/redisoperator/ | ||
src=./cmd/redisoperator | ||
out=./bin/redis-operator | ||
|
||
if [[ ! -z ${TARGETOS} ]] && [[ ! -z ${TARGETARCH} ]]; | ||
then | ||
echo "Building ${TARGETOS}/${TARGETARCH} release..." | ||
export GOOS=${TARGETOS} | ||
export GOARCH=${TARGETARCH} | ||
binary_ext=-${TARGETOS}-${TARGETARCH} | ||
else | ||
echo "Building native release..." | ||
fi | ||
|
||
final_out=${out}${binary_ext} | ||
ldf_cmp="-w -extldflags '-static'" | ||
f_ver="-X main.Version=${VERSION:-dev}" | ||
|
||
echo "Building binary at ${out}" | ||
CGO_ENABLED=0 go build -o ${out} --ldflags "${ldf_cmp} ${f_ver}" ${src} |