Skip to content

Commit 7b47bfa

Browse files
committed
system agent upgrade script
1 parent d4b2ed3 commit 7b47bfa

File tree

6 files changed

+105
-4
lines changed

6 files changed

+105
-4
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: System Agent Upgrade
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
system_agent_version:
6+
type: string
7+
description: "system agent version to update"
8+
source_author:
9+
type: string
10+
description: "Username of the source for this workflow run"
11+
12+
env:
13+
SYSTEM_AGENT_VERSION: ${{ github.event.inputs.system_agent_version }}
14+
INPUT_SOURCE_AUTHOR: ${{ github.event.inputs.source_author }}
15+
16+
permissions:
17+
contents: write
18+
pull-requests: write
19+
jobs:
20+
system-agent-update:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Check out repository code
24+
uses: actions/checkout@v2
25+
- name: Update system agent in files
26+
run: make system-agent-upgrade
27+
- name: Check for repository changes
28+
run: |
29+
if git diff --name-only --exit-code; then
30+
echo "No changes found in repository after 'go get'"
31+
echo "changes_exist=false" >> $GITHUB_ENV
32+
else
33+
echo "Changes found in repository after 'go get':"
34+
git diff --name-only
35+
echo "changes_exist=true" >> $GITHUB_ENV
36+
fi
37+
- name: Create branch, commit and push
38+
if: ${{ env.changes_exist == 'true' }}
39+
id: branch
40+
run: |
41+
BRANCH="githubaction-system-agent-upgrade-$(date +%Y-%m-%d-%H-%M-%S)"
42+
echo "::set-output name=branch::$BRANCH"
43+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
44+
git config --global user.name "github-actions[bot]"
45+
git checkout -b "$BRANCH"
46+
git commit -a -m "updated system-agent to ${SYSTEM_AGENT_VERSION}"
47+
git push origin "$BRANCH"
48+
- name: Create Pull Request
49+
if: ${{ env.changes_exist == 'true' }}
50+
id: cpr
51+
uses: actions/[email protected]
52+
env:
53+
SOURCE_BRANCH: ${{ steps.branch.outputs.branch }}
54+
with:
55+
github-token: ${{ secrets.GITHUB_TOKEN }}
56+
script: |
57+
const { SYSTEM_AGENT_VERSION } = process.env
58+
let body = 'Auto-generated by GitHub Actions\n\n'
59+
if ( `${ process.env.INPUT_SOURCE_URL }` ) {
60+
body += `\nSource URL: ${ process.env.INPUT_SOURCE_URL }`
61+
}
62+
if ( `${ process.env.INPUT_SOURCE_AUTHOR }` ) {
63+
body += `\nSource AUTHOR: @${ process.env.INPUT_SOURCE_AUTHOR}`
64+
}
65+
66+
const { data: pr } = await github.rest.pulls.create({
67+
title: `[${{ github.ref_name }}] update system-agent to ${SYSTEM_AGENT_VERSION}`,
68+
body: body,
69+
owner: context.repo.owner,
70+
repo: context.repo.repo,
71+
base: "${{ github.ref_name }}",
72+
head: `${ process.env.SOURCE_BRANCH }`
73+
});
74+
await github.rest.issues.addLabels({
75+
...context.repo,
76+
issue_number: pr.number,
77+
labels: ["status/auto-created"],
78+
});
79+
if ( `${ process.env.INPUT_SOURCE_AUTHOR }` ) {
80+
await github.rest.issues.addAssignees({
81+
...context.repo,
82+
issue_number: pr.number,
83+
assignees: [`${ process.env.INPUT_SOURCE_AUTHOR}`],
84+
});
85+
}
86+
console.log('Created new pull request');
87+
return pr.html_url;
88+
- name: Check outputs
89+
if: ${{ env.changes_exist == 'true' }}
90+
run: |
91+
echo "Pull Request URL - ${{ steps.cpr.outputs.result }}"

Dockerfile.dapper

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ RUN curl -sLf https://github.com/rancher/k3s/releases/download/${CATTLE_K3S_VERS
119119
RUN zypper -n install python311-pip python311-base python311 python311-devel python311-tox libffi-devel libopenssl-devel
120120

121121
ENV HELM_HOME /root/.helm
122-
ENV DAPPER_ENV REPO TAG CI DRONE_BUILD_NUMBER DRONE_TAG DRONE_COMMIT DRONE_BRANCH DRONE_BUILD_EVENT SYSTEM_CHART_DEFAULT_BRANCH FOSSA_API_KEY GOGET_MODULE GOGET_VERSION RELEASE_ACTION RELEASE_TYPE POSTRELEASE_RANCHER_VERSION POSTRELEASE_RANCHER_STABLE DEBUG SOME_K8S_VERSION V2PROV_TEST_DIST V2PROV_TEST_RUN_REGEX V2PROV_DISTRO_DATA_DIR V2PROV_PROVISIONING_DATA_DIR V2PROV_SYSTEM_AGENT_DATA_DIR
122+
ENV DAPPER_ENV REPO TAG CI DRONE_BUILD_NUMBER DRONE_TAG DRONE_COMMIT DRONE_BRANCH DRONE_BUILD_EVENT SYSTEM_CHART_DEFAULT_BRANCH FOSSA_API_KEY GOGET_MODULE GOGET_VERSION RELEASE_ACTION RELEASE_TYPE POSTRELEASE_RANCHER_VERSION POSTRELEASE_RANCHER_STABLE DEBUG SOME_K8S_VERSION V2PROV_TEST_DIST V2PROV_TEST_RUN_REGEX V2PROV_DISTRO_DATA_DIR V2PROV_PROVISIONING_DATA_DIR V2PROV_SYSTEM_AGENT_DATA_DIR SYSTEM_AGENT_VERSION
123123
ENV DAPPER_SOURCE /go/src/github.com/rancher/rancher/
124124
ENV DAPPER_OUTPUT ./bin ./dist ./go.mod ./go.sum ./pkg/apis/go.mod ./pkg/apis/go.sum ./pkg/client/go.mod ./pkg/client/go.sum ./scripts/package ./pkg/settings/setting.go ./package/Dockerfile ./Dockerfile.dapper ./pkg/crds/yaml/generated
125125
ENV DAPPER_DOCKER_SOCKET true

