mirror of
https://github.com/floci-io/floci.git
synced 2026-11-29 08:31:53 -05:00
* feat(ecr): PutImage and the layer API PutImage, BatchCheckLayerAvailability, GetDownloadUrlForLayer, InitiateLayerUpload, UploadLayerPart and CompleteLayerUpload now go through the registry:2 container that docker push already writes to, so an image written through the API is the image docker pull and BatchGetImage return. - PutImage writes the manifest under its tag, or under its digest. It answers ImageDigestDoesNotMatchException, ImageAlreadyExistsException, ImageTagAlreadyExistsException and LayersNotFoundException as the model lists them. - Layer uploads map onto registry upload sessions, held in memory. Parts must follow each other, be at most 20 MiB, and all but the last at least 5 MiB. - GetDownloadUrlForLayer returns the blob's address on Floci's registry endpoint. - The immutable-tag guard moves into EcrService, so a docker push and a PutImage of one tag cannot both succeed. Closes #5735 * fix(ecr): refuse mixed layer digests, keep push time on retag, expire idle uploads CompleteLayerUpload refuses a second, different layer digest instead of ignoring it. PutImage keeps an image's first push time when it retags it. A layer upload idle for a day is refused even when no other upload opens, and dropping one cancels its registry upload session. * fix(ecr): check PutImage tags, require a manifest media type, share registry error handling - PutImage checks imageTag against the OCI tag grammar and answers InvalidParameterException otherwise. The tag goes into the registry's manifest URL, so v1?x wrote v1 and a slash wrote into another repository. - A manifest with no mediaType needs imageManifestMediaType, as on AWS, instead of Floci guessing one from the manifest's shape. - PutImage and the layer API reach the registry through one helper, callRegistry, in place of five copies of the same failure handling. * fix(ecr): answer ECR's own message for a tag outside its rule PutImage refuses a tag outside ECR's rule, [a-zA-Z0-9-_.]+ up to 300 characters, with ECR's message. A tag ECR takes but the backing registry cannot hold, one starting with '.' or '-' or longer than 128 characters, is refused with a message naming that limit, which docs/services/ecr.md now notes.
143 lines
6.4 KiB
Bash
143 lines
6.4 KiB
Bash
#!/usr/bin/env bats
|
|
# ECR control-plane integration tests.
|
|
#
|
|
# Test-first: this file is committed before the server-side ECR implementation
|
|
# lands. With ECR unimplemented, every test below should fail.
|
|
|
|
setup() {
|
|
load 'test_helper/common-setup'
|
|
REPO_NAME="floci-it/app-cli-$(unique_name)"
|
|
}
|
|
|
|
teardown() {
|
|
aws_cmd ecr delete-repository --repository-name "$REPO_NAME" --force >/dev/null 2>&1 || true
|
|
}
|
|
|
|
@test "ECR: create-repository returns loopback URI" {
|
|
run aws_cmd ecr create-repository --repository-name "$REPO_NAME"
|
|
assert_success
|
|
arn=$(json_get "$output" '.repository.repositoryArn')
|
|
uri=$(json_get "$output" '.repository.repositoryUri')
|
|
name=$(json_get "$output" '.repository.repositoryName')
|
|
[ "$name" = "$REPO_NAME" ]
|
|
[[ "$arn" =~ ^arn:aws:ecr: ]]
|
|
[[ "$arn" == *":repository/$REPO_NAME" ]]
|
|
[[ "$uri" == *"localhost:"* ]]
|
|
[[ "$uri" == *"/$REPO_NAME" ]]
|
|
}
|
|
|
|
@test "ECR: create-repository duplicate fails with RepositoryAlreadyExistsException" {
|
|
aws_cmd ecr create-repository --repository-name "$REPO_NAME" >/dev/null
|
|
run aws_cmd ecr create-repository --repository-name "$REPO_NAME"
|
|
assert_failure
|
|
[[ "$output" == *"RepositoryAlreadyExistsException"* ]]
|
|
}
|
|
|
|
@test "ECR: describe-repositories returns the created repo" {
|
|
aws_cmd ecr create-repository --repository-name "$REPO_NAME" >/dev/null
|
|
run aws_cmd ecr describe-repositories --repository-names "$REPO_NAME"
|
|
assert_success
|
|
name=$(json_get "$output" '.repositories[0].repositoryName')
|
|
[ "$name" = "$REPO_NAME" ]
|
|
}
|
|
|
|
@test "ECR: get-authorization-token returns AWS:<password>" {
|
|
aws_cmd ecr create-repository --repository-name "$REPO_NAME" >/dev/null
|
|
run aws_cmd ecr get-authorization-token
|
|
assert_success
|
|
token=$(json_get "$output" '.authorizationData[0].authorizationToken')
|
|
proxy=$(json_get "$output" '.authorizationData[0].proxyEndpoint')
|
|
[ -n "$token" ]
|
|
[[ "$proxy" =~ ^https?:// ]]
|
|
decoded=$(echo "$token" | base64 -d)
|
|
[[ "$decoded" == AWS:* ]]
|
|
}
|
|
|
|
@test "ECR: list-images on empty repo returns []" {
|
|
aws_cmd ecr create-repository --repository-name "$REPO_NAME" >/dev/null
|
|
run aws_cmd ecr list-images --repository-name "$REPO_NAME"
|
|
assert_success
|
|
count=$(echo "$output" | jq '.imageIds | length')
|
|
[ "$count" = "0" ]
|
|
}
|
|
|
|
@test "ECR: put-image-tag-mutability round-trips IMMUTABLE" {
|
|
aws_cmd ecr create-repository --repository-name "$REPO_NAME" >/dev/null
|
|
run aws_cmd ecr put-image-tag-mutability --repository-name "$REPO_NAME" --image-tag-mutability IMMUTABLE
|
|
assert_success
|
|
mut=$(json_get "$output" '.imageTagMutability')
|
|
[ "$mut" = "IMMUTABLE" ]
|
|
}
|
|
|
|
@test "ECR: put-lifecycle-policy round-trips" {
|
|
aws_cmd ecr create-repository --repository-name "$REPO_NAME" >/dev/null
|
|
policy='{"rules":[{"rulePriority":1,"selection":{"tagStatus":"untagged","countType":"imageCountMoreThan","countNumber":5},"action":{"type":"expire"}}]}'
|
|
aws_cmd ecr put-lifecycle-policy --repository-name "$REPO_NAME" --lifecycle-policy-text "$policy" >/dev/null
|
|
run aws_cmd ecr get-lifecycle-policy --repository-name "$REPO_NAME"
|
|
assert_success
|
|
got=$(json_get "$output" '.lifecyclePolicyText')
|
|
[ "$got" = "$policy" ]
|
|
}
|
|
|
|
@test "ECR: set-repository-policy round-trips" {
|
|
aws_cmd ecr create-repository --repository-name "$REPO_NAME" >/dev/null
|
|
policy='{"Version":"2012-10-17","Statement":[{"Sid":"AllowAll","Effect":"Allow","Principal":"*","Action":"ecr:*"}]}'
|
|
aws_cmd ecr set-repository-policy --repository-name "$REPO_NAME" --policy-text "$policy" >/dev/null
|
|
run aws_cmd ecr get-repository-policy --repository-name "$REPO_NAME"
|
|
assert_success
|
|
got=$(json_get "$output" '.policyText')
|
|
[ "$got" = "$policy" ]
|
|
}
|
|
|
|
@test "ECR: delete-repository force=true removes the repo" {
|
|
aws_cmd ecr create-repository --repository-name "$REPO_NAME" >/dev/null
|
|
run aws_cmd ecr delete-repository --repository-name "$REPO_NAME" --force
|
|
assert_success
|
|
run aws_cmd ecr describe-repositories --repository-names "$REPO_NAME"
|
|
assert_failure
|
|
[[ "$output" == *"RepositoryNotFoundException"* ]]
|
|
}
|
|
|
|
@test "ECR: describe-repositories on missing name fails" {
|
|
run aws_cmd ecr describe-repositories --repository-names "does-not-exist-cli"
|
|
assert_failure
|
|
[[ "$output" == *"RepositoryNotFoundException"* ]]
|
|
}
|
|
|
|
@test "ECR: an image pushed with the layer API retags with batch-get-image and put-image" {
|
|
aws_cmd ecr create-repository --repository-name "$REPO_NAME" >/dev/null
|
|
printf '{"architecture":"amd64","os":"linux"}' > "$BATS_TEST_TMPDIR/config"
|
|
printf 'floci layer bytes' > "$BATS_TEST_TMPDIR/layer"
|
|
|
|
for blob in config layer; do
|
|
file="$BATS_TEST_TMPDIR/$blob"
|
|
size=$(wc -c < "$file" | tr -d ' ')
|
|
digest="sha256:$(sha256sum "$file" | cut -d' ' -f1)"
|
|
upload=$(aws_cmd ecr initiate-layer-upload --repository-name "$REPO_NAME" | jq -r '.uploadId')
|
|
run aws_cmd ecr upload-layer-part --repository-name "$REPO_NAME" --upload-id "$upload" \
|
|
--part-first-byte 0 --part-last-byte $((size - 1)) --layer-part-blob "fileb://$file"
|
|
assert_success
|
|
run aws_cmd ecr complete-layer-upload --repository-name "$REPO_NAME" --upload-id "$upload" \
|
|
--layer-digests "$digest"
|
|
assert_success
|
|
[ "$(json_get "$output" '.layerDigest')" = "$digest" ]
|
|
eval "${blob}_digest=$digest ${blob}_size=$size"
|
|
done
|
|
|
|
manifest=$(printf '{"schemaVersion":2,"mediaType":"application/vnd.oci.image.manifest.v1+json","config":{"mediaType":"application/vnd.oci.image.config.v1+json","size":%s,"digest":"%s"},"layers":[{"mediaType":"application/vnd.oci.image.layer.v1.tar","size":%s,"digest":"%s"}]}' \
|
|
"$config_size" "$config_digest" "$layer_size" "$layer_digest")
|
|
run aws_cmd ecr put-image --repository-name "$REPO_NAME" --image-tag v1 --image-manifest "$manifest"
|
|
assert_success
|
|
digest=$(json_get "$output" '.image.imageId.imageDigest')
|
|
|
|
read_back=$(aws_cmd ecr batch-get-image --repository-name "$REPO_NAME" --image-ids imageTag=v1 \
|
|
--query 'images[0].imageManifest' --output text)
|
|
run aws_cmd ecr put-image --repository-name "$REPO_NAME" --image-tag release --image-manifest "$read_back"
|
|
assert_success
|
|
[ "$(json_get "$output" '.image.imageId.imageDigest')" = "$digest" ]
|
|
|
|
run aws_cmd ecr describe-images --repository-name "$REPO_NAME" --image-ids imageTag=release
|
|
assert_success
|
|
[ "$(json_get "$output" '.imageDetails[0].imageDigest')" = "$digest" ]
|
|
}
|