Skip to content

Commit

Permalink
Pull from GitHub for latest version when installing
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Kim <[email protected]>
  • Loading branch information
Oats87 committed Mar 4, 2021
1 parent 5467b06 commit 78914b0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
13 changes: 12 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,18 @@ setup_env() {
fi

if [ -z "${CATTLE_AGENT_BINARY_URL}" ]; then
CATTLE_AGENT_BINARY_URL=https://github.com/Oats87/rancher-agent/releases/download/v0.0.2/rancher-agent
FALLBACK=v0.0.1-alpha1
if [[ $(curl --silent https://api.github.com/rate_limit | grep '"rate":' -A 4 | grep '"remaining":' | sed -E 's/.*"[^"]+": (.*),/\1/') = 0 ]]; then
info "GitHub Rate Limit exceeded, falling back to known good version"
VERSION=$FALLBACK
else
VERSION=$(curl --silent "https://api.github.com/repos/rancher/system-agent/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [[ -z "$VERSION" ]]; then # Fall back to a known good fallback version because we had an error pulling the latest
info "Error contacting GitHub to retrieve the latest version"
VERSION=$FALLBACK
fi
fi
CATTLE_AGENT_BINARY_URL="https://github.com/rancher/system-agent/releases/download/${VERSION}/rancher-system-agent"
fi

if [ "${CATTLE_REMOTE_ENABLED}" = "true" ]; then
Expand Down
4 changes: 2 additions & 2 deletions package/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM alpine
COPY bin/rancher-agent /usr/bin/
CMD ["rancher-agent"]
COPY bin/rancher-system-agent /usr/bin/
CMD ["rancher-system-agent"]
6 changes: 3 additions & 3 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ if [ "$(uname)" = "Linux" ]; then
fi
LINKFLAGS="-X github.com/rancher/system-agent.Version=$VERSION"
LINKFLAGS="-X github.com/rancher/system-agent.GitCommit=$COMMIT $LINKFLAGS"
CGO_ENABLED=0 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/rancher-agent
CGO_ENABLED=0 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/rancher-system-agent
if [ "$CROSS" = "true" ] && [ "$ARCH" = "amd64" ]; then
GOOS=darwin go build -ldflags "$LINKFLAGS" -o bin/rancher-agent-darwin
GOOS=windows go build -ldflags "$LINKFLAGS" -o bin/rancher-agent-windows
GOOS=darwin go build -ldflags "$LINKFLAGS" -o bin/rancher-system-agent-darwin
GOOS=windows go build -ldflags "$LINKFLAGS" -o bin/rancher-system-agent-windows
fi
4 changes: 2 additions & 2 deletions scripts/package
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ source $(dirname $0)/version
cd $(dirname $0)/..

mkdir -p dist/artifacts
cp bin/rancher-agent dist/artifacts/rancher-agent${SUFFIX}
cp bin/rancher-system-agent dist/artifacts/rancher-system-agent${SUFFIX}

IMAGE=${REPO}/rancher-agent:${TAG}
IMAGE=${REPO}/rancher-system-agent:${TAG}
DOCKERFILE=package/Dockerfile
if [ -e ${DOCKERFILE}.${ARCH} ]; then
DOCKERFILE=${DOCKERFILE}.${ARCH}
Expand Down
2 changes: 1 addition & 1 deletion scripts/version
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fi
SUFFIX="-${ARCH}"

TAG=${TAG:-${VERSION}${SUFFIX}}
REPO=${REPO:-oats87}
REPO=${REPO:-rancher}

if echo $TAG | grep -q dirty; then
TAG=dev
Expand Down

0 comments on commit 78914b0

Please sign in to comment.