stdlib: aws: s3: add #Sync

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2021-05-29 01:20:57 -07:00
parent 9facaa65f4
commit 3605d399c9
2 changed files with 97 additions and 0 deletions

View File

@ -90,3 +90,80 @@ import (
] ]
} }
} }
// S3 Sync
#Sync: {
// AWS Config
config: aws.#Config
// Source Artifact to upload to S3
source: dagger.#Artifact @dagger(input)
// Target S3 URL (eg. s3://<bucket-name>/<path>/<sub-path>)
target: string @dagger(input)
// Files that exist in the destination but not in the
// source are deleted during sync.
delete: *false | bool @dagger(input)
// Object content type
contentType: string | *"" @dagger(input)
// Always write the object to S3
always: bool | *true @dagger(input)
// URL of the uploaded S3 object
url: {
@dagger(output)
string
#up: [
op.#Load & {
from: aws.#CLI & {
"config": config
}
},
op.#Exec & {
if always != _|_ {
"always": always
}
env: {
TARGET: target
OPT_CONTENT_TYPE: contentType
if delete {
OPT_DELETE: "1"
}
}
mount: "/source": from: source
args: [
"/bin/bash",
"--noprofile",
"--norc",
"-eo",
"pipefail",
"-c",
#"""
opts=()
if [ -d /source ]; then
op=sync
fi
[ -n "$OPT_CONTENT_TYPE" ] && opts+="--content-type $OPT_CONTENT_TYPE"
[ -n "$OPT_DELETE" ] && opts+="--delete"
aws s3 sync ${opts[@]} /source "$TARGET"
echo -n "$TARGET" \
| sed -E 's=^s3://([^/]*)/=https://\1.s3.amazonaws.com/=' \
> /url
"""#,
]
},
op.#Export & {
source: "/url"
format: "string"
},
]
}
}

View File

@ -49,3 +49,23 @@ TestS3UploadDir: {
file: "foo.txt" file: "foo.txt"
} }
} }
TestS3Sync: {
deploy: s3.#Sync & {
config: TestConfig.awsConfig
source: TestDirectory
target: "s3://\(bucket)/"
}
verifyFile: #VerifyS3 & {
config: TestConfig.awsConfig
target: deploy.target
file: "dirFile.txt"
}
verifyDir: #VerifyS3 & {
config: TestConfig.awsConfig
target: deploy.target
file: "foo.txt"
}
}