diff --git a/go.mod b/go.mod index 7c14d17..755e6b8 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ toolchain go1.22.1 require ( github.com/BurntSushi/toml v1.2.1 - github.com/cloudbase/garm-provider-common v0.1.1 + github.com/cloudbase/garm-provider-common v0.1.2 github.com/google/uuid v1.3.0 github.com/gophercloud/gophercloud v1.11.0 github.com/gophercloud/utils v0.0.0-20230324070755-05e9e7f5ea4d diff --git a/go.sum b/go.sum index 8fd8362..72d8997 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/cloudbase/garm-provider-common v0.1.1 h1:9SbkEevpycI/P3J7jEmjJf6VzdrxAIHkLppnjqaKAWU= github.com/cloudbase/garm-provider-common v0.1.1/go.mod h1:igxJRT3OlykERYc6ssdRQXcb+BCaeSfnucg6I0OSoDc= +github.com/cloudbase/garm-provider-common v0.1.2 h1:EqSpUjw9rzo4PiUmteHkFtZNWCnRi0QXHRKZ+VA1IPo= +github.com/cloudbase/garm-provider-common v0.1.2/go.mod h1:igxJRT3OlykERYc6ssdRQXcb+BCaeSfnucg6I0OSoDc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/vendor/github.com/cloudbase/garm-provider-common/cloudconfig/cloudconfig.go b/vendor/github.com/cloudbase/garm-provider-common/cloudconfig/cloudconfig.go index fe468ec..a49fe42 100644 --- a/vendor/github.com/cloudbase/garm-provider-common/cloudconfig/cloudconfig.go +++ b/vendor/github.com/cloudbase/garm-provider-common/cloudconfig/cloudconfig.go @@ -34,6 +34,7 @@ func NewDefaultCloudInitConfig() *CloudInit { "curl", "tar", }, + Users: []string{"default"}, SystemInfo: &SystemInfo{ DefaultUser: DefaultUser{ Name: defaults.DefaultUser, @@ -69,6 +70,7 @@ type File struct { type CloudInit struct { mux sync.Mutex + Users []string `yaml:"users"` PackageUpgrade bool `yaml:"package_upgrade"` Packages []string `yaml:"packages,omitempty"` SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys,omitempty"` diff --git a/vendor/github.com/cloudbase/garm-provider-common/cloudconfig/templates.go b/vendor/github.com/cloudbase/garm-provider-common/cloudconfig/templates.go index d3cb660..ab51d8e 100644 --- a/vendor/github.com/cloudbase/garm-provider-common/cloudconfig/templates.go +++ b/vendor/github.com/cloudbase/garm-provider-common/cloudconfig/templates.go @@ -47,23 +47,30 @@ function call() { curl --retry 5 --retry-delay 5 --retry-connrefused --fail -s -X POST -d "${PAYLOAD}" -H 'Accept: application/json' -H "Authorization: Bearer ${BEARER_TOKEN}" "${CALLBACK_URL}" || echo "failed to call home: exit code ($?)" } +function systemInfo() { + if [ -f "/etc/os-release" ];then + . /etc/os-release + fi + OS_NAME=${NAME:-""} + OS_VERSION=${VERSION_ID:-""} + AGENT_ID=${1:-null} + # strip status from the callback url + [[ $CALLBACK_URL =~ ^(.*)/status(/)?$ ]] && CALLBACK_URL="${BASH_REMATCH[1]}" || true + SYSINFO_URL="${CALLBACK_URL}/system-info/" + PAYLOAD="{\"os_name\": \"$OS_NAME\", \"os_version\": \"$OS_VERSION\", \"agent_id\": $AGENT_ID}" + curl --retry 5 --retry-delay 5 --retry-connrefused --fail -s -X POST -d "${PAYLOAD}" -H 'Accept: application/json' -H "Authorization: Bearer ${BEARER_TOKEN}" "${SYSINFO_URL}" || true +} + function sendStatus() { MSG="$1" call "{\"status\": \"installing\", \"message\": \"$MSG\"}" } -{{- if .UseJITConfig }} function success() { MSG="$1" - call "{\"status\": \"idle\", \"message\": \"$MSG\"}" -} -{{- else}} -function success() { - MSG="$1" - ID=$2 + ID=${2:-null} call "{\"status\": \"idle\", \"message\": \"$MSG\", \"agent_id\": $ID}" } -{{- end}} function fail() { MSG="$1" @@ -147,6 +154,10 @@ SVC_NAME=$(cat /home/{{ .RunnerUsername }}/actions-runner/.service) sendStatus "generating systemd unit file" getRunnerFile "systemd/unit-file?runAsUser={{ .RunnerUsername }}" "$SVC_NAME" || fail "failed to get service file" sudo mv $SVC_NAME /etc/systemd/system/ || fail "failed to move service file" +sudo chown root:root /etc/systemd/system/$SVC_NAME || fail "failed to change owner" +if [ -e "/sys/fs/selinux" ];then + sudo chcon -h system_u:object_r:systemd_unit_file_t:s0 /etc/systemd/system/$SVC_NAME || fail "failed to change selinux context" +fi sendStatus "enabling runner service" cp /home/{{ .RunnerUsername }}/actions-runner/bin/runsvc.sh /home/{{ .RunnerUsername }}/actions-runner/ || fail "failed to copy runsvc.sh" @@ -162,9 +173,9 @@ attempt=1 while true; do ERROUT=$(mktemp) {{- if .GitHubRunnerGroup }} - ./config.sh --unattended --url "{{ .RepoURL }}" --token "$GITHUB_TOKEN" --runnergroup {{.GitHubRunnerGroup}} --name "{{ .RunnerName }}" --labels "{{ .RunnerLabels }}" --ephemeral 2>$ERROUT + ./config.sh --unattended --url "{{ .RepoURL }}" --token "$GITHUB_TOKEN" --runnergroup {{.GitHubRunnerGroup}} --name "{{ .RunnerName }}" --labels "{{ .RunnerLabels }}" --no-default-labels --ephemeral 2>$ERROUT {{- else}} - ./config.sh --unattended --url "{{ .RepoURL }}" --token "$GITHUB_TOKEN" --name "{{ .RunnerName }}" --labels "{{ .RunnerLabels }}" --ephemeral 2>$ERROUT + ./config.sh --unattended --url "{{ .RepoURL }}" --token "$GITHUB_TOKEN" --name "{{ .RunnerName }}" --labels "{{ .RunnerLabels }}" --no-default-labels --ephemeral 2>$ERROUT {{- end}} if [ $? -eq 0 ]; then rm $ERROUT || true @@ -195,13 +206,12 @@ sudo ./svc.sh install {{ .RunnerUsername }} || fail "failed to install service" {{- end}} if [ -e "/sys/fs/selinux" ];then - sudo chcon -h user_u:object_r:bin_t /home/runner/ || fail "failed to change selinux context" - sudo chcon -R -h {{ .RunnerUsername }}:object_r:bin_t /home/runner/* || fail "failed to change selinux context" + sudo chcon -R -h user_u:object_r:bin_t:s0 /home/runner/ || fail "failed to change selinux context" fi +AGENT_ID="" {{- if .UseJITConfig }} sudo systemctl start $SVC_NAME || fail "failed to start service" -success "runner successfully installed" {{- else}} sendStatus "starting service" sudo ./svc.sh start || fail "failed to start service" @@ -212,8 +222,9 @@ if [ $? -ne 0 ];then fail "failed to get agent ID" fi set -e -success "runner successfully installed" $AGENT_ID {{- end}} +systemInfo $AGENT_ID +success "runner successfully installed" $AGENT_ID ` var WindowsSetupScriptTemplate = `#ps1_sysnative @@ -347,7 +358,7 @@ function Update-GarmStatus() { } if ($AgentID -ne 0) { - $body["AgentID"] = $AgentID + $body["agent_id"] = $AgentID } Invoke-APICall -Payload $body -CallbackURL $CallbackURL | Out-Null } diff --git a/vendor/github.com/cloudbase/garm-provider-common/execution/execution.go b/vendor/github.com/cloudbase/garm-provider-common/execution/execution.go index 4d47a1f..948fe3a 100644 --- a/vendor/github.com/cloudbase/garm-provider-common/execution/execution.go +++ b/vendor/github.com/cloudbase/garm-provider-common/execution/execution.go @@ -77,6 +77,10 @@ func GetEnvironment() (Environment, error) { if err := json.Unmarshal(data.Bytes(), &bootstrapParams); err != nil { return Environment{}, fmt.Errorf("failed to decode instance params: %w", err) } + if bootstrapParams.ExtraSpecs == nil { + // Initialize ExtraSpecs as an empty JSON object + bootstrapParams.ExtraSpecs = json.RawMessage([]byte("{}")) + } env.BootstrapParams = bootstrapParams } diff --git a/vendor/modules.txt b/vendor/modules.txt index 3e37edb..8f8b7d5 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -2,7 +2,7 @@ ## explicit; go 1.16 github.com/BurntSushi/toml github.com/BurntSushi/toml/internal -# github.com/cloudbase/garm-provider-common v0.1.1 +# github.com/cloudbase/garm-provider-common v0.1.2 ## explicit; go 1.20 github.com/cloudbase/garm-provider-common/cloudconfig github.com/cloudbase/garm-provider-common/defaults