Skip to content

Commit

Permalink
Add Version Deletion Script
Browse files Browse the repository at this point in the history
  • Loading branch information
cdgco committed Apr 10, 2024
1 parent 0486de3 commit e86fc18
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ aws s3 cp Release.key s3://rmagent/apt/Release.key

## Automated Builds

[![CircleCI](https://dl.circleci.com/insights-snapshot/gh/RackManage/agent/main/build_and_release/badge.svg?window=24h)](https://app.circleci.com/insights/github/RackManage/agent?branches=main&workflows=build_and_release&reporting-window=last-24-hours&insights-snapshot=true)
[![CircleCI](https://dl.circleci.com/insights-snapshot/gh/RackManage/agent/main/build_and_release/badge.svg?window=30d)](https://app.circleci.com/insights/github/RackManage/agent?branches=main&workflows=build_and_release&reporting-window=last-30-days&insights-snapshot=true)


The agent is built and distributed automatically through CircleCI. The build process is defined in the `.circleci/config.yml` file and is triggered by pushing tags to the repository. Pushing tags will trigger builds to the `stable` release channel.
Expand Down Expand Up @@ -238,6 +238,19 @@ The public key should also be uploaded to the Ubuntu keyserver with `gpg --send-

The build process will also update `install.sh` and the `Release.key` file in the Debian repository using the public key in the `GPG_PUBLIC_KEY` environment variable.

## Deleting Versions
oclif does not provide any built in method to delete old versions from S3 storage. To remove previous versions from the update server, use the following command:

```bash
./scripts/delete-s3-version.sh <version>
```

Where `<version>` is the version number to delete (e.g. `1.0.0`).

You must have `jq` and `aws` installed to run this script, and your S3 credentials must be set in the `AWS_` environment variables as described above.

Note that this does not remove the latest version from the public / beta release channels or the apt repo, it only removes the ability for users to update to that specific version from the CLI.

## 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
53 changes: 53 additions & 0 deletions scripts/delete-s3-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

# Check if a version number is passed as an argument
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <version_to_delete>"
exit 1
fi

# Check if jq is installed
if ! [ -x "$(command -v jq)" ]; then
echo 'Error: jq is not installed.' >&2
exit 1
fi

# Check if aws-cli is installed
if ! [ -x "$(command -v aws)" ]; then
echo 'Error: aws-cli is not installed.' >&2
exit 1
fi

VERSION_TO_DELETE="$1"
BUCKET_NAME="rmagent"

aws s3 ls s3://${BUCKET_NAME}/versions/ | grep '.json$' | awk '{print $4}' | while read -r manifest; do
# Download the manifest file
aws s3 cp s3://${BUCKET_NAME}/versions/${manifest} ./tmp/

# Remove the specified version key from the manifest
if [ -f ./tmp/$(basename "$manifest") ]; then
if [ $(jq ".\"${VERSION_TO_DELETE}\"" ./tmp/$(basename "$manifest")) != "null" ]; then
jq "del(.\"${VERSION_TO_DELETE}\")" ./tmp/$(basename "$manifest") > ./tmp/updated_manifest.json

# Upload the updated manifest back to S3
aws s3 cp ./tmp/updated_manifest.json s3://${BUCKET_NAME}/versions/${manifest}
else
echo "WARNING: Version ${VERSION_TO_DELETE} not found in manifest file ${manifest}"
fi

# Cleanup local files
rm ./tmp/$(basename "$manifest")
else
echo "Error: Could not download manifest file ${manifest}"
exit 1
fi
done

# Remove updated manifest
if [ -f ./tmp/updated_manifest.json ]; then
rm ./tmp/updated_manifest.json
fi

# List all objects in the version directory and delete them
aws s3 rm s3://${BUCKET_NAME}/versions/${VERSION_TO_DELETE}/ --recursive

0 comments on commit e86fc18

Please sign in to comment.