-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassembly.sh
executable file
·99 lines (79 loc) · 2.88 KB
/
assembly.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
download_helm_charts() {
# Parse the charts.yaml file for helm repos to add
while read -r repo_name repo_url; do
helm repo add ${repo_name} ${repo_url}
done < <(yq -r '.charts[] | "\(.name) \(.repo)"' charts.yaml)
helm repo update
# Get the repo name, chart name, and chart version to pull the charts
# and save them to the 'charts' subdirectory
while read -r repo_name chart_name chart_version; do
helm pull --untar "${repo_name}/${chart_name}" --version "${chart_version}" -d charts
done < <(yq -r '.charts[] | "\(.name) \(.chart) \(.version)"' charts.yaml)
}
do_bundle() {
# Switch to the distribution directory
pushd dist > /dev/null || exit 1
echo "Downloading Porter CLI..."
download_porter_cli
# Build the bundle
porter build --dir ../
porter publish --force --dir ../ --reference ${BUNDLE_REGISTRY}/${BUNDLE_NAME}:v${BUNDLE_VERSION}
porter archive ${BUNDLE_NAME}.tgz --reference ${BUNDLE_REGISTRY}/${BUNDLE_NAME}:v${BUNDLE_VERSION}
# Package the CLI and the bundle in a distributable archive
tar -czf ./${BUNDLE_NAME}-bundle.tar.gz porter ${BUNDLE_NAME}.tgz
}
download_porter_cli() {
if [ "$PORTER_OS" == "linux" ]; then
PORTER_FILENAME="porter-linux-amd64"
elif [ "$PORTER_OS" == "darwin" ]; then
PORTER_FILENAME="porter-darwin-amd64"
elif [ "$PORTER_OS" == "windows" ]; then
PORTER_FILENAME="porter-windows-amd64.exe"
else
echo "Unsupported operating system: $PORTER_OS"
exit 1
fi
# Download the Porter CLI binary for use on systems that do not have Porter installed
curl -L https://cdn.porter.sh/v${PORTER_VERSION}/$PORTER_FILENAME -o ./porter
chmod +x ./porter
}
init() {
# Get the latest Porter version
PORTER_VERSION=$(porter version | grep -o -E '[0-9]+\.[0-9]+\.[0-9]+')
# Get the Porter bundle name
BUNDLE_NAME=$(cat ./porter.yaml | grep "name:" | head -n 1 | cut -d':' -f2 | xargs)
BUNDLE_VERSION=$(cat ./porter.yaml | grep "version:" | head -n 1 | cut -d':' -f2 | xargs)
BUNDLE_REGISTRY=$(grep -E '^registry:' porter.yaml | sed 's/"//g' | cut -d':' -f2,3 | xargs)
# Create the "charts" directory if it doesn't exist
mkdir -p charts
touch charts/tmp
rm -rf charts/*
# Create the "dist" directory if nonexistent
mkdir -p dist
# Clear any previous distribution files
rm -rf dist/*
}
finish() {
popd > /dev/null
}
PORTER_OS=$(uname -s | tr '[:upper:]' '[:lower:]')
PORTER_OS=${PORTER_OS:-linux}
case "$PORTER_OS" in
linux*) PORTER_OS=linux;;
darwin*) PORTER_OS=darwin;;
cygwin*) PORTER_OS=windows;;
mingw*) PORTER_OS=windows;;
*) echo "Unsupported operating system: $(uname -s)" && exit 1
esac
# Prepare for script actions
echo "Initializing..."
init
# Download the helm charts
echo "Downloading helm charts..."
download_helm_charts
# Build and export the bundle to a portable file
echo "Creating and exporting bundle..."
do_bundle
echo "Finished..."
finish