AWS - Implement backward compatible localstack

Signed-off-by: Guillaume de Rouville <guillaume.derouville@gmail.com>
This commit is contained in:
Guillaume de Rouville 2021-08-17 02:59:22 +02:00
parent 65de05ecb5
commit a33a4f4749

View File

@ -10,11 +10,13 @@ import (
// AWS Config shared by all AWS packages // AWS Config shared by all AWS packages
#Config: { #Config: {
// AWS region // AWS region
region: string @dagger(input) region: dagger.#Input & { string }
// AWS access key // AWS access key
accessKey: dagger.#Secret @dagger(input) accessKey: dagger.#Input & { dagger.#Secret }
// AWS secret key // AWS secret key
secretKey: dagger.#Secret @dagger(input) secretKey: dagger.#Input & { dagger.#Secret }
// AWS localstack mode
localMode: dagger.#Input & { string | *null }
} }
// Re-usable aws-cli component // Re-usable aws-cli component
@ -30,6 +32,9 @@ import (
"package": jq: "=~1.6" "package": jq: "=~1.6"
"package": curl: true "package": curl: true
"package": "aws-cli": "=~1.18" "package": "aws-cli": "=~1.18"
if config.localMode != null {
"package": "py3-pip": true
}
} }
}, },
op.#Exec & { op.#Exec & {
@ -40,6 +45,7 @@ import (
"-eo", "-eo",
"pipefail", "pipefail",
"-c", "-c",
if config.localMode == null {
#""" #"""
aws configure set aws_access_key_id "$(cat /run/secrets/access_key)" aws configure set aws_access_key_id "$(cat /run/secrets/access_key)"
aws configure set aws_secret_access_key "$(cat /run/secrets/secret_key)" aws configure set aws_secret_access_key "$(cat /run/secrets/secret_key)"
@ -48,6 +54,28 @@ import (
aws configure set default.cli_pager "" aws configure set default.cli_pager ""
aws configure set default.output "json" aws configure set default.output "json"
"""#, """#,
}
if config.localMode != null {
#"""
# Download awscli v3 and override aws
pip install awscli-local[v2]
mv /usr/bin/awslocal /usr/bin/aws
# Configure
mkdir -p ~/.aws/
# Set up ~/.aws/config
echo "[default]" > ~/.aws/config
echo "region = $AWS_DEFAULT_REGION" >> ~/.aws/config
echo "cli_pager =" >> ~/.aws/config
echo "output = json" >> ~/.aws/config
# Set up ~/.aws/credentials
echo "[default]" > ~/.aws/credentials
echo "aws_access_key_id = $(cat /run/secrets/access_key)" >> ~/.aws/credentials
echo "aws_secret_access_key = $(cat /run/secrets/secret_key)" >> ~/.aws/credentials
"""#,
}
] ]
mount: "/run/secrets/access_key": secret: config.accessKey mount: "/run/secrets/access_key": secret: config.accessKey
mount: "/run/secrets/secret_key": secret: config.secretKey mount: "/run/secrets/secret_key": secret: config.secretKey