Skip to content

Optionally enable the ecr credential helper plugin #763

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

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
1 change: 1 addition & 0 deletions packer/linux/conf/bin/bk-install-elastic-stack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ PLUGINS_ENABLED=()
[[ $SECRETS_PLUGIN_ENABLED == "true" ]] && PLUGINS_ENABLED+=("secrets")
[[ $ECR_PLUGIN_ENABLED == "true" ]] && PLUGINS_ENABLED+=("ecr")
[[ $DOCKER_LOGIN_PLUGIN_ENABLED == "true" ]] && PLUGINS_ENABLED+=("docker-login")
[[ ${ECR_CRED_HELPER_PLUGIN_ENABLED:-} == "true" ]] && PLUGINS_ENABLED+=("ecr-cred-helper")

# cfn-env is sourced by the environment hook in builds
cat << EOF > /var/lib/buildkite-agent/cfn-env
Expand Down
13 changes: 13 additions & 0 deletions packer/linux/conf/buildkite-agent/hooks/environment
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ source ~/cfn-env
BUILDKITE_DOCKER_CONFIG_TEMP_DIRECTORY=$(mktemp -d)
export BUILDKITE_DOCKER_CONFIG_TEMP_DIRECTORY
export DOCKER_CONFIG="$BUILDKITE_DOCKER_CONFIG_TEMP_DIRECTORY"
DOCKER_CONFIG_FILE="${DOCKER_CONFIG}/config.json"
# Write an empty docker config file
echo '{}' > $DOCKER_CONFIG_FILE

echo "~~~ :llama: Setting up elastic stack environment ($BUILDKITE_STACK_VERSION)"
cat ~/cfn-env
Expand Down Expand Up @@ -39,10 +42,12 @@ echo "Configuring built-in plugins"
[[ ! ${SECRETS_PLUGIN_ENABLED:-true} =~ (on|1|true) ]] && PLUGINS_ENABLED=${PLUGINS_ENABLED/secrets/}
[[ ! ${DOCKER_LOGIN_PLUGIN_ENABLED:-true} =~ (on|1|true) ]] && PLUGINS_ENABLED=${PLUGINS_ENABLED/docker-login/}
[[ ! ${ECR_PLUGIN_ENABLED:-true} =~ (on|1|true) ]] && PLUGINS_ENABLED=${PLUGINS_ENABLED/ecr/}
[[ ! ${ECR_CRED_HELPER_PLUGIN_ENABLED:-true} =~ (on|1|true) ]] && PLUGINS_ENABLED=${PLUGINS_ENABLED/ecr-cred-helper/}

SECRETS_PLUGIN_ENABLED=0
DOCKER_LOGIN_PLUGIN_ENABLED=0
ECR_PLUGIN_ENABLED=0
ECR_CRED_HELPER_PLUGIN_ENABLED=0

for plugin in $PLUGINS_ENABLED ; do
case "$plugin" in
Expand All @@ -58,9 +63,17 @@ for plugin in $PLUGINS_ENABLED ; do
export ECR_PLUGIN_ENABLED=1
echo "ECR plugin enabled"
;;
ecr-cred-helper)
export ECR_CRED_HELPER_PLUGIN_ENABLED=1
echo "ECR cred helper plugin enabled"
;;
esac
done

if [[ "${ECR_CRED_HELPER_PLUGIN_ENABLED:-}" == "1" ]] ; then
cat <<< "$(jq '."credsStore"="ecr-login"' $DOCKER_CONFIG_FILE)" > $DOCKER_CONFIG_FILE
fi

if [[ -n "${BUILDKITE_SECRETS_BUCKET:-}" && "${SECRETS_PLUGIN_ENABLED:-}" == "1" ]] ; then
export BUILDKITE_PLUGIN_S3_SECRETS_BUCKET="$BUILDKITE_SECRETS_BUCKET"

Expand Down
3 changes: 3 additions & 0 deletions packer/linux/scripts/install-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ sudo curl -Lsf -o /usr/bin/jq https://github.com/stedolan/jq/releases/download/j
sudo chmod +x /usr/bin/jq
jq --version

echo "Installing ecr credential helper..."
sudo amazon-linux-extras enable docker
sudo yum install -y amazon-ecr-credential-helper
10 changes: 10 additions & 0 deletions templates/aws-stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Metadata:
Parameters:
- EnableSecretsPlugin
- EnableECRPlugin
- EnableECRCredHelperPlugin
- EnableDockerLoginPlugin

Parameters:
Expand Down Expand Up @@ -341,6 +342,14 @@ Parameters:
- "false"
Default: "true"

EnableECRCredHelperPlugin:
Type: String
Description: Enables ecr credential helper plugin
AllowedValues:
- "true"
- "false"
Default: "false"

EnableDockerLoginPlugin:
Type: String
Description: Enables docker-login plugin for all pipelines
Expand Down Expand Up @@ -915,6 +924,7 @@ Resources:
AWS_DEFAULT_REGION=${AWS::Region} \
SECRETS_PLUGIN_ENABLED=${EnableSecretsPlugin} \
ECR_PLUGIN_ENABLED=${EnableECRPlugin} \
ECR_CRED_HELPER_PLUGIN_ENABLED=${EnableECRCredHelperPlugin} \
DOCKER_LOGIN_PLUGIN_ENABLED=${EnableDockerLoginPlugin} \
AWS_REGION=${AWS::Region} \
/usr/local/bin/bk-install-elastic-stack.sh
Expand Down