Skip to content

Commit

Permalink
Merge pull request #63 from CircleCI-Public/feat/add-parameters-commands
Browse files Browse the repository at this point in the history
feat: add new parameters to commands
  • Loading branch information
brivu authored Jul 31, 2023
2 parents c33e270 + 2421f61 commit 467368d
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ workflows:
s3_bucket: "sam-orb-testing"
parameter_overrides: ParameterKey=dummy,ParameterValue=dummy
arguments: --disable-rollback
build_container_vars: Function1.GITHUB_TOKEN=VAR1, GLOBAL_ENV_VAR=VAR2
build_arguments: --parallel
build_parameter_overrides: BuildParameterKey=dummy,BuildParameterValue=dummy
context: CPE-OIDC
filters: *filters
- sam/deploy:
Expand Down
20 changes: 20 additions & 0 deletions src/commands/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ parameters:
type: boolean
description: If your functions depend on packages that have natively compiled dependencies, use this flag to build your function inside an AWS Lambda-like Docker container.
default: true
build_container_vars:
type: string
description: >-
Environment variables to pass into the build container. Each instance of this option takes a key-value pair, where the key is the environment variable, and the value is the environment variable's value.
Separate each key value pair with a comma, e.g build_container_vars: Function1.GITHUB_TOKEN=$TOKEN1, GLOBAL_ENV_VAR=$VAR2
NOTE: use_container parameter must be set to true in order to use build_container_vars.
default: ""
region:
type: string
description: Sets the AWS Region of the service (for example, us-east-1).
Expand All @@ -36,6 +43,16 @@ parameters:
type: boolean
description: Turns on debug logging.
default: false
build_parameter_overrides:
type: string
description: >-
AWS CloudFormation parameter overrides encoded as key=value pairs
for the sam build command. Use the same format as the AWS CLI.
default: ""
build_arguments:
type: string
description: Additional arguments to pass to the build command. e.g. (--parallel)
default: ""

steps:
- when:
Expand All @@ -59,4 +76,7 @@ steps:
ORB_BOOL_USE_CONTAINER: << parameters.use_container >>
ORB_STR_REGION: << parameters.region >>
ORB_BOOL_DEBUG: << parameters.debug >>
ORB_STR_BUILD_PARAMETER_OVERRIDES: << parameters.build_parameter_overrides >>
ORB_STR_BUILD_ARGUMENTS: << parameters.build_arguments >>
ORB_STR_BUILD_CONTAINER_VARS: << parameters.build_container_vars >>
command: <<include(scripts/build.sh)>>
9 changes: 9 additions & 0 deletions src/commands/local_start_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ parameters:
description: Dockerize is a utility that will continuously attempt to connect to an endpoint. Used to wait for the API to come online.
default: "0.6.1"
type: string
warm_containers:
description: >-
Specifies how AWS SAM CLI manages containers for each function with two available options:
EAGER: Containers for all functions are loaded at startup and persist between invocations.
LAZY: Containers are only loaded when each function is first invoked. Those containers persist for additional invocations.
type: enum
enum: ["" , "EAGER", "LAZY"]
default: ""
steps:
- run:
name: install dockerize
Expand All @@ -43,6 +51,7 @@ steps:
ORB_STR_TEMPLATE: <<parameters.template>>
ORB_INT_PORT: <<parameters.port>>
ORB_STR_ENV_VARS: <<parameters.env_vars>>
ORB_ENUM_WARM_CONTAINERS: << parameters.warm_containers >>
command: <<include(scripts/local_start_api.sh)>>
- run:
name: Wait for API
Expand Down
22 changes: 21 additions & 1 deletion src/jobs/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ parameters:
type: boolean
description: If your functions depend on packages that have natively compiled dependencies, use this flag to build your function inside an AWS Lambda-like Docker container.
default: true
build_container_vars:
type: string
description: >-
Environment variables to pass into the build container. Each instance of this option takes a key-value pair, where the key is the environment variable, and the value is the environment variable's value.
Separate each key value pair with a comma, e.g build_container_vars: Function1.GITHUB_TOKEN=$TOKEN1, GLOBAL_ENV_VAR=$VAR2
NOTE: use_container parameter must be set to true in order to use build_container_vars.
default: ""
region:
type: string
description: Sets the AWS Region of the service (for example, us-east-1).
Expand All @@ -77,12 +84,22 @@ parameters:
default: ""
no_fail_on_empty_changeset:
type: boolean
description: Specify if deploy command hould return a zero exit code if there are no changes to be made to the stack.
description: Specify if deploy command should return a zero exit code if there are no changes to be made to the stack.
default: true
arguments:
type: string
description: Additional arguments to pass to the deploy command. e.x. (--resolve-image-repos)
default: ""
build_parameter_overrides:
type: string
description: >-
AWS CloudFormation parameter overrides encoded as key=value pairs
for the sam build command. Use the same format as the AWS CLI.
default: ""
build_arguments:
type: string
description: Additional arguments to pass to the build command. e.g. (--parallel)
default: ""
auth:
description: |
The authentication method used to access your AWS account. Import the aws-cli orb in your config and
Expand All @@ -103,6 +120,9 @@ steps:
use_container: << parameters.use_container >>
region: << parameters.region >>
debug: << parameters.debug >>
build_parameter_overrides: << parameters.build_parameter_overrides >>
build_arguments: << parameters.build_arguments >>
build_container_vars: << parameters.build_container_vars >>
- steps: << parameters.pre_deploy >>
- deploy:
capabilities: << parameters.capabilities >>
Expand Down
21 changes: 20 additions & 1 deletion src/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,44 @@
set -o noglob
ORB_STR_REGION="$(echo "${ORB_STR_REGION}" | circleci env subst)"
ORB_STR_TEMPLATE="$(echo "${ORB_STR_TEMPLATE}" | circleci env subst)"
ORB_STR_BUILD_PARAMETER_OVERRIDES="$(echo "${ORB_STR_BUILD_PARAMETER_OVERRIDES}" | circleci env subst)"
ORB_STR_BUILD_ARGUMENTS="$(echo "${ORB_STR_BUILD_ARGUMENTS}" | circleci env subst)"
ORB_STR_BUILD_CONTAINER_VARS="$(echo "${ORB_STR_BUILD_CONTAINER_VARS}" | circleci env subst)"
ORB_EVAL_BUILD_DIR="$(eval echo "${ORB_EVAL_BUILD_DIR}" | circleci env subst)"
ORB_EVAL_BASE_DIR="$(eval echo "${ORB_EVAL_BASE_DIR}" | circleci env subst)"

