Skip to content

Commit dc75c00

Browse files
Danny Joycekardolus
andcommitted
Remove scripts submodule and hard code for now [#163825783]
Co-authored-by: Guillermo Kardolus <gkardolus@pivotal.io>
1 parent c2690b6 commit dc75c00

7 files changed

Lines changed: 168 additions & 4 deletions

File tree

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "scripts"]
2-
path = scripts
3-
url = git@github.com:cloudfoundry/cnb-scripts

scripts

Lines changed: 0 additions & 1 deletion
This file was deleted.

scripts/all-tests.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
cd "$( dirname "${BASH_SOURCE[0]}" )/.."
5+
./scripts/unit.sh && ./scripts/integration.sh
6+

scripts/install_tools.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
PACK_VERSION=latest
5+
6+
usage() {
7+
echo "Usage: install_tools.sh <version: optional>"
8+
echo "Example: install_tools.sh 0.0.9"
9+
exit 0
10+
}
11+
12+
if [ "$#" -gt 1 ]; then
13+
usage
14+
fi
15+
16+
if [[ "$#" -eq 1 && $1 == "-h" ]]; then
17+
usage
18+
fi
19+
20+
if [ "$#" -eq 1 ]; then
21+
PACK_VERSION="$1"
22+
fi
23+
24+
install_pack() {
25+
OS=$(uname -s)
26+
27+
if [[ $OS == "Darwin" ]]; then
28+
OS="macos"
29+
elif [[ $OS == "Linux" ]]; then
30+
OS="linux"
31+
else
32+
echo "Unsupported operating system"
33+
exit 1
34+
fi
35+
36+
if [ "$PACK_VERSION" != "latest" ]; then
37+
echo "Installing pack $PACK_VERSION"
38+
39+
PACK_ARTIFACT=pack-$PACK_VERSION-$OS.tar.gz
40+
ARTIFACT_URL="https://github.com/buildpack/pack/releases/download/v$PACK_VERSION/$PACK_ARTIFACT"
41+
expand $ARTIFACT_URL
42+
return 0
43+
fi
44+
45+
if [[ $OS == "macos" ]]; then
46+
ARTIFACT_URL=$(curl -s https://api.github.com/repos/buildpack/pack/releases/latest | jq --raw-output '.assets[1] | .browser_download_url')
47+
else
48+
ARTIFACT_URL=$(curl -s https://api.github.com/repos/buildpack/pack/releases/latest | jq --raw-output '.assets[0] | .browser_download_url')
49+
fi
50+
51+
expand $ARTIFACT_URL
52+
}
53+
54+
expand() {
55+
PACK_ARTIFACT=$(echo $1 | sed "s/.*\///")
56+
PACK_VERSION=v$(echo $PACK_ARTIFACT | sed 's/pack-//' | sed 's/-.*//')
57+
58+
if [[ ! -f .bin/pack ]]; then
59+
echo "Installing Pack"
60+
elif [[ "$(.bin/pack version | sed 's/VERSION: //' | cut -d ' ' -f 1)" != *$PACK_VERSION* ]]; then
61+
rm .bin/pack
62+
echo "Updating Pack"
63+
else
64+
echo "Version $PACK_VERSION of pack is already installed"
65+
return 0
66+
fi
67+
wget $ARTIFACT_URL
68+
tar xzvf $PACK_ARTIFACT -C .bin
69+
rm $PACK_ARTIFACT
70+
}
71+
72+
configure_pack() {
73+
pack add-stack org.cloudfoundry.stacks.cflinuxfs3 \
74+
--build-image cfbuildpacks/cflinuxfs3-cnb-experimental:build \
75+
--run-image cfbuildpacks/cflinuxfs3-cnb-experimental:run || echo "Ignoring add stack error"
76+
}
77+
78+
cd "$( dirname "${BASH_SOURCE[0]}" )/.."
79+
80+
mkdir -p .bin
81+
export PATH=$(pwd)/.bin:$PATH
82+
83+
install_pack
84+
configure_pack

scripts/integration.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
cd "$( dirname "${BASH_SOURCE[0]}" )/.."
5+
6+
if [[ ! -d integration ]]; then
7+
echo "No integration tests"
8+
exit 1
9+
fi
10+
11+
PACK_VERSION=${PACK_VERSION:-""}
12+
source ./scripts/install_tools.sh $PACK_VERSION
13+
14+
export CNB_BUILD_IMAGE=${CNB_BUILD_IMAGE:-cfbuildpacks/cflinuxfs3-cnb-experimental:build}
15+
export CNB_RUN_IMAGE=${CNB_RUN_IMAGE:-cfbuildpacks/cflinuxfs3-cnb-experimental:run}
16+
17+
# Always pull latest images
18+
# Most helpful for local testing consistency with CI (which would already pull the latest)
19+
docker pull $CNB_BUILD_IMAGE
20+
docker pull $CNB_RUN_IMAGE
21+
22+
set +e
23+
echo "Run Buildpack Runtime Integration Tests"
24+
go test ./integration/... -v -run Integration
25+
exit_code=$?
26+
27+
if [ "$exit_code" != "0" ]; then
28+
echo -e "\n\033[0;31m** GO Test Failed **\033[0m"
29+
else
30+
echo -e "\n\033[0;32m** GO Test Succeeded **\033[0m"
31+
fi
32+
33+
exit $exit_code

scripts/package.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
TARGET_OS=${1:-linux}
5+
6+
cd "$( dirname "${BASH_SOURCE[0]}" )/.."
7+
8+
echo "Target OS is $TARGET_OS"
9+
echo -n "Creating buildpack directory..."
10+
bp_dir=/tmp/"${PWD##*/}"_$(openssl rand -hex 12)
11+
mkdir $bp_dir
12+
echo "done"
13+
14+
echo -n "Copying buildpack.toml..."
15+
cp buildpack.toml $bp_dir/buildpack.toml
16+
echo "done"
17+
18+
if [ "${BP_REWRITE_HOST:-}" != "" ]; then
19+
sed -i -e "s|^uri = \"https:\/\/buildpacks\.cloudfoundry\.org\(.*\)\"$|uri = \"http://$BP_REWRITE_HOST\1\"|g" "$bp_dir/buildpack.toml"
20+
fi
21+
22+
for b in $(ls cmd); do
23+
echo -n "Building $b..."
24+
GOOS=$TARGET_OS go build -o $bp_dir/bin/$b ./cmd/$b
25+
echo "done"
26+
done
27+
echo "Buildpack packaged into: $bp_dir"

scripts/unit.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
cd "$( dirname "${BASH_SOURCE[0]}" )/.."
5+
6+
echo "Run Buildpack Unit Tests"
7+
8+
set +e
9+
go test ./... -v -run Unit
10+
exit_code=$?
11+
12+
if [ "$exit_code" != "0" ]; then
13+
echo -e "\n\033[0;31m** GO Test Failed **\033[0m"
14+
else
15+
echo -e "\n\033[0;32m** GO Test Succeeded **\033[0m"
16+
fi
17+
18+
exit $exit_code

0 commit comments

Comments
 (0)