Skip to content

Commit 60fc5d3

Browse files
authored
Add install scripts (#1232)
* Add install script * Remove release logic * Update docs * Add sudo
1 parent 7941c79 commit 60fc5d3

File tree

4 files changed

+155
-24
lines changed

4 files changed

+155
-24
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ jobs:
159159
gh release upload ${{ needs.release-drafter.outputs.tag_name }} .artifacts/publish/docs-builder/release/*.zip
160160
gh release upload ${{ needs.release-drafter.outputs.tag_name }} .artifacts/publish/docs-assembler/release/*.zip
161161
shell: bash
162-
162+
163163
publish-release:
164164
needs:
165165
- release

docs/contribute/locally.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,44 +30,43 @@ This guide uses the first option. If you'd like to clone the repository and buil
3030

3131
:::{tab-item} macOS
3232

33-
1. **Download the Binary:**
34-
Download the latest macOS binary from [releases](https://github.com/elastic/docs-builder/releases/latest/):
35-
```sh
36-
curl -LO https://github.com/elastic/docs-builder/releases/latest/download/docs-builder-mac-arm64.zip
37-
```
33+
1. **Download and run the install script**
34+
35+
Run this command to download and install the latest version of `docs-builder`:
3836

39-
2. **Extract the Binary:**
40-
Unzip the downloaded file:
4137
```sh
42-
unzip docs-builder-mac-arm64.zip
38+
sudo curl -L https://raw.githubusercontent.com/elastic/docs-builder/refs/heads/main/install.sh | sh
4339
```
40+
This downloads the latest binary, makes it executable, and installs it to your user PATH.
41+
42+
2. **Run docs-builder from a docs folder**
43+
44+
Use the `serve` command from any docs folder to start serving the documentation at http://localhost:3000. The path to the `docset.yml` file that you want to build can be specified with `-p`:
4445

45-
3. **Run the Binary:**
46-
Use the `serve` command to start serving the documentation at http://localhost:3000. The path to the `docset.yml` file that you want to build can be specified with `-p`:
4746
```sh
48-
./docs-builder serve -p ./path/to/docs
47+
docs-builder serve
4948
```
5049

5150
:::
5251

5352
:::{tab-item} Windows
5453

55-
1. **Download the Binary:**
56-
Download the latest Windows binary from [releases](https://github.com/elastic/docs-builder/releases/latest/):
57-
```sh
58-
Invoke-WebRequest -Uri https://github.com/elastic/docs-builder/releases/latest/download/docs-builder-win-x64.zip -OutFile docs-builder-win-x64.zip
59-
```
54+
1. **Download and run the install script**
6055

61-
2. **Extract the Binary:**
62-
Unzip the downloaded file. You can use tools like WinZip, 7-Zip, or the built-in Windows extraction tool.
63-
```sh
64-
Expand-Archive -Path docs-builder-win-x64.zip -DestinationPath .
56+
Run this command to download and install the latest version of `docs-builder`:
57+
58+
```powershell
59+
iex (New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/elastic/docs-builder/refs/heads/main/install.ps1')
6560
```
6661

67-
3. **Run the Binary:**
68-
Use the `serve` command to start serving the documentation at http://localhost:3000. The path to the `docset.yml` file that you want to build can be specified with `-p`:
62+
This downloads the latest binary, makes it executable, and installs it to your user PATH.
63+
64+
2. **Run docs-builder from a docs folder**
65+
66+
Use the `serve` command from any docs folder to start serving the documentation at http://localhost:3000. The path to the `docset.yml` file that you want to build can be specified with `-p`:
67+
6968
```sh
70-
.\docs-builder serve -p ./path/to/docs
69+
docs-builder serve
7170
```
7271

7372
:::

install.ps1

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# PowerShell script to install docs-builder binary
2+
3+
# Use AppData\Local for user-specific installation instead of Program Files
4+
$targetDir = Join-Path -Path $env:LOCALAPPDATA -ChildPath "docs-builder"
5+
$targetPath = Join-Path -Path $targetDir -ChildPath "docs-builder.exe"
6+
7+
# Check if docs-builder already exists
8+
if (Test-Path -Path $targetPath) {
9+
Write-Host "docs-builder is already installed."
10+
$choice = Read-Host -Prompt "Do you want to update/overwrite it? (y/n)"
11+
switch ($choice.ToLower()) {
12+
'y' { Write-Host "Updating docs-builder..." }
13+
'n' { Write-Host "Installation aborted."; exit 0 }
14+
Default { Write-Host "Invalid choice. Installation aborted."; exit 1 }
15+
}
16+
}
17+
18+
# Create target directory if it doesn't exist
19+
if (-not (Test-Path -Path $targetDir)) {
20+
New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
21+
}
22+
23+
# Download the latest Windows binary from releases
24+
$tempZipPath = "$env:TEMP\docs-builder-win-x64.zip"
25+
Write-Host "Downloading docs-builder binary..."
26+
Invoke-WebRequest -Uri "https://github.com/elastic/docs-builder/releases/latest/download/docs-builder-win-x64.zip" -OutFile $tempZipPath
27+
28+
# Create a temporary directory for extraction
29+
$tempExtractPath = "$env:TEMP\docs-builder-extract"
30+
if (Test-Path -Path $tempExtractPath) {
31+
Remove-Item -Path $tempExtractPath -Recurse -Force
32+
}
33+
New-Item -ItemType Directory -Path $tempExtractPath -Force | Out-Null
34+
35+
# Extract the binary
36+
Write-Host "Extracting binary..."
37+
Expand-Archive -Path $tempZipPath -DestinationPath $tempExtractPath -Force
38+
39+
# Copy the executable to the target location
40+
Write-Host "Installing docs-builder..."
41+
Copy-Item -Path "$tempExtractPath\docs-builder.exe" -Destination $targetPath -Force
42+
43+
# Add to PATH if not already in PATH (using User scope instead of Machine)
44+
$currentPath = [Environment]::GetEnvironmentVariable("PATH", [EnvironmentVariableTarget]::User)
45+
if ($currentPath -notlike "*$targetDir*") {
46+
Write-Host "Adding docs-builder to the user PATH..."
47+
[Environment]::SetEnvironmentVariable(
48+
"PATH",
49+
"$currentPath;$targetDir",
50+
[EnvironmentVariableTarget]::User
51+
)
52+
$env:PATH = "$env:PATH;$targetDir"
53+
}
54+
55+
# Clean up temporary files
56+
Remove-Item -Path $tempZipPath -Force
57+
Remove-Item -Path $tempExtractPath -Recurse -Force
58+
59+
Write-Host "docs-builder has been installed successfully and is available in your PATH."
60+
Write-Host "You may need to restart your terminal or PowerShell session for the PATH changes to take effect."

install.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Determine OS type and architecture
5+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
6+
ARCH=$(uname -m)
7+
8+
# Map architecture naming
9+
if [ "$ARCH" = "x86_64" ]; then
10+
ARCH="amd64"
11+
elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
12+
ARCH="arm64"
13+
fi
14+
15+
# Determine binary to download based on OS
16+
if [ "$OS" = "darwin" ]; then
17+
BINARY="docs-builder-mac-$ARCH.zip"
18+
DEFAULT_INSTALL_DIR="/usr/local/bin"
19+
elif [ "$OS" = "linux" ]; then
20+
BINARY="docs-builder-linux-$ARCH.zip"
21+
DEFAULT_INSTALL_DIR="/usr/local/bin"
22+
else
23+
echo "Unsupported operating system: $OS"
24+
exit 1
25+
fi
26+
27+
# Determine if we need sudo for the install directory
28+
INSTALL_DIR="$DEFAULT_INSTALL_DIR"
29+
if [ ! -w "$INSTALL_DIR" ]; then
30+
USE_SUDO=true
31+
echo "Note: Installing to $INSTALL_DIR requires administrator privileges."
32+
else
33+
USE_SUDO=false
34+
fi
35+
36+
# Check if docs-builder already exists
37+
if [ -f "$INSTALL_DIR/docs-builder" ]; then
38+
echo "docs-builder is already installed."
39+
printf "Do you want to update/overwrite it? (y/n): "
40+
read choice
41+
case "$choice" in
42+
y|Y ) echo "Updating docs-builder..." ;;
43+
n|N ) echo "Installation aborted."; exit 0 ;;
44+
* ) echo "Invalid choice. Installation aborted."; exit 1 ;;
45+
esac
46+
fi
47+
48+
echo "Downloading docs-builder for $OS/$ARCH..."
49+
50+
# Download the appropriate binary
51+
curl -LO "https://github.com/elastic/docs-builder/releases/latest/download/$BINARY"
52+
53+
# Extract only the docs-builder file to /tmp directory
54+
# Use -o flag to always overwrite files without prompting
55+
unzip -j -o "$BINARY" docs-builder -d /tmp
56+
57+
# Ensure the binary is executable
58+
chmod +x /tmp/docs-builder
59+
60+
# Move the binary to the install directory
61+
echo "Installing docs-builder to $INSTALL_DIR..."
62+
if [ "$USE_SUDO" = true ]; then
63+
sudo mv -f /tmp/docs-builder "$INSTALL_DIR/docs-builder"
64+
else
65+
mv -f /tmp/docs-builder "$INSTALL_DIR/docs-builder"
66+
fi
67+
68+
# Clean up the downloaded zip file
69+
rm -f "$BINARY"
70+
71+
echo "docs-builder has been installed successfully and is available in your PATH."
72+
echo "You can run 'docs-builder --help' to see available commands."

0 commit comments

Comments
 (0)