Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds multiarch builds for k8s http2 example #568

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions walkthroughs/howto-k8s-http2/color_client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
FROM public.ecr.aws/amazonlinux/amazonlinux:2 AS builder
RUN yum update -y && \
yum install -y ca-certificates unzip tar gzip git && \
yum clean all && \
rm -rf /var/cache/yum
FROM --platform=${BUILDPLATFORM} golang:1.20 as builder

RUN curl -LO https://golang.org/dl/go1.17.1.linux-amd64.tar.gz && \
tar -C /usr/local -xzvf go1.17.1.linux-amd64.tar.gz

ENV PATH="${PATH}:/usr/local/go/bin"
ENV GOPATH="${HOME}/go"
ENV PATH="${PATH}:${GOPATH}/bin"
WORKDIR /go/src/github.com/aws/aws-app-mesh-examples/walkthroughs/howto-http2/color_client

# Use the default go proxy
ARG GO_PROXY=https://proxy.golang.org

WORKDIR /go/src/github.com/aws/aws-app-mesh-examples/walkthroughs/howto-http2/color_client

# Set the proxies for the go compiler.
ENV GOPROXY=$GO_PROXY

# go.mod and go.sum go into their own layers.
# This ensures `go mod download` happens only when go.mod and go.sum change.
COPY go.mod .
COPY go.sum .
COPY go.mod go.sum ./
RUN go mod download

COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o /color_client .

ARG TARGETOS
ARG TARGETARCH

RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -installsuffix nocgo -o /color_client .

FROM public.ecr.aws/amazonlinux/amazonlinux:2
RUN yum update -y && \
Expand Down
24 changes: 8 additions & 16 deletions walkthroughs/howto-k8s-http2/color_server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
FROM public.ecr.aws/amazonlinux/amazonlinux:2 AS builder
RUN yum update -y && \
yum install -y ca-certificates unzip tar gzip git && \
yum clean all && \
rm -rf /var/cache/yum
FROM --platform=${BUILDPLATFORM} golang:1.20 as builder

RUN curl -LO https://golang.org/dl/go1.17.1.linux-amd64.tar.gz && \
tar -C /usr/local -xzvf go1.17.1.linux-amd64.tar.gz

ENV PATH="${PATH}:/usr/local/go/bin"
ENV GOPATH="${HOME}/go"
ENV PATH="${PATH}:${GOPATH}/bin"
WORKDIR /go/src/github.com/aws/aws-app-mesh-examples/walkthroughs/howto-http2/color_server

# Use the default go proxy
ARG GO_PROXY=https://proxy.golang.org

WORKDIR /go/src/github.com/aws/aws-app-mesh-examples/walkthroughs/howto-http2/color_server

# Set the proxies for the go compiler.
ENV GOPROXY=$GO_PROXY

# go.mod and go.sum go into their own layers.
# This ensures `go mod download` happens only when go.mod and go.sum change.
COPY go.mod .
COPY go.sum .
COPY go.mod go.sum ./
RUN go mod download

COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o /color_server .

ARG TARGETOS
ARG TARGETARCH

RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -installsuffix nocgo -o /color_server .

FROM public.ecr.aws/amazonlinux/amazonlinux:2
RUN yum update -y && \
Expand Down
21 changes: 17 additions & 4 deletions walkthroughs/howto-k8s-http2/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ MESH_NAME=${PROJECT_NAME}
CLOUDMAP_NAMESPACE="${APP_NAMESPACE}.svc.cluster.local"
ECR_URL="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
ECR_IMAGE_PREFIX="${ECR_URL}/${PROJECT_NAME}"
CLIENT_APP_IMAGE="${ECR_IMAGE_PREFIX}/color_client"
COLOR_APP_IMAGE="${ECR_IMAGE_PREFIX}/color_server"
CLIENT_APP_IMAGE="${ECR_IMAGE_PREFIX}/color_client:latest"
COLOR_APP_IMAGE="${ECR_IMAGE_PREFIX}/color_server:latest"
MANIFEST_VERSION="${1:-v1beta2}"
AWS_CLI_VERSION=$(aws --version 2>&1 | cut -d/ -f2 | cut -d. -f1)

Expand Down Expand Up @@ -83,8 +83,21 @@ deploy_images() {
ecr_login
for app in color_client color_server; do
aws ecr describe-repositories --repository-name $PROJECT_NAME/$app >/dev/null 2>&1 || aws ecr create-repository --repository-name $PROJECT_NAME/$app >/dev/null
docker build -t ${ECR_IMAGE_PREFIX}/${app} ${DIR}/${app} --build-arg GO_PROXY=${GO_PROXY:-"https://proxy.golang.org"}
docker push ${ECR_IMAGE_PREFIX}/${app}

# performs a multiarch build and deploy if cross-build tools are
# available. Otherwise, builds on the current architecture.
docker image rm "${ECR_IMAGE_PREFIX}/${app}:latest" 1>/dev/null 2>/dev/null || :
missing_buildx=`docker buildx version 1>/dev/null 2>/dev/null; echo $?`
if [[ "$missing_buildx" -eq "0" ]]; then
docker manifest rm "${ECR_IMAGE_PREFIX}/${app}:latest" 1>/dev/null 2>/dev/null || :
docker buildx build --platform linux/amd64 -t "${ECR_IMAGE_PREFIX}/${app}:latest-linux_amd64" ${DIR}/${app} --build-arg GO_PROXY=${GO_PROXY:-"https://proxy.golang.org"} --push
docker buildx build --platform linux/arm64 -t "${ECR_IMAGE_PREFIX}/${app}:latest-linux_arm64" ${DIR}/${app} --build-arg GO_PROXY=${GO_PROXY:-"https://proxy.golang.org"} --push
docker manifest create "${ECR_IMAGE_PREFIX}/${app}:latest" "${ECR_IMAGE_PREFIX}/${app}:latest-linux_amd64" "${ECR_IMAGE_PREFIX}/${app}:latest-linux_arm64"
docker manifest push "${ECR_IMAGE_PREFIX}/${app}:latest"
else
docker build -t "${ECR_IMAGE_PREFIX}/${app}:latest" ${DIR}/${app} --build-arg GO_PROXY=${GO_PROXY:-"https://proxy.golang.org"}
docker push "${ECR_IMAGE_PREFIX}/${app}:latest"
fi
done
}

Expand Down