|
| 1 | +#!/usr/bin/env bash |
| 2 | +##===----------------------------------------------------------------------===## |
| 3 | +## |
| 4 | +## This source file is part of the SwiftContainerPlugin open source project |
| 5 | +## |
| 6 | +## Copyright (c) 2025 Apple Inc. and the SwiftContainerPlugin project authors |
| 7 | +## Licensed under Apache License v2.0 |
| 8 | +## |
| 9 | +## See LICENSE.txt for license information |
| 10 | +## See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors |
| 11 | +## |
| 12 | +## SPDX-License-Identifier: Apache-2.0 |
| 13 | +## |
| 14 | +##===----------------------------------------------------------------------===## |
| 15 | + |
| 16 | +log() { printf -- "** %s\n" "$*" >&2; } |
| 17 | +error() { printf -- "** ERROR: %s\n" "$*" >&2; } |
| 18 | +fatal() { error "$@"; exit 1; } |
| 19 | + |
| 20 | +set -euo pipefail |
| 21 | + |
| 22 | +RUNTIME=${RUNTIME-"docker"} |
| 23 | +PKGPATH=$(mktemp -d) |
| 24 | + |
| 25 | +# |
| 26 | +# Package an example payload with resources. This test only checks |
| 27 | +# that the correct files are in the container image and does not run |
| 28 | +# it, so the payload does not need to be an executable. |
| 29 | +# |
| 30 | +touch "$PKGPATH/hello" |
| 31 | +mkdir -p "$PKGPATH/resourcedir" |
| 32 | +touch "$PKGPATH/resourcedir/resource1.txt" "$PKGPATH/resourcedir/resource2.txt" "$PKGPATH/resourcedir/resource3.txt" |
| 33 | +touch "$PKGPATH/resourcefile.dat" |
| 34 | +swift run containertool \ |
| 35 | + "$PKGPATH/hello" \ |
| 36 | + --repository localhost:5000/resource_test \ |
| 37 | + --from scratch \ |
| 38 | + --resources "$PKGPATH/resourcedir" \ |
| 39 | + --resources "$PKGPATH/resourcefile.dat" |
| 40 | + |
| 41 | +$RUNTIME rm -f resource-test |
| 42 | +$RUNTIME create --pull always --name resource-test localhost:5000/resource_test:latest |
| 43 | + |
| 44 | +cleanup() { |
| 45 | + log "Deleting temporary package $PKGPATH" |
| 46 | + rm -rf "$PKGPATH" |
| 47 | + |
| 48 | + log "Deleting resource-test container" |
| 49 | + $RUNTIME rm -f resource-test |
| 50 | +} |
| 51 | +trap cleanup EXIT |
| 52 | + |
| 53 | + |
| 54 | +for resource in \ |
| 55 | + /hello \ |
| 56 | + /resourcedir/resource1.txt \ |
| 57 | + /resourcedir/resource2.txt \ |
| 58 | + /resourcedir/resource3.txt \ |
| 59 | + /resourcefile.dat |
| 60 | +do |
| 61 | + # This will return a non-zero exit code if the file does not exist |
| 62 | + if $RUNTIME cp resource-test:$resource - > /dev/null ; then |
| 63 | + log "$resource: OK" |
| 64 | + else |
| 65 | + fatal "$resource: FAILED" |
| 66 | + fi |
| 67 | +done |
| 68 | + |
0 commit comments