Skip to content

Commit f3e0984

Browse files
committed
Adding install script to docs
Signed-off-by: Mikkel Mørk Hegnhøj <mikkel@fermyon.com>
1 parent 53d8c69 commit f3e0984

File tree

3 files changed

+172
-18
lines changed

3 files changed

+172
-18
lines changed

docs/content/quickstart.md

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,49 @@ url = "https://github.com/fermyon/spin/blob/main/docs/content/quickstart.md"
1212

1313
## Getting the `spin` binary
1414

15-
You can download the [latest release](https://github.com/fermyon/spin/releases).
16-
For example, for an Apple silicon macOS machine:
15+
You can install the `spin` binary using the `install.sh` script hosted on this site.
1716

18-
```
19-
$ wget https://github.com/fermyon/spin/releases/download/v0.5.0/spin-v0.5.0-macos-aarch64.tar.gz
20-
$ tar xfv spin-v0.5.0-macos-aarch64.tar.gz
21-
$ ./spin --help
17+
```console
18+
$ curl https://spin.fermyon.dev/downloads/install.sh | bash
2219
```
2320

24-
If you have [`cargo`](https://doc.rust-lang.org/cargo/getting-started/installation.html), you can clone the repo and install it to your path:
21+
To install a specific version (or canary), you can pass arguments to the install script this way:
2522

26-
```bash
27-
$ git clone https://github.com/fermyon/spin -b v0.5.0
28-
$ cd spin
29-
$ rustup target add wasm32-wasi
30-
$ cargo install --locked --path .
31-
$ spin --help
23+
```console
24+
$ curl https://spin.fermyon.dev/downloads/install.sh | bash -s -- -v v0.5.0
25+
26+
$ curl https://spin.fermyon.dev/downloads/install.sh | bash -s -- -v canary
27+
```
28+
29+
At this point, move the `spin` binary somewhere in your path, so it can be
30+
accessed from any directory. For example:
31+
32+
```console
33+
$ sudo mv ./spin /usr/local/bin/spin
3234
```
3335

34-
Alternatively, [follow the contribution document](./contributing.md) for a detailed guide
36+
### Alternative 1: Building Spin from source
37+
38+
[Follow the contribution document](./contributing.md) for a detailed guide
3539
on building Spin from source:
3640

37-
```bash
41+
```console
3842
$ git clone https://github.com/fermyon/spin
3943
$ cd spin && make build
4044
$ ./target/release/spin --help
4145
```
4246

43-
At this point, move the `spin` binary somewhere in your path, so it can be
44-
accessed from any directory.
47+
### Alternative 2: Using Cargo to install Spin
48+
49+
If you have [`cargo`](https://doc.rust-lang.org/cargo/getting-started/installation.html), you can clone the repo and install it to your path:
50+
51+
```console
52+
$ git clone https://github.com/fermyon/spin -b v0.4.0
53+
$ cd spin
54+
$ rustup target add wasm32-wasi
55+
$ cargo install --locked --path .
56+
$ spin --help
57+
```
4558

4659
### Linux: Additional Libraries
4760

docs/downloads/install.sh

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Fancy colors for output
5+
RED='\033[0;31m'
6+
GREEN='\033[0;32m'
7+
NC='\033[0m' # No Color aka reset
8+
9+
# Version to install. Defaults to latest or set by --version or -v
10+
VERSION=""
11+
12+
# Print in colors - 0=green, 1=red, 2=neutral
13+
# e.g. fancy_print 0 "All is great"
14+
fancy_print() {
15+
if [[ $1 == 0 ]]; then
16+
echo -e "${GREEN}${2}${NC}"
17+
elif [[ $1 == 1 ]]; then
18+
echo -e "${RED}${2}${NC}"
19+
else
20+
echo -e "${2}"
21+
fi
22+
}
23+
24+
# Function to print the help message
25+
print_help() {
26+
fancy_print 2 ""
27+
fancy_print 2 "---- Spin Installer Script ----"
28+
fancy_print 2 "This script installs Spin in the current directory."
29+
fancy_print 2 ""
30+
fancy_print 2 "Comand line arguments"
31+
fancy_print 2 "--version or -v : Provide what version to install e.g. \"v0.5.0\" or \"canary\"."
32+
fancy_print 2 "--help or -h : Shows this help message"
33+
}
34+
35+
# Function used to check if utilities are available
36+
require() {
37+
if ! hash "$1" &>/dev/null; then
38+
fancy_print 1 "'$1' not found in PATH. This is required for this script to work."
39+
exit 1
40+
fi
41+
}
42+
43+
# Parse input arguments
44+
while [[ $# -gt 0 ]]; do
45+
case $1 in
46+
'--version' | -v)
47+
shift
48+
if [[ $# -ne 0 ]]; then
49+
VERSION="${1}"
50+
else
51+
fancy_print 1 "Please provide the desired version. e.g. --version v0.5.0 or -v canary"
52+
exit 0
53+
fi
54+
;;
55+
'--help' | -h)
56+
shift
57+
print_help
58+
;;
59+
*)
60+
fancy_print 1 "Unknown argument ${1}."
61+
print_help
62+
exit 1
63+
;;
64+
esac
65+
shift
66+
done
67+
68+
# Check all required utilities are available
69+
require wget
70+
require tar
71+
require uname
72+
73+
# Check if we're on a suppoerted system and get OS and processor architecture to download the right version
74+
UNAME_ARC=$(uname -m)
75+
76+
case $UNAME_ARC in
77+
"x86_64")
78+
ARC="amd64"
79+
;;
80+
"arm64" | "aarch64")
81+
ARC="aarch64"
82+
;;
83+
*)
84+
fancy_print 1 "The Processor type: ${UNAME_ARC} is not yet supported by Spin."
85+
exit 1
86+
;;
87+
esac
88+
89+
case $OSTYPE in
90+
"linux-gnu"*)
91+
OS="linux"
92+
if [[ $ARC == "aarch64" ]]; then
93+
fancy_print 1 "The Processor type: ${ARC}, on ${OSTYPE} is not yet supported by Spin."
94+
exit 1
95+
fi
96+
;;
97+
"darwin"*)
98+
OS="macos"
99+
;;
100+
*)
101+
fancy_print 1 "The OSTYPE: ${OSTYPE} is not supported by this script."
102+
fancy_print 2 "Please refer to this article to install Spin: https://spin.fermyon.dev/quickstart/"
103+
exit 1
104+
;;
105+
esac
106+
107+
# Check desired version. Default to latest if no desired version was requested
108+
if [[ $VERSION = "" ]]; then
109+
VERSION=$(wget -qO- https://github.com/fermyon/spin/releases | grep 'href="/fermyon/spin/releases/tag/v[0-9]*.[0-9]*.[0-9]*\"' | sed -E 's/.*\/fermyon\/spin\/releases\/tag\/(v[0-9\.]+)".*/\1/g' | head -1)
110+
fi
111+
112+
# Constructing download FILE and URL
113+
FILE="spin-${VERSION}-${OS}-${ARC}.tar.gz"
114+
URL="https://github.com/fermyon/spin/releases/download/${VERSION}/${FILE}"
115+
116+
# Download file, exit if not found - e.g. version does not exist
117+
fancy_print 0 "Step 1: Downloading: ${URL}"
118+
wget -q $URL || (fancy_print 1 "The requested file does not exist: ${FILE}"; exit 1)
119+
fancy_print 0 "Done...\n"
120+
121+
# Decompress the file
122+
fancy_print 0 "Step 2: Decompressing: ${FILE}"
123+
tar xfv $FILE
124+
./spin --version
125+
fancy_print 0 "Done...\n"
126+
127+
# Remove the compressed file
128+
fancy_print 0 "Step 3: Removing the downloaded tarball"
129+
rm $FILE
130+
fancy_print 0 "Done...\n"
131+
132+
# Direct to quicks-start doc
133+
fancy_print 0 "You're good to go. Check here for the next steps: https://spin.fermyon.dev/quickstart/"
134+
fancy_print 0 "Run './spin' to get started"

docs/spin.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ route = "/..."
1414

1515
[[component]]
1616
source = "modules/spin_static_fs.wasm"
17-
id = "fileserver"
17+
id = "fileserver_static"
1818
files = [ { source = "static/", destination = "/" } ]
1919
[component.trigger]
2020
route = "/static/..."
21+
22+
[[component]]
23+
source = "modules/spin_static_fs.wasm"
24+
id = "fileserver_downloads"
25+
files = [ { source = "downloads/", destination = "/" } ]
26+
[component.trigger]
27+
route = "/downloads/..."

0 commit comments

Comments
 (0)