package/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ ENV CATTLE_WINS_AGENT_UNINSTALL_SCRIPT https://raw.githubusercontent.com/rancher
7474
ENV CATTLE_WINS_AGENT_UPGRADE_IMAGE rancher/wins:${CATTLE_WINS_AGENT_VERSION}
7575
ENV CATTLE_CSI_PROXY_AGENT_VERSION v1.1.3
7676
# make sure the CATTLE_SYSTEM_AGENT_VERSION is consistent with tests/v2/codecoverage/package/Dockerfile
77-
ENV CATTLE_SYSTEM_AGENT_VERSION v0.3.9-rc.4
77+
ENV CATTLE_SYSTEM_AGENT_VERSION v0.3.9-rc.6
7878
ENV CATTLE_SYSTEM_AGENT_DOWNLOAD_PREFIX https://github.com/rancher/system-agent/releases/download
7979
ENV CATTLE_SYSTEM_AGENT_UPGRADE_IMAGE rancher/system-agent:${CATTLE_SYSTEM_AGENT_VERSION}-suc
8080
ENV CATTLE_SYSTEM_AGENT_INSTALLER_IMAGE rancher/system-agent-installer-

pkg/settings/setting.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ var (
103103
WinsAgentVersion = NewSetting("wins-agent-version", "")
104104
CSIProxyAgentVersion = NewSetting("csi-proxy-agent-version", "")
105105
CSIProxyAgentURL = NewSetting("csi-proxy-agent-url", "https://acs-mirror.azureedge.net/csi-proxy/%[1]s/binaries/csi-proxy-%[1]s.tar.gz")
106-
SystemAgentInstallScript = NewSetting("system-agent-install-script", "https://github.com/rancher/system-agent/releases/download/v0.3.9-rc.4/install.sh") // To ensure consistency between SystemAgentInstallScript default value and CATTLE_SYSTEM_AGENT_INSTALL_SCRIPT to utilize the local system-agent-install.sh script when both values are equal.
106+
SystemAgentInstallScript = NewSetting("system-agent-install-script", "https://github.com/rancher/system-agent/releases/download/v0.3.9-rc.6/install.sh") // To ensure consistency between SystemAgentInstallScript default value and CATTLE_SYSTEM_AGENT_INSTALL_SCRIPT to utilize the local system-agent-install.sh script when both values are equal.
107107
WinsAgentInstallScript = NewSetting("wins-agent-install-script", "https://raw.githubusercontent.com/rancher/wins/v0.4.18-rc1/install.ps1")
108108
SystemAgentInstallerImage = NewSetting("system-agent-installer-image", "") // Defined via environment variable
109109
SystemAgentUpgradeImage = NewSetting("system-agent-upgrade-image", "") // Defined via environment variable

scripts/system-agent-upgrade

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -e
3+
VERSION=$SYSTEM_AGENT_VERSION
4+
5+
updated_install_script_url="https://github.com/rancher/system-agent/releases/download/${VERSION}/install.sh" # update it to regular expression
6+
existing_install_script_url=$(grep -E -o 'https:\/\/github.com\/rancher\/system-agent\/releases\/download\/[^/]+\/install.sh' pkg/settings/setting.go)
7+
sed -i "s|$existing_install_script_url|$updated_install_script_url|g" pkg/settings/setting.go
8+
9+
sed -i "s|^ENV CATTLE_SYSTEM_AGENT_VERSION .\+$|ENV CATTLE_SYSTEM_AGENT_VERSION ${VERSION}|g" package/Dockerfile # try to use regex to avoid extracting the string from the file
10+
sed -i "s|^ENV CATTLE_SYSTEM_AGENT_VERSION .\+$|ENV CATTLE_SYSTEM_AGENT_VERSION ${VERSION}|g" tests/v2/codecoverage/package/Dockerfile # try to use regex to avoid extracting the string from the file

tests/v2/codecoverage/package/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ ENV CATTLE_WINS_AGENT_UNINSTALL_SCRIPT https://raw.githubusercontent.com/rancher
7373
ENV CATTLE_WINS_AGENT_UPGRADE_IMAGE rancher/wins:${CATTLE_WINS_AGENT_VERSION}
7474
ENV CATTLE_CSI_PROXY_AGENT_VERSION v1.1.3
7575
# make sure the CATTLE_SYSTEM_AGENT_VERSION is consistent with tests/v2/codecoverage/package/Dockerfile
76-
ENV CATTLE_SYSTEM_AGENT_VERSION v0.3.9-rc.4
76+
ENV CATTLE_SYSTEM_AGENT_VERSION v0.3.9-rc.6
7777
ENV CATTLE_SYSTEM_AGENT_DOWNLOAD_PREFIX https://github.com/rancher/system-agent/releases/download
7878
ENV CATTLE_SYSTEM_AGENT_UPGRADE_IMAGE rancher/system-agent:${CATTLE_SYSTEM_AGENT_VERSION}-suc
7979
ENV CATTLE_SYSTEM_AGENT_INSTALLER_IMAGE rancher/system-agent-installer-

0 commit comments

Comments
 (0)