2021-06-15 10:46:56 +02:00
|
|
|
// AWS base package
|
2021-03-04 02:33:19 +01:00
|
|
|
package aws
|
|
|
|
|
2021-03-18 23:53:26 +01:00
|
|
|
import (
|
2021-10-07 09:44:14 +02:00
|
|
|
"regexp"
|
2021-06-23 16:31:42 +02:00
|
|
|
"alpha.dagger.io/dagger"
|
|
|
|
"alpha.dagger.io/dagger/op"
|
|
|
|
"alpha.dagger.io/alpine"
|
2021-03-18 23:53:26 +01:00
|
|
|
)
|
2021-03-10 20:13:12 +01:00
|
|
|
|
2021-06-15 10:46:56 +02:00
|
|
|
// AWS Config shared by all AWS packages
|
2021-03-04 02:33:19 +01:00
|
|
|
#Config: {
|
|
|
|
// AWS region
|
2021-08-19 17:11:33 +02:00
|
|
|
region: dagger.#Input & {string}
|
2021-03-04 02:33:19 +01:00
|
|
|
// AWS access key
|
2021-08-19 17:11:33 +02:00
|
|
|
accessKey: dagger.#Input & {dagger.#Secret}
|
2021-03-04 02:33:19 +01:00
|
|
|
// AWS secret key
|
2021-08-19 17:11:33 +02:00
|
|
|
secretKey: dagger.#Input & {dagger.#Secret}
|
2021-08-17 02:59:22 +02:00
|
|
|
// AWS localstack mode
|
2021-08-31 17:16:04 +02:00
|
|
|
localMode: dagger.#Input & {*false | bool}
|
2021-03-04 02:33:19 +01:00
|
|
|
}
|
2021-03-18 23:53:26 +01:00
|
|
|
|
2021-10-07 09:44:14 +02:00
|
|
|
// Configuration specific to CLI v1
|
|
|
|
#V1: {
|
2021-05-27 03:03:48 +02:00
|
|
|
config: #Config
|
2021-05-27 14:20:15 +02:00
|
|
|
package: [string]: string | bool
|
2022-01-04 15:27:33 +01:00
|
|
|
version: dagger.#Input & {*"1.19" | string}
|
2021-04-10 00:48:18 +02:00
|
|
|
|
2021-04-03 00:00:30 +02:00
|
|
|
#up: [
|
2021-04-06 02:27:51 +02:00
|
|
|
op.#Load & {
|
2021-03-18 23:53:26 +01:00
|
|
|
from: alpine.#Image & {
|
2021-04-10 00:48:18 +02:00
|
|
|
"package": package
|
2022-01-04 15:27:33 +01:00
|
|
|
"package": bash: true
|
|
|
|
"package": jq: true
|
2021-05-27 14:20:15 +02:00
|
|
|
"package": curl: true
|
2021-10-07 09:44:14 +02:00
|
|
|
"package": "aws-cli": "=~\( version )"
|
|
|
|
if config.localMode != false {
|
|
|
|
package: "py3-pip": true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Configuration specific to CLI v2
|
|
|
|
#V2: {
|
|
|
|
config: #Config
|
|
|
|
package: [string]: string | bool
|
2022-01-04 15:27:33 +01:00
|
|
|
version: dagger.#Input & {*"2.1.29" | string}
|
2021-10-07 09:44:14 +02:00
|
|
|
|
|
|
|
#up: [
|
|
|
|
op.#Load & {
|
|
|
|
from: alpine.#Image & {
|
|
|
|
"package": package
|
2022-01-04 15:27:33 +01:00
|
|
|
"package": bash: true
|
|
|
|
"package": jq: true
|
2021-10-07 09:44:14 +02:00
|
|
|
"package": curl: true
|
|
|
|
"package": binutils: true
|
2021-08-31 17:16:04 +02:00
|
|
|
if config.localMode != false {
|
2021-08-19 17:11:33 +02:00
|
|
|
package: "py3-pip": true
|
2021-08-17 02:59:22 +02:00
|
|
|
}
|
2021-03-18 23:53:26 +01:00
|
|
|
}
|
|
|
|
},
|
2021-10-07 09:44:14 +02:00
|
|
|
//https://stackoverflow.com/a/61268529
|
2021-05-27 03:03:48 +02:00
|
|
|
op.#Exec & {
|
2021-10-07 09:44:14 +02:00
|
|
|
env: AWS_CLI_VERSION: version
|
|
|
|
args: ["/bin/bash", "--noprofile", "--norc", "-eo", "pipefail", "-c",
|
|
|
|
#"""
|
|
|
|
curl -sL https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub -o /etc/apk/keys/sgerrand.rsa.pub
|
|
|
|
curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.31-r0/glibc-2.31-r0.apk
|
|
|
|
curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.31-r0/glibc-bin-2.31-r0.apk
|
|
|
|
curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.31-r0/glibc-i18n-2.31-r0.apk
|
|
|
|
apk add --no-cache glibc-2.31-r0.apk glibc-bin-2.31-r0.apk glibc-i18n-2.31-r0.apk
|
|
|
|
/usr/glibc-compat/bin/localedef -i en_US -f UTF-8 en_US.UTF-8
|
|
|
|
|
|
|
|
curl -s https://awscli.amazonaws.com/awscli-exe-linux-x86_64-${AWS_CLI_VERSION}.zip -o awscliv2.zip
|
|
|
|
unzip awscliv2.zip > /dev/null
|
|
|
|
./aws/install
|
|
|
|
rm -rf awscliv2.zip aws /usr/local/aws-cli/v2/*/dist/aws_completer /usr/local/aws-cli/v2/*/dist/awscli/data/ac.index \
|
|
|
|
usr/local/aws-cli/v2/*/dist/awscli/examples glibc-*.apk
|
|
|
|
"""#]
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
#CLI: {
|
|
|
|
config: #Config
|
|
|
|
package: [string]: string | bool
|
2022-01-04 15:27:33 +01:00
|
|
|
version: dagger.#Input & {*"1.19" | string}
|
2021-10-07 09:44:14 +02:00
|
|
|
|
|
|
|
_isV2: regexp.Match("^2.*$", version)
|
|
|
|
|
|
|
|
#up: [
|
|
|
|
op.#Load & {
|
|
|
|
if _isV2 == false {
|
|
|
|
from: #V1 & {
|
|
|
|
"config": config
|
|
|
|
"package": package
|
|
|
|
"version": version
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if _isV2 == true {
|
|
|
|
from: #V2 & {
|
|
|
|
"config": config
|
|
|
|
"package": package
|
|
|
|
"version": version
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
op.#Exec & {
|
|
|
|
if config.localMode == false {
|
|
|
|
args: ["/bin/bash", "--noprofile", "--norc", "-eo", "pipefail", "-c",
|
2021-08-19 17:11:33 +02:00
|
|
|
#"""
|
2021-10-07 09:44:14 +02:00
|
|
|
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 default.region "$AWS_DEFAULT_REGION"
|
|
|
|
aws configure set default.cli_pager ""
|
|
|
|
aws configure set default.output "json"
|
|
|
|
"""#]
|
|
|
|
}
|
|
|
|
if config.localMode == true {
|
|
|
|
args: [ "/bin/bash", "--noprofile", "--norc", "-eo", "pipefail", "-c",
|
2021-08-19 17:11:33 +02:00
|
|
|
#"""
|
2021-10-07 09:44:14 +02:00
|
|
|
# Download awscli v3 and override aws
|
|
|
|
pip install awscli-local==0.14
|
|
|
|
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
|
|
|
|
"""#]
|
|
|
|
}
|
2021-05-27 03:03:48 +02:00
|
|
|
mount: "/run/secrets/access_key": secret: config.accessKey
|
|
|
|
mount: "/run/secrets/secret_key": secret: config.secretKey
|
2021-05-27 18:22:41 +02:00
|
|
|
env: AWS_DEFAULT_REGION: config.region
|
2021-05-27 03:03:48 +02:00
|
|
|
},
|
2021-03-18 23:53:26 +01:00
|
|
|
]
|
2021-05-27 18:22:41 +02:00
|
|
|
}
|