set -- "$@" --template-file "${ORB_STR_TEMPLATE}"

set -- "$@" --region "${ORB_STR_REGION}"


if [ -n "$ORB_EVAL_BUILD_DIR" ]; then
set -- "$@" --build-dir "${ORB_EVAL_BUILD_DIR}"
fi
if [ -n "$ORB_EVAL_BASE_DIR" ]; then
set -- "$@" --base-dir "${ORB_EVAL_BASE_DIR}"
fi
if [ "$ORB_BOOL_USE_CONTAINER" -eq 1 ]; then
if [ "$ORB_BOOL_USE_CONTAINER" -eq 0 ] && [ -n "$ORB_STR_BUILD_CONTAINER_VARS" ]; then
echo "Error - use_container parameter set to false. Set to true to use build_container_vars"
exit 1;
elif [ "$ORB_BOOL_USE_CONTAINER" -eq 1 ]; then
set -- "$@" --use-container
if [ -n "$ORB_STR_BUILD_CONTAINER_VARS" ]; then
IFS="," read -ra container_vars <<< "${ORB_STR_BUILD_CONTAINER_VARS}"
for var in "${container_vars[@]}"; do
set -- "$@" --container-env-var "${var}"
done
fi
fi
if [ "$ORB_BOOL_DEBUG" -eq 1 ]; then
set -- "$@" --debug
fi
if [ -n "$ORB_STR_BUILD_PARAMETER_OVERRIDES" ]; then
set -- "$@" --parameter-overrides "${ORB_STR_BUILD_PARAMETER_OVERRIDES}"
fi
if [ -n "$ORB_STR_BUILD_ARGUMENTS" ]; then
set -- "$@" "${ORB_STR_BUILD_ARGUMENTS}"
fi

set -x
sam build --profile "${ORB_STR_PROFILE_NAME}" "$@"
Expand Down
5 changes: 5 additions & 0 deletions src/scripts/local_start_api.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
ORB_STR_TEMPLATE="$(echo "${ORB_STR_TEMPLATE}" | circleci env subst)"
ORB_STR_ENV_VARS="$(echo "${ORB_STR_ENV_VARS}" | circleci env subst)"

if [ -n "$ORB_STR_TEMPLATE" ]; then
set -- "$@" -t "$ORB_STR_TEMPLATE"
fi
Expand All @@ -11,6 +12,10 @@ if [ -n "$ORB_STR_ENV_VARS" ]; then
set -- "$@" -n "$PARAM_ENV_VARS"
fi

if [ -n "$ORB_ENUM_WARM_CONTAINERS" ]; then
set -- "$@" --warm-containers "$ORB_ENUM_WARM_CONTAINERS"
fi

if [ "$ORB_BOOL_DEBUG" -eq 1 ]; then
set -- "$@" --debug
fi
Expand Down

0 comments on commit 467368d

Please sign in to comment.