Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix some edge cases with resource uploads #1736

Merged
merged 8 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions charmcraft/application/commands/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -1992,9 +1992,10 @@ def run(self, parsed_args: argparse.Namespace) -> int:
if const.STORE_REGISTRY_ENV_VAR in os.environ:
# If the user has specified a registry to use, replace what the store
# gives with that registry.
registry_url = os.environ[const.STORE_REGISTRY_ENV_VAR][7:]
registry_url = os.environ[const.STORE_REGISTRY_ENV_VAR]
registry_url_without_scheme = registry_url.partition("://")[2]
lengau marked this conversation as resolved.
Show resolved Hide resolved
image_name = credentials.image_name.split("/", 1)[1]
dest_path = f"docker://{registry_url}/{image_name}"
dest_path = f"docker://{registry_url_without_scheme}/{image_name}"
else:
dest_path = f"docker://{credentials.image_name}"

Expand Down
2 changes: 1 addition & 1 deletion charmcraft/services/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ImageService(craft_application.AppService):
def setup(self) -> None:
"""Set up the image service."""
super().setup()
self._skopeo = utils.Skopeo()
self._skopeo = utils.Skopeo(insecure_policy=True)
self._docker = docker.from_env()

def copy(
Expand Down
1 change: 1 addition & 0 deletions spread.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ environment:
SNAPD_TESTING_TOOLS: $PROJECT_PATH/tools/external/tools
PATH: /snap/bin:$PATH:$SNAPD_TESTING_TOOLS
CRAFT_DEBUG: 1 # Show exception tracebacks.
CRAFT_VERBOSITY_LEVEL: debug # Show debugging output when failing.
# Use the staging store for tests:
CHARMCRAFT_STORE_API_URL: https://api.staging.charmhub.io
CHARMCRAFT_UPLOAD_URL: https://storage.staging.snapcraftcontent.com
Expand Down
18 changes: 9 additions & 9 deletions tests/spread/store/resources/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ execute: |

# upload and verify the file resource
upload_revision_number=$(charmcraft upload-resource $CHARM_DEFAULT_NAME example-file --format=json --file=resourcefile.txt --arch=amd64,riscv64 | jq -r '.revision')
revisions_json=$(charmcraft resource-revisions $CHARM_DEFAULT_NAME example-file --format=json)
upload_revision=$(echo "$revisions_json" | jq -c ".[] | select(.revision == $upload_revision_number)" )
charmcraft resource-revisions $CHARM_DEFAULT_NAME example-file --format=json > file_revisions.json
lengau marked this conversation as resolved.
Show resolved Hide resolved
upload_revision=$(cat file_revisions.json | jq -c ".[] | select(.revision == $upload_revision_number)" )
upload_revision_architectures=$(echo "$upload_revision" | jq -c '.bases[0].architectures')
[[ "$upload_revision_architectures" = '["amd64","riscv64"]' ]]
last_revision=$(echo "$revisions_json" | jq -r .[-1])
last_revision=$(jq -r .[-1] file_revisions.json)
last_file_revno=$(echo $last_revision | jq .revision)
[[ "$upload_revision_number" -le "$last_file_revno" ]]
last_revision_created=$(echo $last_revision | jq -r .created_at)
Expand All @@ -82,28 +82,28 @@ execute: |

# upload and verify the OCI image resource by digest
# This is a different image hash because it's what Docker contains locally on amd64.
uploaded_revision=$(charmcraft --verbose upload-resource --format=json $CHARM_DEFAULT_NAME example-image --image=sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412 | jq -r '.revision')
uploaded_revision=$(charmcraft upload-resource --format=json $CHARM_DEFAULT_NAME example-image --image=sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412 | jq -r '.revision')
sleep 3 # Give the store a bit of time to process it
last_revision=$(charmcraft resource-revisions $CHARM_DEFAULT_NAME example-image --format=json | jq -r .[0])
last_revision=$(charmcraft resource-revisions $CHARM_DEFAULT_NAME example-image --format=json | jq -r 'max_by(.revision)')
last_image_revno=$(echo $last_revision | jq .revision)
test $last_image_revno -ge $uploaded_revision
last_revision_created=$(echo $last_revision | jq -r '.["created at"]')

# Upload and verify the OCI image resource by image ID.
uploaded_revision=$(charmcraft upload-resource --format=json $CHARM_DEFAULT_NAME example-image --image=feb5d9fea6a5 | jq -r '.revision')
sleep 3 # Give the store a bit of time to process it
last_revision=$(charmcraft resource-revisions $CHARM_DEFAULT_NAME example-image --format=json | jq -r .[0])
last_revision=$(charmcraft resource-revisions $CHARM_DEFAULT_NAME example-image --format=json | jq -r 'max_by(.revision)')
last_image_revno=$(echo $last_revision | jq .revision)
test $last_image_revno -ge $uploaded_revision
last_revision_created=$(echo $last_revision | jq -r '.["created at"]')

# Upload and verify a docker image resource file.
docker save hello-world@sha256:18a657d0cc1c7d0678a3fbea8b7eb4918bba25968d3e1b0adebfa71caddbc346 -o hello-world.docker
docker save hello-world@sha256:18a657d0cc1c7d0678a3fbea8b7eb4918bba25968d3e1b0adebfa71caddbc346 > hello-world.docker
docker_revision=$(charmcraft upload-resource --format=json $CHARM_DEFAULT_NAME example-image --image=docker-archive:hello-world.docker | jq -r '.revision')
/snap/charmcraft/current/libexec/charmcraft/skopeo copy docker-archive:hello-world.docker oci-archive:hello-world.tar
/snap/charmcraft/current/libexec/charmcraft/skopeo --insecure-policy copy docker-archive:hello-world.docker oci-archive:hello-world.tar
oci_revision=$(charmcraft upload-resource --format=json $CHARM_DEFAULT_NAME example-image --image=oci-archive:hello-world.tar | jq -r '.revision')
test $docker_revision -eq $uploaded_revision
test $oci_revision -eq $uploaded_revision
test $oci_revision -ge $uploaded_revision # Expected to be newer because the OCI archive is normally slightly different from the Docker file.

# release and check full status
charmcraft release $CHARM_DEFAULT_NAME -r $last_charm_revno -c edge --resource=example-file:$last_file_revno --resource=example-image:$last_image_revno
Expand Down
Loading