Skip to content

Commit

Permalink
Following changes have been made in this commit -
Browse files Browse the repository at this point in the history
1. The pause container image name and tag have been moved to Makefile
2. The corresponding config is populated using loader flags at build time.
This is similar to how Linux agent populates these values
3. Formatting changes
4. Modified the Readme
  • Loading branch information
Harsh Rawat committed Jul 2, 2020
1 parent 138df14 commit b89935a
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 21 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ build-in-docker: .builder-image-stamp .out-stamp
--env TARGET_OS="${TARGET_OS}" \
--env LDFLAGS="-X github.com/aws/amazon-ecs-agent/agent/config.DefaultPauseContainerTag=$(PAUSE_CONTAINER_TAG) \
-X github.com/aws/amazon-ecs-agent/agent/config.DefaultPauseContainerImageName=$(PAUSE_CONTAINER_IMAGE)" \
--env LDFLAGS_WINDOWS="-X github.com/aws/amazon-ecs-agent/agent/config.DefaultPauseContainerTag=$(PAUSE_CONTAINER_TAG_WINDOWS) \
-X github.com/aws/amazon-ecs-agent/agent/config.DefaultPauseContainerImageName=$(PAUSE_CONTAINER_IMAGE_WINDOWS)" \
--volume "$(PWD)/out:/out" \
--volume "$(PWD):/go/src/github.com/aws/amazon-ecs-agent" \
--user "$(USERID)" \
Expand All @@ -80,6 +82,8 @@ docker-release: pause-container-release cni-plugins .out-stamp
--env TARGET_OS="${TARGET_OS}" \
--env LDFLAGS="-X github.com/aws/amazon-ecs-agent/agent/config.DefaultPauseContainerTag=$(PAUSE_CONTAINER_TAG) \
-X github.com/aws/amazon-ecs-agent/agent/config.DefaultPauseContainerImageName=$(PAUSE_CONTAINER_IMAGE)" \
--env LDFLAGS_WINDOWS="-X github.com/aws/amazon-ecs-agent/agent/config.DefaultPauseContainerTag=$(PAUSE_CONTAINER_TAG_WINDOWS) \
-X github.com/aws/amazon-ecs-agent/agent/config.DefaultPauseContainerImageName=$(PAUSE_CONTAINER_IMAGE_WINDOWS)" \
--user "$(USERID)" \
--volume "$(PWD)/out:/out" \
--volume "$(PWD):/src/amazon-ecs-agent" \
Expand Down Expand Up @@ -155,6 +159,8 @@ replicate-images: build-image-for-ecr
PAUSE_CONTAINER_IMAGE = "amazon/amazon-ecs-pause"
PAUSE_CONTAINER_TAG = "0.1.0"
PAUSE_CONTAINER_TARBALL = "amazon-ecs-pause.tar"
PAUSE_CONTAINER_IMAGE_WINDOWS = "amazonaws.com/ecs/pause-windows"
PAUSE_CONTAINER_TAG_WINDOWS = "latest"

pause-container: .out-stamp
@docker build -f scripts/dockerfiles/Dockerfile.buildPause -t "amazon/amazon-ecs-build-pause-bin:make" .
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ The following targets are available. Each may be run with `make <target>`.

### Standalone (on Windows)

The Amazon ECS Container Agent may be built by typing `go build -o amazon-ecs-agent.exe ./agent`.
The Amazon ECS Container Agent may be built by invoking `scripts\build_agent.ps1`

### Scripts (on Windows)

Expand Down
4 changes: 2 additions & 2 deletions agent/app/agent_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ func (agent *ecsAgent) getPlatformDevices() []*ecs.PlatformDevice {
}

