Skip to content

Commit

Permalink
Update S3, Deb Instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
cdgco committed Apr 6, 2024
1 parent b462c95 commit f4a9953
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 9 deletions.
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,16 @@ To enable automatic updates, the agent must be distributed through an S3 storage

Rack Manage uses Cloudflare R2 rather than AWS S3 for distribution. While `oclif` supports non-AWS S3 storage, there is some additional configuration required to use it.

First, you must set the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables to the Cloudflare R2 credentials. You must also set the `AWS_S3_ENDPOINT` and `AWS_ENDPOINT_URL` environment variables to the Cloudflare R2 endpoint.
### Cloudflare R2 Configuration

The Rack Manage Agent R2 server is configured to use the `rmagent` bucket on the `agent.rackmanage.io` domain. This domain is registered in the Rack Manage Subdomain Router and is excluded in the banned names list of the cloud functions repository.

First, you must set the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables to the Cloudflare R2 credentials. You must also set the `AWS_ENDPOINT_URL_S3` variable to the Cloudflare R2 endpoint.

```bash
export AWS_ACCESS_KEY_ID=<READ_WRITE_ACCESS_KEY>
export AWS_SECRET_ACCESS_KEY=<SECRET_ACCESS_KEY>
export AWS_S3_ENDPOINT=https://<ACCOUNT_ID>.r2.cloudflarestorage.com
export AWS_ENDPOINT_URL=https://<ACCOUNT_ID>.r2.cloudflarestorage.com
export AWS_ENDPOINT_URL_S3=https://<ACCOUNT_ID>.r2.cloudflarestorage.com
```

Once these environment variables are set, you can upload the agent to Cloudflare R2 by running the following command:
Expand All @@ -154,21 +157,31 @@ oclif promote --channel <channel> --version <version> --sha <sha> --indexes --xz

Where `<channel>` is the release channel to publish to, such as `stable` or `beta`, `<version>` is the version number, and `<sha>` is the 7 character git commit hash.

By default, this command will only publish tarballs. To publish other types of files, you must specify the type with the `-m`, or `-w` flags for deb, macos, and win files, respectively.
By default, this command will only publish tarballs. To publish other types of files, you must specify the type with the `-m`, or `-w` flags for macos, and win files, respectively.

### Debian Packages

The Debian commands `oclif upload deb` and `oclif promote -d` do not work properly (see [oclif issue #1074](https://github.com/oclif/oclif/issues/1074)) due to the improper use of `./` as the Debian distribution.
The Debian commands `oclif upload deb` and `oclif promote -d` do not work properly (see [oclif issue #1074](https://github.com/oclif/oclif/issues/1074)) due to the use of `./` as the Debian distribution, where S3 does not support folders named `.`.

To work around this, you can manually upload the Debian package to Cloudflare R2 through the `aws` CLI with the following command:

```bash
aws s3 cp dist/deb s3://rmagent/channels/stable/apt --recursive
aws s3 cp dist/deb s3://rmagent/apt --recursive
```

In order to handle the cases where Debian attempts to download the package from the `./` directory, a redirect is setup in the Rack Manage Subdomain Router to redirect requests from `https://rmagent-assets.rackmanage.io/channels/stable/apt/./` to `https://rmagent-assets.rackmanage.io/channels/stable/apt/`.
In order to handle the cases where Debian attempts to download the package from the `./` directory, a redirect is setup in the Rack Manage Subdomain Router to redirect requests from `https://agent.rackmanage.io/apt/./` to `https://agent.rackmanage.io/apt/`. Note that the apt reposity does not support release channels and only the latest version is available.

The Debian repository also includes two additional files, `Release.key` and `install.sh` which are used to add the GPG key to the system, and automate the installation of the package. These are manually uploaded to the repository and are not generated by `oclif`. `install.sh` is located in the `scripts` directory and `Release.key` is not included in the repository.

The Debian repository also includes two additional files, `Release.key` and `install.sh` which are used to add the GPG key to the system, and automate the installation of the package. These are manually uploaded to the repository and are not generated by `oclif`.
To update `install.sh` and `Release.key`, run the following commands:

```bash
aws s3 cp scripts/install.sh s3://rmagent/install.sh
```

```bash
aws s3 cp Release.key s3://rmagent/apt/Release.key
```

## Service Management
This agent is designed to run as a service in both user and system contexts (on login and on boot) for Linux, Windows, and MacOS, using systemd, launchd, and the Windows Service Manager, respectively. The service is configured to run the agent in the background and restart it if it crashes.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
},
"update": {
"s3": {
"host": "https://rmagent-assets.rackmanage.io",
"host": "https://agent.rackmanage.io",
"bucket": "rmagent",
"xz": true
}
Expand Down
46 changes: 46 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh

{
set -e
SUDO=''
if [ "$(id -u)" != "0" ]; then
SUDO='sudo'
echo "This script requires superuser access."
echo "You will be prompted for your password by sudo."
sudo -k
fi

$SUDO sh <<SCRIPT
set -ex
# Check if apt-transport-https is installed, install if not
if ! dpkg -s apt-transport-https >/dev/null 2>&1; then
apt-get update
apt-get install -y apt-transport-https
fi
APT_VERSION=$(apt --version | cut -d ' ' -f 2)
MIN_VERSION="1.1" # Example minimum version that supports signed-by, adjust as needed
# If we're on a version of apt that supports signed-by, use it
if dpkg --compare-versions "\$APT_VERSION" ge "\$MIN_VERSION"; then
if ! grep -q "^deb https://agent.rackmanage.io/apt ./$" /etc/apt/sources.list /etc/apt/sources.list.d/*; then
echo "deb [signed-by=/usr/share/keyrings/rmagent.gpg] https://agent.rackmanage.io/apt ./" | tee /etc/apt/sources.list.d/rmagent.list
curl -sL https://agent.rackmanage.io/apt/Release.key -o /usr/share/keyrings/rmagent.gpg
fi
else
if ! grep -q "^deb https://agent.rackmanage.io/apt ./$" /etc/apt/sources.list /etc/apt/sources.list.d/*; then
echo "deb https://agent.rackmanage.io/apt ./" | tee /etc/apt/sources.list.d/rmagent.list
curl -sL https://agent.rackmanage.io/apt/Release.key | apt-key add -
fi
fi
apt-get update
apt-get install -y libsecret-1-dev ipmitool rmagent
SCRIPT

LOCATION=$(which rmagent)
echo "rmagent installed to $LOCATION"
rmagent version
}

0 comments on commit f4a9953

Please sign in to comment.