...

Text file src/oras.land/oras-go/scripts/acceptance.sh

Documentation: oras.land/oras-go/scripts

     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
    17DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
    18cd $DIR/../
    19
    20LOCAL_REGISTRY_HOSTNAME="${LOCAL_REGISTRY_HOSTNAME:-localhost}"
    21
    22# Cleanup from previous runs
    23rm -f hello.txt
    24rm -f bin/oras-acceptance-* || true
    25docker rm -f oras-acceptance-registry || true
    26
    27# Build the examples into binaries
    28CGO_ENABLED=0 go build -v -o bin/oras-acceptance-simple ./examples/simple
    29CGO_ENABLED=0 go build -v -o bin/oras-acceptance-advanced ./examples/advanced
    30
    31# Run a test registry and expose at localhost:5000
    32trap "docker rm -f oras-acceptance-registry" EXIT
    33docker 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)
    38WAIT_TIME=0
    39while 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
    52done
    53
    54# Wait another 5 seconds for good measure
    55sleep 5
    56
    57# Run the example binary
    58bin/oras-acceptance-simple
    59
    60# Ensure hello.txt exists and contains expected content
    61grep '^Hello World!$' hello.txt

View as plain text