diff --git a/.circleci/config.yml b/.circleci/config.yml index 422565c..c22871d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,196 +1,36 @@ version: 2.1 - +setup: true orbs: - orb-tools: circleci/orb-tools@10.0 - shellcheck: circleci/shellcheck@2.0 - aws-cli: circleci/aws-cli@<> - -# Pipeline Parameters -## These parameters are used internally by orb-tools. Skip to the Jobs section. -parameters: - run-integration-tests: - description: An internal flag to prevent integration test from running before a development version has been created. - type: boolean - default: false - dev-orb-version: - description: > - The development version of the orb to test. - This value is automatically adjusted by the "trigger-integration-tests-workflow" job to correspond with the specific version created by the commit and should not be edited. - A "dev:alpha" version must exist for the initial pipeline run. - type: string - default: "dev:alpha" - -executors: - docker-base: - docker: - - image: cimg/base:stable - macos: - macos: - xcode: 12.4.0 - arm: - machine: - image: ubuntu-2004:202101-01 - resource_class: arm.medium - linuxvm: - machine: - image: ubuntu-2004:202101-01 -commands: - check_aws_version: - parameters: - version: - type: string - default: "" - steps: - - run: - name: check_aws_version - command: | - if [ -n "<>" ]; then - INSTALLED_AWS_VERSION="$(aws --version)" - aws --version | grep <> - else - if ! command -v aws &> /dev/null; then exit 1; else exit 0; fi - fi - test-paging: - steps: - - run: - name: Test that paging is disabled - command: | - # Test with aws command that would require paging if a pager is enabled - aws ec2 describe-images \ - --owners amazon \ - --filters "Name=platform,Values=windows" "Name=root-device-type,Values=ebs" + orb-tools: circleci/orb-tools@11.1 + shellcheck: circleci/shellcheck@3.1 -jobs: - integration-test-install: - parameters: - executor: - type: executor - version: - description: Select a specific version of the AWS v2 CLI. By default the latest version will be used. - default: latest - type: string - override-installed: - type: boolean - default: false - executor: <> - steps: - - aws-cli/setup: - version: <> - - test-paging - - integration-test-role-arn-setup: - executor: docker-base - parameters: - profile-name: - description: Name of new profile associated with role arn. - type: string - role-arn: - description: Role ARN that the profile should take. - type: string - source-profile: - description: Source profile containing credentials to assume the role with role-arn. - type: string - default: "default" - steps: - - aws-cli/setup - - aws-cli/role-arn-setup: - profile-name: <> - role-arn: <> - - run: - name: Check profiles were created - command: | - which aws - ROLE_ARN=$(aws configure get role_arn --profile <>) - SOURCE_PROFILE=$(aws configure get source_profile --profile <>) - if [ "${ROLE_ARN}" == "<>" ] && [ "${SOURCE_PROFILE}" == "<>" ]; then - echo configuration is correctly set. - else - echo Wrong configuration set. - exit 1 - fi +filters: &filters + tags: + only: /.*/ workflows: - # Prior to producing a development orb (which requires credentials) basic validation, linting, and even unit testing can be performed. - # This workflow will run on every commit - test-pack: - unless: << pipeline.parameters.run-integration-tests >> + lint-pack: jobs: - - orb-tools/lint # Lint Yaml files - - orb-tools/pack # Pack orb source + - orb-tools/lint: + filters: *filters + - orb-tools/pack: + filters: *filters + - orb-tools/review: + filters: *filters - shellcheck/check: - dir: ./src/scripts - exclude: SC2148 - # Publish development version(s) of the orb. - - orb-tools/publish-dev: + exclude: SC2148,SC2038,SC2086,SC2002,SC2016,SC1090 + filters: *filters + - orb-tools/publish: orb-name: circleci/aws-cli - context: orb-publisher # A restricted context containing your private publishing credentials. Will only execute if approved by an authorized user. + vcs-type: << pipeline.project.type >> requires: - - orb-tools/lint - - orb-tools/pack - - shellcheck/check - # Trigger an integration workflow to test the - # dev:${CIRCLE_SHA1:0:7} version of your orb - - orb-tools/trigger-integration-tests-workflow: - name: trigger-integration-dev + [orb-tools/lint, orb-tools/review, orb-tools/pack, shellcheck/check] + # Use a context to hold your publishing token. context: orb-publisher - requires: - - orb-tools/publish-dev - - # This `integration-test_deploy` workflow will only run - # when the run-integration-tests pipeline parameter is set to true. - # It is meant to be triggered by the "trigger-integration-tests-workflow" - # job, and run tests on @dev:${CIRCLE_SHA1:0:7}. - integration-test_deploy: - when: << pipeline.parameters.run-integration-tests >> - jobs: - # Run any integration tests defined within the `jobs` key. - - integration-test-install: - matrix: - parameters: - executor: ["linuxvm", "docker-base", "macos", "arm"] - post-steps: - - check_aws_version - - integration-test-install: - name: integration-test-install-version - executor: docker-base - version: "2.1.10" - post-steps: - - check_aws_version: - version: "2.1.10" - - integration-test-install: - name: integration-test-install-override-version - executor: docker-base - version: "2.1.10" - post-steps: - - check_aws_version: - version: "2.1.10" - - aws-cli/setup: - version: "2.0.20" - override-installed: true - - check_aws_version: - version: "2.0.20" - - integration-test-role-arn-setup: - name: test-role-arn-config - profile-name: "CircleCI-Tester" - role-arn: "arn:aws:iam::0123456789:role/foo-bar" - - # Publish a semver version of the orb. relies on - # the commit subject containing the text "[semver:patch|minor|major|skip]" - # as that will determine whether a patch, minor or major - # version will be published or if publishing should - # be skipped. - # e.g. [semver:patch] will cause a patch version to be published. - - orb-tools/dev-promote-prod-from-commit-subject: - orb-name: circleci/aws-cli - context: orb-publisher - add-pr-comment: false - fail-if-semver-not-indicated: true - publish-version-tag: false - requires: - - integration-test-install - - integration-test-install-version - - integration-test-install-override-version - filters: - branches: - only: - - master + filters: *filters + # Triggers the next workflow in the Orb Development Kit. + - orb-tools/continue: + pipeline-number: << pipeline.number >> + vcs-type: << pipeline.project.type >> + requires: [orb-tools/publish] + filters: *filters diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml new file mode 100644 index 0000000..fe91fde --- /dev/null +++ b/.circleci/test-deploy.yml @@ -0,0 +1,183 @@ +version: 2.1 +orbs: + aws-cli: circleci/aws-cli@dev:<> + orb-tools: circleci/orb-tools@11.1 +filters: &filters + tags: + only: /.*/ +jobs: + integration-test-install: + parameters: + executor: + type: executor + version: + description: Select a specific version of the AWS v2 CLI. By default the latest version will be used. + default: latest + type: string + override-installed: + type: boolean + default: false + binary-dir: + type: string + default: "/usr/local/bin" + description: | + Specify the binary directory + install-dir: + type: string + default: "/usr/local/aws-cli" + description: | + Specify the installation directory + executor: <> + steps: + - aws-cli/setup: + version: <> + override-installed: <> + install-dir: <> + binary-dir: <> + - test-paging + integration-test-role-arn-setup: + executor: docker-base + parameters: + profile-name: + description: Name of new profile associated with role arn. + type: string + role-arn: + description: Role ARN that the profile should take. + type: string + source-profile: + description: Source profile containing credentials to assume the role with role-arn. + type: string + default: "default" + steps: + - aws-cli/setup + - aws-cli/role-arn-setup: + profile-name: <> + role-arn: <> + - run: + name: Check if profiles were created + command: |- + which aws + ROLE_ARN=$(aws configure get role_arn --profile <>) + SOURCE_PROFILE=$(aws configure get source_profile --profile <>) + if [ "${ROLE_ARN}" == "<>" ] && [ "${SOURCE_PROFILE}" == "<>" ]; then + echo configuration is correctly set. + else + echo Wrong configuration set. + exit 1 + fi +workflows: + test-deploy: + jobs: + # Testing executors that do not AWS pre-installed + - integration-test-install: + name: integration-test-install-<> + matrix: + parameters: + executor: ["docker-base", "macos", "alpine"] + filters: *filters + post-steps: + - check_aws_version + # Test installing specific versions on executors without AWS pre-installed + - integration-test-install: + name: integration-test-install-version-<> + matrix: + parameters: + executor: ["docker-base", "macos", "alpine"] + version: "2.1.10" + filters: *filters + post-steps: + - check_aws_version: + version: "2.1.10" + # Test overriding existing version of AWS pre-installed + - integration-test-install: + name: integration-test-install-override-version-<> + matrix: + parameters: + executor: ["linuxvm", "windows", "arm"] + version: "2.1.10" + install-dir: "/usr/local/aws-cli" + binary-dir: "" + override-installed: true + filters: *filters + post-steps: + - check_aws_version: + version: "2.1.10" + - integration-test-role-arn-setup: + name: test-role-arn-config + profile-name: "CircleCI-Tester" + role-arn: "arn:aws:iam::0123456789:role/foo-bar" + - orb-tools/pack: + filters: *filters + - orb-tools/publish: + orb-name: circleci/aws-cli + vcs-type: << pipeline.project.type >> + pub-type: production + requires: + - orb-tools/pack + - integration-test-install-docker-base + - integration-test-install-alpine + - integration-test-install-macos + - integration-test-install-version-docker-base + - integration-test-install-version-macos + - integration-test-install-version-alpine + - integration-test-install-override-version-linuxvm + - integration-test-install-override-version-windows + - integration-test-install-override-version-arm + context: orb-publisher + filters: + branches: + ignore: /.*/ + tags: + only: /^v[0-9]+\.[0-9]+\.[0-9]+$/ +executors: + alpine: + docker: + - image: alpine:latest + docker-base: + docker: + - image: cimg/base:stable + macos: + macos: + xcode: 13.3.0 + arm: + machine: + image: ubuntu-2004:202101-01 + resource_class: arm.medium + linuxvm: + machine: + image: ubuntu-2004:202101-01 + windows: + machine: + image: windows-server-2019-vs2019:stable + shell: bash.exe + resource_class: windows.medium +commands: + check_aws_version: + parameters: + version: + type: string + default: "" + steps: + - run: + name: check_aws_version + command: | + aws --version + if [ -n "<>" ]; then + INSTALLED_AWS_VERSION="$(aws --version)" + aws --version | grep <> + else + if ! command -v aws &> /dev/null; then exit 1; else exit 0; fi + fi + test-paging: + steps: + - run: + name: Test that paging is disabled + command: |- + # Test with aws command that would require paging if a pager is enabled + if cat /etc/issue | grep "Alpine" || uname -a | grep "x86_64 Msys"; then + source $BASH_ENV + fi + aws --version + aws ec2 describe-images \ + --owners amazon \ + --filters "Name=platform,Values=windows" "Name=root-device-type,Values=ebs" diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..c9a8a2e --- /dev/null +++ b/.yamllint @@ -0,0 +1,7 @@ +extends: relaxed + +rules: + line-length: + max: 200 + allow-non-breakable-inline-mappings: true + diff --git a/README.md b/README.md index c55e8ac..f73a489 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,18 @@ -# AWS CLI Orb [![CircleCI status](https://circleci.com/gh/CircleCI-Public/aws-cli-orb.svg?style=shield "CircleCI status")](https://circleci.com/gh/CircleCI-Public/aws-cli-orb) [![CircleCI Orb Version](https://badges.circleci.com/orbs/circleci/slack.svg)](https://circleci.com/developer/orbs/orb/circleci/aws-cli) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/CircleCI-Public/aws-cli-orb/master/LICENSE) [![CircleCI Community](https://img.shields.io/badge/community-CircleCI%20Discuss-343434.svg)](https://discuss.circleci.com/c/ecosystem/orbs) +# AWS CLI Orb [![CircleCI status](https://circleci.com/gh/CircleCI-Public/aws-cli-orb.svg?style=shield "CircleCI status")](https://circleci.com/gh/CircleCI-Public/aws-cli-orb) [![CircleCI Orb Version](https://badges.circleci.com/orbs/circleci/aws-cli.svg)](https://circleci.com/developer/orbs/orb/circleci/aws-cli) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/CircleCI-Public/aws-cli-orb/master/LICENSE) [![CircleCI Community](https://img.shields.io/badge/community-CircleCI%20Discuss-343434.svg)](https://discuss.circleci.com/c/ecosystem/orbs) -Easily install and configure the AWS CLI in your CircleCI jobs. +CircleCI orb for installing and configuring the AWS CLI in your CircleCI jobs. -## Usage +## Resources -See [this orb's listing in CircleCI's Orbs Registry](https://circleci.com/orbs/registry/orb/circleci/aws-cli) for details on usage, or see below example: +[CircleCI Orb Registry Page](https://circleci.com/orbs/registry/orb/circleci/aws-cli) - The official registry page of this orb for all versions, executors, commands, and jobs described. -## Example +[CircleCI Orb Docs](https://circleci.com/docs/2.0/orb-intro/#section=configuration) - Docs for using and creating CircleCI Orbs -In this example `config.yml` snippet, the required AWS secrets (Access Key ID, Secret Access Key) are stored, via [Contexts](https://circleci.com/docs/2.0/contexts), as environment variables in the `aws` context and then read as default parameter values by the `aws-cli/setup` command. +### Examples +Please visit the the Orb Registry's [usage examples](https://circleci.com/developer/orbs/orb/circleci/aws-cli#usage-install-aws-cli) for the `install-aws-cli` example. -```yaml -version: 2.1 +### How to Contribute +We welcome [issues](https://github.com/CircleCI-Public/aws-ecr-orb/issues) to and [pull requests](https://github.com/CircleCI-Public/aws-ecr-orb/pulls) against this repository! -orbs: - aws-cli: circleci/aws-cli@x.y -jobs: - aws-cli-example: - executor: aws-cli/default - steps: - - checkout - - aws-cli/setup: - profile-name: example - - run: echo "Run your code here" - -workflows: - version: 2 - aws-cli: - jobs: - - aws-cli-example: - context: aws -``` +For further questions/comments about this or other orbs, visit [CircleCI's Orbs discussion forum](https://discuss.circleci.com/c/orbs). diff --git a/src/@orb.yml b/src/@orb.yml index 2fcb9cc..bba6f1e 100644 --- a/src/@orb.yml +++ b/src/@orb.yml @@ -8,3 +8,4 @@ description: | display: source_url: https://github.com/CircleCI-Public/aws-cli-orb + home_url: https://aws.amazon.com/cli diff --git a/src/commands/install.yml b/src/commands/install.yml index ec53938..e43c64d 100644 --- a/src/commands/install.yml +++ b/src/commands/install.yml @@ -16,7 +16,16 @@ parameters: Set to false to skip forceful disabling of all AWS CLI output paging. type: boolean default: true - + install-dir: + type: string + default: /usr/local/aws-cli + description: | + Specify the installation dirertory of AWS CLI. Defaults to /usr/local/aws-cli + binary-dir: + type: string + default: /usr/local/bin + description: | + The main aws program in the install directory is symbolically linked to the file aws in the specified path. Defaults to /usr/local/bin steps: - run: name: Install AWS CLI - <> @@ -24,4 +33,6 @@ steps: PARAM_AWS_CLI_VERSION: <> PARAM_AWS_CLI_DISABLE_PAGER: <> PARAM_AWS_CLI_OVERRIDE: <> + PARAM_AWS_CLI_INSTALL_DIR: <> + PARAM_AWS_CLI_BINARY_DIR: <> command: <> diff --git a/src/commands/role-arn-setup.yml b/src/commands/role-arn-setup.yml index 82aa363..d59be88 100644 --- a/src/commands/role-arn-setup.yml +++ b/src/commands/role-arn-setup.yml @@ -20,27 +20,23 @@ parameters: default: true profile-name: - description: Name of new profile associated with role arn. - type: string + description: Name of new profile associated with role arn. + type: string role-arn: - description: Role ARN that the profile should take. - type: string + description: Role ARN that the profile should take. + type: string source-profile: - description: Source profile containing credentials to assume the role with role-arn. - type: string - default: "default" + description: Source profile containing credentials to assume the role with role-arn. + type: string + default: "default" steps: - - run: - name: Configure role arn for profie <> + name: Configure role arn for profile <> environment: PARAM_AWS_CLI_PROFILE_NAME: <> PARAM_AWS_CLI_SOURCE_PROFILE: <> PARAM_AWS_CLI_ROLE_ARN: <> command: <> - - - diff --git a/src/commands/setup.yml b/src/commands/setup.yml index 1a21bef..22ce0eb 100644 --- a/src/commands/setup.yml +++ b/src/commands/setup.yml @@ -59,12 +59,25 @@ parameters: type: boolean default: true + install-dir: + type: string + default: /usr/local/aws-cli + description: | + Specify the installation dirertory of AWS CLI. Defaults to /usr/local/aws-cli + + binary-dir: + type: string + default: /usr/local/bin + description: | + The main aws program in the install directory is symbolically linked to the file aws in the specified path. Defaults to /usr/local/bin + steps: - install: version: <> disable-aws-pager: <> override-installed: <> - + install-dir: <> + binary-dir: <> - run: name: Configure AWS Access Key ID environment: diff --git a/src/examples/configure-role-arn.yml b/src/examples/configure-role-arn.yml index 9b553e5..cbc1c6b 100644 --- a/src/examples/configure-role-arn.yml +++ b/src/examples/configure-role-arn.yml @@ -18,8 +18,7 @@ usage: source-profile: default # Use profile created from setup command - run: aws sts assume-role --role-arn "arn:aws:iam::123456789012:role/example-role" --role-session-name AWSCLI-Session - workflows: aws-cli: jobs: - - configure-role-arn + - configure-role-arn diff --git a/src/scripts/configure.sh b/src/scripts/configure.sh index d9c53aa..4dee9f5 100644 --- a/src/scripts/configure.sh +++ b/src/scripts/configure.sh @@ -3,6 +3,10 @@ PARAM_AWS_CLI_SECRET_ACCESS_KEY=$(eval echo "\$$PARAM_AWS_CLI_SECRET_ACCESS_KEY" PARAM_AWS_CLI_REGION=$(eval echo "\$$PARAM_AWS_CLI_REGION") PARAM_AWS_CLI_ROLE_ARN=$(eval echo "${PARAM_AWS_CLI_ROLE_ARN}") +if cat /etc/issue | grep "Alpine" || uname -a | grep "x86_64 Msys"; then + source "$BASH_ENV" +fi +echo "${PATH}" aws configure set aws_access_key_id \ "$PARAM_AWS_CLI_ACCESS_KEY_ID" \ --profile "$PARAM_AWS_CLI_PROFILE_NAME" @@ -19,9 +23,3 @@ if [ "$PARAM_AWS_CLI_CONFIG_PROFILE_REGION" = "1" ]; then aws configure set region "$PARAM_AWS_CLI_REGION" \ --profile "$PARAM_AWS_CLI_PROFILE_NAME" fi - -if [ -n "$PARAM_AWS_CLI_ROLE_ARN" ]; then - echo "The role-arn parameter is deprecated. Please use the role-arn-setup command." - aws configure set role_arn "$PARAM_AWS_CLI_ROLE_ARN" \ - --profile "$PARAM_AWS_CLI_PROFILE_NAME" -fi diff --git a/src/scripts/install.sh b/src/scripts/install.sh index a72f4c7..9a1edc9 100644 --- a/src/scripts/install.sh +++ b/src/scripts/install.sh @@ -1,26 +1,6 @@ if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi -if [ ! "$(which aws)" ] || [ "$PARAM_AWS_CLI_OVERRIDE" = 1 ]; then - # setup - export AWS_CLI_VER_STRING="" - if [ ! "$PARAM_AWS_CLI_VERSION" = "latest" ]; then export AWS_CLI_VER_STRING="-$PARAM_AWS_CLI_VERSION"; fi - - # Uninstall existing AWS CLI if override is enabled. - if [ "$PARAM_AWS_CLI_OVERRIDE" = 1 ]; then - AWS_CLI_PATH=$(which aws) - if [ -n "$AWS_CLI_PATH" ]; then - EXISTING_AWS_VERSION=$(aws --version) - echo "Uninstalling ${EXISTING_AWS_VERSION}" - # shellcheck disable=SC2012 - if [ -L "$AWS_CLI_PATH" ]; then - AWS_SYMLINK_PATH=$(ls -l "$AWS_CLI_PATH" | sed -e 's/.* -> //') - fi - $SUDO rm -rf "$AWS_CLI_PATH" "$AWS_SYMLINK_PATH" "$HOME/.aws/" "/usr/local/bin/aws" "/usr/local/bin/aws_completer" "/usr/local/aws-cli" - else - echo "No AWS install found" - fi - fi - +Install_AWS_CLI() { echo "Installing AWS CLI v2" cd /tmp || exit # Platform check @@ -30,45 +10,129 @@ if [ ! "$(which aws)" ] || [ "$PARAM_AWS_CLI_OVERRIDE" = 1 ]; then export SYS_ENV_PLATFORM=linux_x86 elif uname -a | grep "aarch64 GNU/Linux"; then export SYS_ENV_PLATFORM=linux_arm + elif uname -a | grep "x86_64 Msys"; then + export SYS_ENV_PLATFORM=windows + elif cat /etc/issue | grep "Alpine" >/dev/null 2>&1; then + export SYS_ENV_PLATFORM=linux_alpine else echo "This platform appears to be unsupported." uname -a exit 1 fi - echo "Platform $SYS_ENV_PLATFORM" + # Install per platform case $SYS_ENV_PLATFORM in linux_x86) - curl -sSL "https://awscli.amazonaws.com/awscli-exe-linux-x86_64${AWS_CLI_VER_STRING}.zip" -o "awscliv2.zip" + curl -sSL "https://awscli.amazonaws.com/awscli-exe-linux-x86_64$1.zip" -o "awscliv2.zip" unzip -q -o awscliv2.zip - $SUDO ./aws/install - rm awscliv2.zip + $SUDO ./aws/install -i "${PARAM_AWS_CLI_INSTALL_DIR}" -b "${PARAM_AWS_CLI_BINARY_DIR}" + rm -r awscliv2.zip ./aws + ;; + windows) + if [ ! "$(command -v choco)" ]; then + echo "Chocolatey is required to uninstall AWS" + exit 1 + fi + choco install awscli --version="$1" + echo "$1" + if echo "$1" | grep "2."; then + echo 'export PATH="${PATH}:/c/Program Files/Amazon/AWSCLIV2"' >>"$BASH_ENV" + else + echo 'export PATH="${PATH}:/c/Program Files/Amazon/AWSCLI/bin"' >>"$BASH_ENV" + fi ;; macos) - curl -sSL "https://awscli.amazonaws.com/AWSCLIV2${AWS_CLI_VER_STRING}.pkg" -o "AWSCLIV2.pkg" + curl -sSL "https://awscli.amazonaws.com/AWSCLIV2$1.pkg" -o "AWSCLIV2.pkg" $SUDO installer -pkg AWSCLIV2.pkg -target / rm AWSCLIV2.pkg ;; linux_arm) - curl -sSL "https://awscli.amazonaws.com/awscli-exe-linux-aarch64${AWS_CLI_VER_STRING}.zip" -o "awscliv2.zip" + curl -sSL "https://awscli.amazonaws.com/awscli-exe-linux-aarch64$1.zip" -o "awscliv2.zip" unzip -q -o awscliv2.zip - $SUDO ./aws/install - rm awscliv2.zip + $SUDO ./aws/install -i "${PARAM_AWS_CLI_INSTALL_DIR}" -b "${PARAM_AWS_CLI_BINARY_DIR}" + rm -r awscliv2.zip ./aws + ;; + linux_alpine) + apk --no-cache add \ + binutils \ + curl + + curl -L https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub -o /etc/apk/keys/sgerrand.rsa.pub + curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.34-r0/glibc-2.34-r0.apk + curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.34-r0/glibc-bin-2.34-r0.apk + curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.34-r0/glibc-i18n-2.34-r0.apk + + apk add --no-cache \ + glibc-2.34-r0.apk \ + glibc-bin-2.34-r0.apk \ + glibc-i18n-2.34-r0.apk + + /usr/glibc-compat/bin/localedef -i en_US -f UTF-8 en_US.UTF-8 + curl -sSL "https://awscli.amazonaws.com/awscli-exe-linux-x86_64$1.zip" -o "awscliv2.zip" + + echo "https://awscli.amazonaws.com/awscli-exe-linux-x86_64$1.zip" + unzip awscliv2.zip + aws/install + rm -r awscliv2.zip ./aws ;; *) echo "This orb does not currently support your platform. If you believe it should, please consider opening an issue on the GitHub repository:" echo "https://github.com/CircleCI-Public/aws-cli-orb/issues/new" exit 1 - ;; + ;; esac # Toggle AWS Pager if [ "$PARAM_AWS_CLI_DISABLE_PAGER" = 1 ]; then if [ -z "${AWS_PAGER+x}" ]; then - echo 'export AWS_PAGER=""' >> "$BASH_ENV" + echo 'export AWS_PAGER=""' >>"$BASH_ENV" echo "AWS_PAGER is being set to the empty string to disable all output paging for AWS CLI commands." echo "You can set the 'disable-aws-pager' parameter to 'false' to disable this behavior." fi fi +} + +Uninstall_AWS_CLI() { + if uname -a | grep "x86_64 Msys"; then + if [ ! "$(command -v choco)" ]; then + echo "Chocolatey is required to uninstall AWS" + exit 1 + fi + choco uninstall awscli + else + AWS_CLI_PATH=$(command -v aws) + echo "$AWS_CLI_PATH" + if [ -n "$AWS_CLI_PATH" ]; then + EXISTING_AWS_VERSION=$(aws --version) + echo "Uninstalling ${EXISTING_AWS_VERSION}" + # shellcheck disable=SC2012 + if [ -L "$AWS_CLI_PATH" ]; then + AWS_SYMLINK_PATH=$(ls -l "$AWS_CLI_PATH" | sed -e 's/.* -> //') + fi + if uname -a | grep "x86_64 Msys"; then export SUDO=""; fi + $SUDO rm -rf "$AWS_CLI_PATH" "$AWS_SYMLINK_PATH" "$HOME/.aws/" "/usr/local/bin/aws" "/usr/local/bin/aws_completer" "/usr/local/aws-cli" + else + echo "No AWS install found" + fi + fi +} + +if [ ! "$(command -v aws)" ]; then + if [ "$PARAM_AWS_CLI_VERSION" = "latest" ]; then + Install_AWS_CLI + else + if uname -a | grep "x86_64 Msys"; then + Install_AWS_CLI "${PARAM_AWS_CLI_VERSION}" + else + Install_AWS_CLI "-${PARAM_AWS_CLI_VERSION}" + fi + fi +elif [ "$PARAM_AWS_CLI_OVERRIDE" = 1 ]; then + Uninstall_AWS_CLI + if uname -a | grep "x86_64 Msys"; then + Install_AWS_CLI "${PARAM_AWS_CLI_VERSION}" + else + Install_AWS_CLI "-${PARAM_AWS_CLI_VERSION}" + fi else echo "AWS CLI is already installed, skipping installation." aws --version diff --git a/src/scripts/role-arn-setup.sh b/src/scripts/role-arn-setup.sh index c706a04..d31754c 100644 --- a/src/scripts/role-arn-setup.sh +++ b/src/scripts/role-arn-setup.sh @@ -1,14 +1,12 @@ - -PARAM_AWS_CLI_PROFILE_NAME=$(eval echo "${PARAM_AWS_CLI_PROFILE_NAME}") -PARAM_AWS_CLI_SOURCE_PROFILE=$(eval echo "${PARAM_AWS_CLI_SOURCE_PROFILE}") -PARAM_AWS_CLI_ROLE_ARN=$(eval echo "${PARAM_AWS_CLI_ROLE_ARN}") +if [ ! -f "${HOME}/.aws/credentials" ]; then + echo "Credentials not found. Run setup command before role-arn-setup." + exit 1 +fi if [ ! -f "${HOME}/.aws/credentials" ]; then echo "Credentials not found. Run setup command before role-arn-setup." exit 1 fi - + aws configure set profile."${PARAM_AWS_CLI_PROFILE_NAME}".role_arn "${PARAM_AWS_CLI_ROLE_ARN}" aws configure set profile."${PARAM_AWS_CLI_PROFILE_NAME}".source_profile "${PARAM_AWS_CLI_SOURCE_PROFILE}" - -