func (agent *ecsAgent) loadPauseContainer() error {
//The pause image would be cached in th ECS-Optimized Windows AMI's and will be available. We will throw an error if the image is not loaded.
//If the agent is run on non-supported instances then pause image has to be loaded manually by the client.
// The pause image would be cached in th ECS-Optimized Windows AMI's and will be available. We will throw an error if the image is not loaded.
// If the agent is run on non-supported instances then pause image has to be loaded manually by the client.
_, err := agent.pauseLoader.IsLoaded(agent.dockerClient)

return err
Expand Down
3 changes: 1 addition & 2 deletions agent/config/config_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ func DefaultConfig() Config {
programData := utils.DefaultIfBlank(os.Getenv("ProgramData"), `C:\ProgramData`)
ecsRoot := filepath.Join(programData, "Amazon", "ECS")
dataDir := filepath.Join(ecsRoot, "data")
DefaultPauseContainerImageName = "amazonaws.com/ecs/pause-windows"
DefaultPauseContainerTag = "latest"

platformVariables := PlatformVariables{
CPUUnbounded: false,
MemoryUnbounded: false,
Expand Down
8 changes: 4 additions & 4 deletions agent/eni/pause/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package pause
import (
"context"
"fmt"

"github.com/aws/amazon-ecs-agent/agent/config"
"github.com/aws/amazon-ecs-agent/agent/dockerclient/dockerapi"
log "github.com/cihub/seelog"
Expand All @@ -37,7 +38,7 @@ func New() Loader {
return &loader{}
}

//This function uses the DockerClient to inspect the image with the given name and tag.
// This function uses the DockerClient to inspect the image with the given name and tag.
func getPauseContainerImage(name string, tag string, dockerClient dockerapi.DockerClient) (*types.ImageInspect, error) {
imageName := fmt.Sprintf("%s:%s", name, tag)
log.Debugf("Inspecting pause container image: %s", imageName)
Expand All @@ -51,14 +52,13 @@ func getPauseContainerImage(name string, tag string, dockerClient dockerapi.Dock
return image, nil
}

//Common function for linux and windows to check if the container pause image has been loaded
// Common function for linux and windows to check if the container pause image has been loaded
func isImageLoaded(dockerClient dockerapi.DockerClient) (bool, error) {
image, err := getPauseContainerImage(
config.DefaultPauseContainerImageName, config.DefaultPauseContainerTag, dockerClient)

if err != nil {
return false, errors.Wrapf(err,
"pause container inspect: failed to inspect image: %s", config.DefaultPauseContainerImageName)
return false, err
}

if image == nil || image.ID == "" {
Expand Down
2 changes: 1 addition & 1 deletion agent/eni/pause/pause_unsupported.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !linux, !windows
// +build !linux,!windows

// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
Expand Down
5 changes: 4 additions & 1 deletion agent/eni/pause/pause_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ import (
"github.com/pkg/errors"
)

// In Linux, we use a tar archive to load the pause image. Whereas in Windows, we will cache the image during AMI build.
// Therefore, this functionality is not supported in Windows.
func (*loader) LoadImage(ctx context.Context, cfg *config.Config, dockerClient dockerapi.DockerClient) (*types.ImageInspect, error) {
return nil, errors.New("This functionality is not supported on this platform.")
return nil, errors.New("this functionality is not supported on this platform.")
}

// This method is used to inspect the presence of the pause image. If the image has not been loaded then we return false.
func (*loader) IsLoaded(dockerClient dockerapi.DockerClient) (bool, error) {
return isImageLoaded(dockerClient)
}
22 changes: 12 additions & 10 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ ROOT=$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )
cd "${ROOT}"

if [[ "${version_gen}" == "true" ]]; then
# Versioning stuff. We run the generator to setup the version and then always
# restore ourselves to a clean state
cp agent/version/version.go agent/version/_version.go
trap "cd \"${ROOT}\"; mv agent/version/_version.go agent/version/version.go" EXIT SIGHUP SIGINT SIGTERM
# Versioning stuff. We run the generator to setup the version and then always
# restore ourselves to a clean state
cp agent/version/version.go agent/version/_version.go
trap "cd \"${ROOT}\"; mv agent/version/_version.go agent/version/version.go" EXIT SIGHUP SIGINT SIGTERM

cd ./agent/version/
go run gen/version-gen.go
cd ./agent/version/
go run gen/version-gen.go
fi

if [ "${TARGET_OS}" == "windows" ]; then
Expand All @@ -49,12 +49,14 @@ else
fi

cd "${ROOT}"
if [[ "${static}" == "true" ]]; then
CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "${LDFLAGS} -s" -o $build_exe ./agent/
if [[ "${TARGET_OS}" == "windows" ]]; then
go build -ldflags "${LDFLAGS_WINDOWS} -s" -o $build_exe ./agent/
elif [[ "${static}" == "true" ]]; then
CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "${LDFLAGS} -s" -o $build_exe ./agent/
else
go build -o $build_exe ./agent/
go build -o $build_exe ./agent/
fi

if [[ -n "${output_directory}" ]]; then
mv $build_exe "${output_directory}"
mv $build_exe "${output_directory}"
fi
23 changes: 23 additions & 0 deletions scripts/build_agent.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may
# not use this file except in compliance with the License. A copy of the
# License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file 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.
#
# Standalone Amazon ECS Container Agent for Windows may be built by using this script

$pauseImageName = "amazonaws.com/ecs/pause-windows"
$pauseImageTag = "latest"

$build_exe = "../amazon-ecs-agent.exe"
$ldflag = "-X github.com/aws/amazon-ecs-agent/agent/config.DefaultPauseContainerTag=$pauseImageTag -X github.com/aws/amazon-ecs-agent/agent/config.DefaultPauseContainerImageName=$pauseImageName"


go build -ldflags "$ldflag" -o $build_exe ../agent/

0 comments on commit b89935a

Please sign in to comment.