From 24d9dd94ceaf17c06270f0651af7dbf84ea6ce4a Mon Sep 17 00:00:00 2001 From: Mythri Garaga Manjunatha Date: Thu, 22 Oct 2020 09:16:40 -0700 Subject: [PATCH] modify Makefile to use different Golang version while building Agent for Windows --- Makefile | 23 +++++++++++++++---- scripts/dockerfiles/Dockerfile.build | 3 ++- .../dockerfiles/Dockerfile.buildECSCNIPlugins | 3 ++- .../dockerfiles/Dockerfile.buildVPCCNIPlugins | 3 ++- scripts/dockerfiles/Dockerfile.cleanbuild | 3 ++- scripts/dockerfiles/Dockerfile.test | 5 +++- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index b0810e191f9..19c424ab925 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,12 @@ else GOARCH=amd64 endif +ifeq (${TARGET_OS},windows) + GO_VERSION=1.12 +else + GO_VERSION=1.15 +endif + all: docker # Dynamic go build; useful in that it does not have -a so it won't recompile @@ -47,7 +53,7 @@ xplatform-build: BUILDER_IMAGE="amazon/amazon-ecs-agent-build:make" .builder-image-stamp: scripts/dockerfiles/Dockerfile.build - @docker build -f scripts/dockerfiles/Dockerfile.build -t $(BUILDER_IMAGE) . + @docker build --build-arg GO_VERSION=$(GO_VERSION) -f scripts/dockerfiles/Dockerfile.build -t $(BUILDER_IMAGE) . touch .builder-image-stamp # 'build-in-docker' builds the agent within a dockerfile and saves it to the ./out @@ -71,11 +77,17 @@ docker: certs build-in-docker pause-container-release cni-plugins .out-stamp @docker build -f scripts/dockerfiles/Dockerfile.release -t "amazon/amazon-ecs-agent:make" . @echo "Built Docker image \"amazon/amazon-ecs-agent:make\"" +ifeq (${TARGET_OS},windows) + BUILD="cleanbuild-${TARGET_OS}" +else + BUILD=cleanbuild +endif + # 'docker-release' builds the agent from a clean snapshot of the git repo in # 'RELEASE' mode # TODO: make this idempotent docker-release: pause-container-release cni-plugins .out-stamp - @docker build -f scripts/dockerfiles/Dockerfile.cleanbuild -t "amazon/amazon-ecs-agent-cleanbuild:make" . + @docker build --build-arg GO_VERSION=${GO_VERSION} -f scripts/dockerfiles/Dockerfile.cleanbuild -t "amazon/amazon-ecs-agent-${BUILD}:make" . @docker run --net=none \ --env TARGET_OS="${TARGET_OS}" \ --env LDFLAGS="-X github.com/aws/amazon-ecs-agent/agent/config.DefaultPauseContainerTag=$(PAUSE_CONTAINER_TAG) \ @@ -84,7 +96,7 @@ docker-release: pause-container-release cni-plugins .out-stamp --volume "$(PWD)/out:/out" \ --volume "$(PWD):/src/amazon-ecs-agent" \ --rm \ - "amazon/amazon-ecs-agent-cleanbuild:make" + "amazon/amazon-ecs-agent-${BUILD}:make" # Release packages our agent into a "scratch" based dockerfile release: certs docker-release @@ -181,7 +193,7 @@ get-cni-sources: git submodule update --init --recursive build-ecs-cni-plugins: - @docker build -f scripts/dockerfiles/Dockerfile.buildECSCNIPlugins -t "amazon/amazon-ecs-build-ecs-cni-plugins:make" . + @docker build --build-arg GO_VERSION=$(GO_VERSION) -f scripts/dockerfiles/Dockerfile.buildECSCNIPlugins -t "amazon/amazon-ecs-build-ecs-cni-plugins:make" . docker run --rm --net=none \ -e GIT_SHORT_HASH=$(shell cd $(ECS_CNI_REPOSITORY_SRC_DIR) && git rev-parse --short=8 HEAD) \ -e GIT_PORCELAIN=$(shell cd $(ECS_CNI_REPOSITORY_SRC_DIR) && git status --porcelain 2> /dev/null | wc -l | sed 's/^ *//') \ @@ -192,7 +204,7 @@ build-ecs-cni-plugins: @echo "Built amazon-ecs-cni-plugins successfully." build-vpc-cni-plugins: - @docker build --build-arg GOARCH=$(GOARCH) -f scripts/dockerfiles/Dockerfile.buildVPCCNIPlugins -t "amazon/amazon-ecs-build-vpc-cni-plugins:make" . + @docker build --build-arg GOARCH=$(GOARCH) --build-arg GO_VERSION=$(GO_VERSION) -f scripts/dockerfiles/Dockerfile.buildVPCCNIPlugins -t "amazon/amazon-ecs-build-vpc-cni-plugins:make" . docker run --rm --net=none \ -e GIT_SHORT_HASH=$(shell cd $(VPC_CNI_REPOSITORY_SRC_DIR) && git rev-parse --short=8 HEAD) \ -u "$(USERID)" \ @@ -331,6 +343,7 @@ clean: # ensure docker is running and we can talk to it, abort if not: docker ps > /dev/null -docker rmi $(BUILDER_IMAGE) "amazon/amazon-ecs-agent-cleanbuild:make" + -docker rmi $(BUILDER_IMAGE) "amazon/amazon-ecs-agent-cleanbuild-windows:make" rm -f misc/certs/ca-certificates.crt &> /dev/null rm -rf out/ -$(MAKE) -C $(ECS_CNI_REPOSITORY_SRC_DIR) clean diff --git a/scripts/dockerfiles/Dockerfile.build b/scripts/dockerfiles/Dockerfile.build index f694d8d5f83..0c29394fbc0 100644 --- a/scripts/dockerfiles/Dockerfile.build +++ b/scripts/dockerfiles/Dockerfile.build @@ -11,7 +11,8 @@ # express or implied. See the License for the specific language governing # permissions and limitations under the License. -FROM golang:1.12 +ARG GO_VERSION +FROM golang:${GO_VERSION} MAINTAINER Amazon Web Services, Inc. ENV XDG_CACHE_HOME /tmp diff --git a/scripts/dockerfiles/Dockerfile.buildECSCNIPlugins b/scripts/dockerfiles/Dockerfile.buildECSCNIPlugins index 9af2e0cce41..1af3d087b86 100644 --- a/scripts/dockerfiles/Dockerfile.buildECSCNIPlugins +++ b/scripts/dockerfiles/Dockerfile.buildECSCNIPlugins @@ -11,7 +11,8 @@ # express or implied. See the License for the specific language governing # permissions and limitations under the License. -FROM golang:1.15 +ARG GO_VERSION +FROM golang:${GO_VERSION} MAINTAINER Amazon Web Services, Inc. ENV XDG_CACHE_HOME /tmp diff --git a/scripts/dockerfiles/Dockerfile.buildVPCCNIPlugins b/scripts/dockerfiles/Dockerfile.buildVPCCNIPlugins index ecebc01996a..7551e6e17d0 100644 --- a/scripts/dockerfiles/Dockerfile.buildVPCCNIPlugins +++ b/scripts/dockerfiles/Dockerfile.buildVPCCNIPlugins @@ -11,7 +11,8 @@ # express or implied. See the License for the specific language governing # permissions and limitations under the License. -FROM golang:1.15 +ARG GO_VERSION +FROM golang:${GO_VERSION} MAINTAINER Amazon Web Services, Inc. ARG GOARCH diff --git a/scripts/dockerfiles/Dockerfile.cleanbuild b/scripts/dockerfiles/Dockerfile.cleanbuild index a43a399c436..7302444e19f 100644 --- a/scripts/dockerfiles/Dockerfile.cleanbuild +++ b/scripts/dockerfiles/Dockerfile.cleanbuild @@ -11,7 +11,8 @@ # express or implied. See the License for the specific language governing # permissions and limitations under the License. -FROM golang:1.15 +ARG GO_VERSION +FROM golang:${GO_VERSION} MAINTAINER Amazon Web Services, Inc. ENV XDG_CACHE_HOME /tmp diff --git a/scripts/dockerfiles/Dockerfile.test b/scripts/dockerfiles/Dockerfile.test index 11bc3de246e..242b508e7d5 100644 --- a/scripts/dockerfiles/Dockerfile.test +++ b/scripts/dockerfiles/Dockerfile.test @@ -17,6 +17,7 @@ # Because the Agent's tests include starting docker containers, it is necessary # to have both go and docker available in the testing environment. # It's easier to get go, so start with docker-in-docker and add go on top + FROM jpetazzo/dind MAINTAINER Amazon Web Services, Inc. @@ -32,7 +33,9 @@ RUN apt-get update && apt-get install -y \ --no-install-recommends \ && rm -rf /var/lib/apt/lists/* -ENV GOLANG_VERSION 1.15 +ARG GO_VERSION=1.15 + +ENV GOLANG_VERSION ${GO_VERSION} ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz ENV GOLANG_DOWNLOAD_SHA256 d7d1f1f88ddfe55840712dc1747f37a790cbcaa448f6c9cf51bbe10aa65442f5