github.com/nikkelma/oras-project_oras-go@v1.1.1-0.20220201001104-a75f6a419090/scripts/acceptance.sh (about) 1 #!/bin/bash -ex 2 3 # Copyright The ORAS Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 18 cd $DIR/../ 19 20 LOCAL_REGISTRY_HOSTNAME="${LOCAL_REGISTRY_HOSTNAME:-localhost}" 21 22 # Cleanup from previous runs 23 rm -f hello.txt 24 rm -f bin/oras-acceptance-* || true 25 docker rm -f oras-acceptance-registry || true 26 27 # Build the examples into binaries 28 CGO_ENABLED=0 go build -v -o bin/oras-acceptance-simple ./examples/simple 29 CGO_ENABLED=0 go build -v -o bin/oras-acceptance-advanced ./examples/advanced 30 31 # Run a test registry and expose at localhost:5000 32 trap "docker rm -f oras-acceptance-registry" EXIT 33 docker run -d -p 5000:5000 \ 34 --name oras-acceptance-registry \ 35 index.docker.io/registry 36 37 # Wait for a connection to port 5000 (timeout after 1 minute) 38 WAIT_TIME=0 39 while true; do 40 if nc -w 1 -z "${LOCAL_REGISTRY_HOSTNAME}" 5000; then 41 echo "Able to connect to ${LOCAL_REGISTRY_HOSTNAME} port 5000" 42 break 43 else 44 if (( ${WAIT_TIME} >= 60 )); then 45 echo "Timed out waiting for connection to ${LOCAL_REGISTRY_HOSTNAME} on port 5000. Exiting." 46 exit 1 47 fi 48 echo "Waiting to connect to ${LOCAL_REGISTRY_HOSTNAME} on port 5000. Sleeping 5 seconds.." 49 sleep 5 50 WAIT_TIME=$((WAIT_TIME + 5)) 51 fi 52 done 53 54 # Wait another 5 seconds for good measure 55 sleep 5 56 57 # Run the example binary 58 bin/oras-acceptance-simple 59 60 # Ensure hello.txt exists and contains expected content 61 grep '^Hello World!$' hello.txt