Skip to content

Commit

Permalink
Merge pull request #5 from nmnellis/install-script
Browse files Browse the repository at this point in the history
Install script and runAsUser
  • Loading branch information
nmnellis authored Jul 9, 2021
2 parents c0bdad0 + 487b9e9 commit 4ad6ace
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 4 deletions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ generate kubernetes yaml for applications

![Kiali UI](./docs/kiali-ui.png)

## To Install

```shell
# latest version
curl -sL https://raw.githubusercontent.com/nmnellis/istio-app-simulator/main/install.sh | sh -
# specific version
curl -sL https://raw.githubusercontent.com/nmnellis/istio-app-simulator/main/install.sh | APP_VERSION=${APP_VERSION} sh -
```


### Synopsis

This application generates kubernetes yaml that sets up complex application networks for a given amount of namespaces.
Expand Down Expand Up @@ -46,7 +56,7 @@ generate [flags]

* Overriding default values
```shell
./istio-app-simulator generate \
ias generate \
# only generate 3 namespaces
# namespaces are named ns-1, ns-2, ns-3
--namespaces 3 \
Expand All @@ -60,7 +70,7 @@ generate [flags]

* Manipulating chances
```shell
./istio-app-simulator generate \
ias generate \
# every application will call some external service
--chance-call-external 100 \
# half of all applications will call an application in another namespace
Expand All @@ -83,14 +93,14 @@ generate [flags]
# istio-injection: enabled
# seed: "1625582727962871000"

./istio-app-simulator generate \
ias generate \
# use the seed above to regenerate the same output
--seed 1625582727962871000
```

* Tuning Apps and sidecars
```shell
./istio-app-simulator generate \
ias generate \
-o out/cluster-1 \
# always generate the same yaml for seed 100
--seed 100 \
Expand Down
80 changes: 80 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/sh

set -eu

if [ -x "$(command -v python3)" ]; then
alias any_python='python3'
elif [ -x "$(command -v python)" ]; then
alias any_python='python'
elif [ -x "$(command -v python2)" ]; then
alias any_python='python2'
else
echo Python 2 or 3 is required to install ias
exit 1
fi

if [ -z "${APP_VERSION:-}" ]; then
APP_VERSIONS=$(curl -sH"Accept: application/vnd.github.v3+json" https://api.github.com/repos/nmnellis/istio-app-simulator/releases | any_python -c "import sys; from distutils.version import StrictVersion, LooseVersion; from json import loads as l; releases = l(sys.stdin.read()); releases = [release['tag_name'] for release in releases]; filtered_releases = list(filter(lambda release_string: len(release_string) > 0 and StrictVersion.version_re.match(release_string[1:]) != None, releases)); filtered_releases.sort(key=LooseVersion, reverse=True); print('\n'.join(filtered_releases))")
else
APP_VERSIONS="${APP_VERSION}"
fi

if [ "$(uname -s)" = "Darwin" ]; then
OS=darwin
else
OS=linux
fi

for app_version in $APP_VERSIONS; do

tmp=$(mktemp -d /tmp/ias.XXXXXX)
filename="istio_app_simulator_${OS}_amd64"
url="https://github.com/nmnellis/istio-app-simulator/releases/download/${app_version}/${filename}.zip"

if curl -f ${url} >/dev/null 2>&1; then
echo "Attempting to download istio app simulator version ${app_version}"
else
continue
fi

(
cd "$tmp"

echo "Downloading ${filename}..."

SHA=$(curl -sL "${url}.sha256" | cut -d' ' -f1)
curl -sLO "${url}"
echo "Download complete!"
# checksum=$(openssl dgst -sha256 "${filename}" | awk '{ print $2 }')
# if [ "$checksum" != "$SHA" ]; then
# echo "Checksum validation failed." >&2
# exit 1
# fi
# echo "Checksum valid."

)

(

cd "$HOME"
mkdir -p ".istio/bin"
echo "extracting zip ${tmp}/${filename}"
unzip "${tmp}/${filename}.zip" -d ${tmp}
mv "${tmp}/istio-app-simulator" ".istio/bin/ias"
chmod +x ".istio/bin/ias"
)

rm -r "$tmp"

echo "istio app simulator was successfully installed 🎉"
echo ""
echo "Add the ias CLI to your path with:"
echo " export PATH=\$HOME/.istio/bin:\$PATH"
echo ""
echo "Now run:"
echo " ias generate # generate applications"
exit 0
done

echo "No versions of ias found."
exit 1
2 changes: 2 additions & 0 deletions pkg/generate/assets/app.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ spec:
image: ghcr.io/nmnellis/fake-service:v2
ports:
- containerPort: 8080
securityContext:
runAsUser: 1001
env:
- name: "LISTEN_ADDR"
value: "0.0.0.0:8080"
Expand Down

0 comments on commit 4ad6ace

Please sign in to comment.