diff --git a/go.mod b/go.mod index 98cee70f..367821c6 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/BurntSushi/toml v1.2.1 - github.com/cloudbase/garm-provider-common v0.0.0-20230924074517-dd3e26769a05 + github.com/cloudbase/garm-provider-common v0.1.0 github.com/go-openapi/errors v0.20.4 github.com/go-openapi/runtime v0.26.0 github.com/go-openapi/strfmt v0.21.7 diff --git a/go.sum b/go.sum index 0a3bf142..596df8af 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04= github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cloudbase/garm-provider-common v0.0.0-20230924074517-dd3e26769a05 h1:V9TQBCnwTeKX+gpmlEtZAQ5gNbYrdGelAA3jgnGde1c= -github.com/cloudbase/garm-provider-common v0.0.0-20230924074517-dd3e26769a05/go.mod h1:NgR629o2NYWTffZt3uURmu3orjMDQ2vh6KJ5ytwh7Qw= +github.com/cloudbase/garm-provider-common v0.1.0 h1:gc2n8nsLjt7G3InAfqZ+75iZjSIUkIx86d6/DFA2+jc= +github.com/cloudbase/garm-provider-common v0.1.0/go.mod h1:igxJRT3OlykERYc6ssdRQXcb+BCaeSfnucg6I0OSoDc= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/runner/pool/enterprise.go b/runner/pool/enterprise.go index b7adad76..25a562c0 100644 --- a/runner/pool/enterprise.go +++ b/runner/pool/enterprise.go @@ -11,6 +11,7 @@ import ( "sync" runnerErrors "github.com/cloudbase/garm-provider-common/errors" + commonParams "github.com/cloudbase/garm-provider-common/params" dbCommon "github.com/cloudbase/garm/database/common" "github.com/cloudbase/garm/params" "github.com/cloudbase/garm/runner/common" @@ -224,7 +225,7 @@ func (r *enterprise) GetGithubRunners() ([]*github.Runner, error) { return allRunners, nil } -func (r *enterprise) FetchTools() ([]*github.RunnerApplicationDownload, error) { +func (r *enterprise) FetchTools() ([]commonParams.RunnerApplicationDownload, error) { r.mux.Lock() defer r.mux.Unlock() tools, ghResp, err := r.ghcEnterpriseCli.ListRunnerApplicationDownloads(r.ctx, r.cfg.Name) @@ -235,7 +236,15 @@ func (r *enterprise) FetchTools() ([]*github.RunnerApplicationDownload, error) { return nil, errors.Wrap(err, "fetching runner tools") } - return tools, nil + ret := []commonParams.RunnerApplicationDownload{} + for _, tool := range tools { + if tool == nil { + continue + } + ret = append(ret, commonParams.RunnerApplicationDownload(*tool)) + } + + return ret, nil } func (r *enterprise) FetchDbInstances() ([]params.Instance, error) { diff --git a/runner/pool/interfaces.go b/runner/pool/interfaces.go index f981992b..cd22a1f6 100644 --- a/runner/pool/interfaces.go +++ b/runner/pool/interfaces.go @@ -17,6 +17,7 @@ package pool import ( "context" + commonParams "github.com/cloudbase/garm-provider-common/params" "github.com/cloudbase/garm/params" "github.com/cloudbase/garm/runner/common" @@ -29,7 +30,7 @@ type poolHelper interface { GetGithubRegistrationToken() (string, error) GetRunnerInfoFromWorkflow(job params.WorkflowJob) (params.RunnerInfo, error) RemoveGithubRunner(runnerID int64) (*github.Response, error) - FetchTools() ([]*github.RunnerApplicationDownload, error) + FetchTools() ([]commonParams.RunnerApplicationDownload, error) InstallHook(ctx context.Context, req *github.Hook) (params.HookInfo, error) UninstallHook(ctx context.Context, url string) error diff --git a/runner/pool/organization.go b/runner/pool/organization.go index 539af39a..0e73bebe 100644 --- a/runner/pool/organization.go +++ b/runner/pool/organization.go @@ -25,6 +25,7 @@ import ( "sync" runnerErrors "github.com/cloudbase/garm-provider-common/errors" + commonParams "github.com/cloudbase/garm-provider-common/params" dbCommon "github.com/cloudbase/garm/database/common" "github.com/cloudbase/garm/params" "github.com/cloudbase/garm/runner/common" @@ -236,7 +237,7 @@ func (r *organization) GetGithubRunners() ([]*github.Runner, error) { return allRunners, nil } -func (r *organization) FetchTools() ([]*github.RunnerApplicationDownload, error) { +func (r *organization) FetchTools() ([]commonParams.RunnerApplicationDownload, error) { r.mux.Lock() defer r.mux.Unlock() tools, ghResp, err := r.ghcli.ListOrganizationRunnerApplicationDownloads(r.ctx, r.cfg.Name) @@ -247,7 +248,15 @@ func (r *organization) FetchTools() ([]*github.RunnerApplicationDownload, error) return nil, errors.Wrap(err, "fetching runner tools") } - return tools, nil + ret := []commonParams.RunnerApplicationDownload{} + for _, tool := range tools { + if tool == nil { + continue + } + ret = append(ret, commonParams.RunnerApplicationDownload(*tool)) + } + + return ret, nil } func (r *organization) FetchDbInstances() ([]params.Instance, error) { diff --git a/runner/pool/pool.go b/runner/pool/pool.go index 4ca49c4e..7f6b07ca 100644 --- a/runner/pool/pool.go +++ b/runner/pool/pool.go @@ -98,7 +98,7 @@ type basePoolManager struct { store dbCommon.Store providers map[string]common.Provider - tools []*github.RunnerApplicationDownload + tools []commonParams.RunnerApplicationDownload quit chan struct{} helper poolHelper diff --git a/runner/pool/repository.go b/runner/pool/repository.go index c74452de..923ae1fc 100644 --- a/runner/pool/repository.go +++ b/runner/pool/repository.go @@ -25,6 +25,7 @@ import ( "sync" runnerErrors "github.com/cloudbase/garm-provider-common/errors" + commonParams "github.com/cloudbase/garm-provider-common/params" dbCommon "github.com/cloudbase/garm/database/common" "github.com/cloudbase/garm/params" "github.com/cloudbase/garm/runner/common" @@ -200,7 +201,7 @@ func (r *repository) GetGithubRunners() ([]*github.Runner, error) { return allRunners, nil } -func (r *repository) FetchTools() ([]*github.RunnerApplicationDownload, error) { +func (r *repository) FetchTools() ([]commonParams.RunnerApplicationDownload, error) { r.mux.Lock() defer r.mux.Unlock() tools, ghResp, err := r.ghcli.ListRunnerApplicationDownloads(r.ctx, r.cfg.Owner, r.cfg.Name) @@ -211,7 +212,15 @@ func (r *repository) FetchTools() ([]*github.RunnerApplicationDownload, error) { return nil, errors.Wrap(err, "fetching runner tools") } - return tools, nil + ret := []commonParams.RunnerApplicationDownload{} + for _, tool := range tools { + if tool == nil { + continue + } + ret = append(ret, commonParams.RunnerApplicationDownload(*tool)) + } + + return ret, nil } func (r *repository) FetchDbInstances() ([]params.Instance, error) { diff --git a/runner/providers/lxd/lxd.go b/runner/providers/lxd/lxd.go index c5f102e4..0ce490b6 100644 --- a/runner/providers/lxd/lxd.go +++ b/runner/providers/lxd/lxd.go @@ -26,7 +26,6 @@ import ( "github.com/cloudbase/garm/params" "github.com/cloudbase/garm/runner/common" - "github.com/google/go-github/v55/github" lxd "github.com/lxc/lxd/client" "github.com/lxc/lxd/shared/api" "github.com/pkg/errors" @@ -173,35 +172,32 @@ func (l *LXD) getProfiles(flavor string) ([]string, error) { return ret, nil } -func (l *LXD) getTools(tools []*github.RunnerApplicationDownload, osType commonParams.OSType, architecture string) (github.RunnerApplicationDownload, error) { +func (l *LXD) getTools(tools []commonParams.RunnerApplicationDownload, osType commonParams.OSType, architecture string) (commonParams.RunnerApplicationDownload, error) { // Validate image OS. Linux only for now. switch osType { case commonParams.Linux: default: - return github.RunnerApplicationDownload{}, fmt.Errorf("this provider does not support OS type: %s", osType) + return commonParams.RunnerApplicationDownload{}, fmt.Errorf("this provider does not support OS type: %s", osType) } // Find tools for OS/Arch. for _, tool := range tools { - if tool == nil { - continue - } - if tool.OS == nil || tool.Architecture == nil { + if tool.GetOS() == "" || tool.GetArchitecture() == "" { continue } // fmt.Println(*tool.Architecture, *tool.OS) // fmt.Printf("image arch: %s --> osType: %s\n", image.Architecture, string(osType)) - if *tool.Architecture == architecture && *tool.OS == string(osType) { - return *tool, nil + if tool.GetArchitecture() == architecture && tool.GetOS() == string(osType) { + return tool, nil } arch, ok := lxdToGithubArchMap[architecture] - if ok && arch == *tool.Architecture && *tool.OS == string(osType) { - return *tool, nil + if ok && arch == tool.GetArchitecture() && tool.GetOS() == string(osType) { + return tool, nil } } - return github.RunnerApplicationDownload{}, fmt.Errorf("failed to find tools for OS %s and arch %s", osType, architecture) + return commonParams.RunnerApplicationDownload{}, fmt.Errorf("failed to find tools for OS %s and arch %s", osType, architecture) } // sadly, the security.secureboot flag is a string encoded boolean. diff --git a/vendor/github.com/cloudbase/garm-provider-common/LICENSE b/vendor/github.com/cloudbase/garm-provider-common/LICENSE new file mode 100644 index 00000000..56ceea9b --- /dev/null +++ b/vendor/github.com/cloudbase/garm-provider-common/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2023 Cloudbase Solutions SRL + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/cloudbase/garm-provider-common/cloudconfig/util.go b/vendor/github.com/cloudbase/garm-provider-common/cloudconfig/util.go index ede8e353..a709dbef 100644 --- a/vendor/github.com/cloudbase/garm-provider-common/cloudconfig/util.go +++ b/vendor/github.com/cloudbase/garm-provider-common/cloudconfig/util.go @@ -1,3 +1,17 @@ +// Copyright 2023 Cloudbase Solutions SRL +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + package cloudconfig import ( @@ -7,8 +21,7 @@ import ( "strings" "github.com/cloudbase/garm-provider-common/defaults" - commonParams "github.com/cloudbase/garm-provider-common/params" - "github.com/google/go-github/v55/github" + "github.com/cloudbase/garm-provider-common/params" "github.com/pkg/errors" ) @@ -47,7 +60,7 @@ func sortMapKeys(m map[string][]byte) []string { } // GetSpecs returns the cloud config specific extra specs from the bootstrap params. -func GetSpecs(bootstrapParams commonParams.BootstrapInstance) (CloudConfigSpec, error) { +func GetSpecs(bootstrapParams params.BootstrapInstance) (CloudConfigSpec, error) { var extraSpecs CloudConfigSpec if len(bootstrapParams.ExtraSpecs) == 0 { return extraSpecs, nil @@ -71,28 +84,24 @@ func GetSpecs(bootstrapParams commonParams.BootstrapInstance) (CloudConfigSpec, // GetRunnerInstallScript returns the runner install script for the given bootstrap params. // This function will return either the default script for the given OS type or will use the supplied template // if one is provided. -func GetRunnerInstallScript(bootstrapParams commonParams.BootstrapInstance, tools github.RunnerApplicationDownload, runnerName string) ([]byte, error) { - if tools.Filename == nil { +func GetRunnerInstallScript(bootstrapParams params.BootstrapInstance, tools params.RunnerApplicationDownload, runnerName string) ([]byte, error) { + if tools.GetFilename() == "" { return nil, fmt.Errorf("missing tools filename") } - if tools.DownloadURL == nil { + if tools.GetDownloadURL() == "" { return nil, fmt.Errorf("missing tools download URL") } - var tempToken string - if tools.TempDownloadToken != nil { - tempToken = *tools.TempDownloadToken - } - + tempToken := tools.GetTempDownloadToken() extraSpecs, err := GetSpecs(bootstrapParams) if err != nil { return nil, errors.Wrap(err, "getting specs") } installRunnerParams := InstallRunnerParams{ - FileName: *tools.Filename, - DownloadURL: *tools.DownloadURL, + FileName: tools.GetFilename(), + DownloadURL: tools.GetDownloadURL(), TempDownloadToken: tempToken, MetadataURL: bootstrapParams.MetadataURL, RunnerUsername: defaults.DefaultUser, @@ -123,7 +132,7 @@ func GetRunnerInstallScript(bootstrapParams commonParams.BootstrapInstance, tool // GetCloudInitConfig returns the cloud-init specific userdata config. This config can be used on most clouds // for most Linux machines. The install runner script must be generated separately either by GetRunnerInstallScript() // or some other means. -func GetCloudInitConfig(bootstrapParams commonParams.BootstrapInstance, installScript []byte) (string, error) { +func GetCloudInitConfig(bootstrapParams params.BootstrapInstance, installScript []byte) (string, error) { extraSpecs, err := GetSpecs(bootstrapParams) if err != nil { return "", errors.Wrap(err, "getting specs") @@ -174,7 +183,7 @@ func GetCloudInitConfig(bootstrapParams commonParams.BootstrapInstance, installS // Windows initialization scripts are run by creating a separate CustomScriptExtension resource for each individual script. // On other clouds it may be different. This function aims to be generic, which is why it only supports the PreInstallScripts // via cloud-init. -func GetCloudConfig(bootstrapParams commonParams.BootstrapInstance, tools github.RunnerApplicationDownload, runnerName string) (string, error) { +func GetCloudConfig(bootstrapParams params.BootstrapInstance, tools params.RunnerApplicationDownload, runnerName string) (string, error) { installScript, err := GetRunnerInstallScript(bootstrapParams, tools, runnerName) if err != nil { return "", errors.Wrap(err, "generating script") @@ -182,13 +191,13 @@ func GetCloudConfig(bootstrapParams commonParams.BootstrapInstance, tools github var asStr string switch bootstrapParams.OSType { - case commonParams.Linux: + case params.Linux: cloudCfg, err := GetCloudInitConfig(bootstrapParams, installScript) if err != nil { return "", errors.Wrap(err, "getting cloud init config") } return cloudCfg, nil - case commonParams.Windows: + case params.Windows: asStr = string(installScript) default: return "", fmt.Errorf("unknown os type: %s", bootstrapParams.OSType) diff --git a/vendor/github.com/cloudbase/garm-provider-common/defaults/defaults.go b/vendor/github.com/cloudbase/garm-provider-common/defaults/defaults.go index e461d10a..0feda5e3 100644 --- a/vendor/github.com/cloudbase/garm-provider-common/defaults/defaults.go +++ b/vendor/github.com/cloudbase/garm-provider-common/defaults/defaults.go @@ -1,3 +1,17 @@ +// Copyright 2023 Cloudbase Solutions SRL +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + package defaults const ( diff --git a/vendor/github.com/cloudbase/garm-provider-common/execution/commands.go b/vendor/github.com/cloudbase/garm-provider-common/execution/commands.go index 4d718a65..b7976bfb 100644 --- a/vendor/github.com/cloudbase/garm-provider-common/execution/commands.go +++ b/vendor/github.com/cloudbase/garm-provider-common/execution/commands.go @@ -1,3 +1,17 @@ +// Copyright 2023 Cloudbase Solutions SRL +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + package execution type ExecutionCommand string 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 448ea84e..4d47a1f0 100644 --- a/vendor/github.com/cloudbase/garm-provider-common/execution/execution.go +++ b/vendor/github.com/cloudbase/garm-provider-common/execution/execution.go @@ -1,3 +1,17 @@ +// Copyright 2023 Cloudbase Solutions SRL +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + package execution import ( diff --git a/vendor/github.com/cloudbase/garm-provider-common/execution/interface.go b/vendor/github.com/cloudbase/garm-provider-common/execution/interface.go index 20188368..24e39e09 100644 --- a/vendor/github.com/cloudbase/garm-provider-common/execution/interface.go +++ b/vendor/github.com/cloudbase/garm-provider-common/execution/interface.go @@ -1,3 +1,17 @@ +// Copyright 2023 Cloudbase Solutions SRL +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + package execution import ( diff --git a/vendor/github.com/cloudbase/garm-provider-common/params/github.go b/vendor/github.com/cloudbase/garm-provider-common/params/github.go new file mode 100644 index 00000000..9f64de9d --- /dev/null +++ b/vendor/github.com/cloudbase/garm-provider-common/params/github.go @@ -0,0 +1,61 @@ +package params + +// RunnerApplicationDownload represents a binary for the self-hosted runner application that can be downloaded. +// This is copied from the go-github package. It does not make sense to create a dependency on go-github just +// for this struct. +type RunnerApplicationDownload struct { + OS *string `json:"os,omitempty"` + Architecture *string `json:"architecture,omitempty"` + DownloadURL *string `json:"download_url,omitempty"` + Filename *string `json:"filename,omitempty"` + TempDownloadToken *string `json:"temp_download_token,omitempty"` + SHA256Checksum *string `json:"sha256_checksum,omitempty"` +} + +// GetArchitecture returns the Architecture field if it's non-nil, zero value otherwise. +func (r *RunnerApplicationDownload) GetArchitecture() string { + if r == nil || r.Architecture == nil { + return "" + } + return *r.Architecture +} + +// GetDownloadURL returns the DownloadURL field if it's non-nil, zero value otherwise. +func (r *RunnerApplicationDownload) GetDownloadURL() string { + if r == nil || r.DownloadURL == nil { + return "" + } + return *r.DownloadURL +} + +// GetFilename returns the Filename field if it's non-nil, zero value otherwise. +func (r *RunnerApplicationDownload) GetFilename() string { + if r == nil || r.Filename == nil { + return "" + } + return *r.Filename +} + +// GetOS returns the OS field if it's non-nil, zero value otherwise. +func (r *RunnerApplicationDownload) GetOS() string { + if r == nil || r.OS == nil { + return "" + } + return *r.OS +} + +// GetSHA256Checksum returns the SHA256Checksum field if it's non-nil, zero value otherwise. +func (r *RunnerApplicationDownload) GetSHA256Checksum() string { + if r == nil || r.SHA256Checksum == nil { + return "" + } + return *r.SHA256Checksum +} + +// GetTempDownloadToken returns the TempDownloadToken field if it's non-nil, zero value otherwise. +func (r *RunnerApplicationDownload) GetTempDownloadToken() string { + if r == nil || r.TempDownloadToken == nil { + return "" + } + return *r.TempDownloadToken +} diff --git a/vendor/github.com/cloudbase/garm-provider-common/params/params.go b/vendor/github.com/cloudbase/garm-provider-common/params/params.go index 7a5b7adc..3bd2e7d4 100644 --- a/vendor/github.com/cloudbase/garm-provider-common/params/params.go +++ b/vendor/github.com/cloudbase/garm-provider-common/params/params.go @@ -1,9 +1,21 @@ +// Copyright 2023 Cloudbase Solutions SRL +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + package params import ( "encoding/json" - - "github.com/google/go-github/v55/github" ) type ( @@ -49,8 +61,8 @@ type UserDataOptions struct { } type BootstrapInstance struct { - Name string `json:"name"` - Tools []*github.RunnerApplicationDownload `json:"tools"` + Name string `json:"name"` + Tools []RunnerApplicationDownload `json:"tools"` // RepoURL is the URL the github runner agent needs to configure itself. RepoURL string `json:"repo_url"` // CallbackUrl is the URL where the instance can send a post, signaling diff --git a/vendor/github.com/cloudbase/garm-provider-common/util/exec/exec.go b/vendor/github.com/cloudbase/garm-provider-common/util/exec/exec.go index 654b0955..cc417f6d 100644 --- a/vendor/github.com/cloudbase/garm-provider-common/util/exec/exec.go +++ b/vendor/github.com/cloudbase/garm-provider-common/util/exec/exec.go @@ -1,3 +1,17 @@ +// Copyright 2023 Cloudbase Solutions SRL +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + package exec import ( diff --git a/vendor/github.com/cloudbase/garm-provider-common/util/exec/exec_nix.go b/vendor/github.com/cloudbase/garm-provider-common/util/exec/exec_nix.go index 1525eca6..4aaea613 100644 --- a/vendor/github.com/cloudbase/garm-provider-common/util/exec/exec_nix.go +++ b/vendor/github.com/cloudbase/garm-provider-common/util/exec/exec_nix.go @@ -1,6 +1,20 @@ //go:build !windows // +build !windows +// Copyright 2023 Cloudbase Solutions SRL +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + package exec import ( diff --git a/vendor/github.com/cloudbase/garm-provider-common/util/exec/exec_windows.go b/vendor/github.com/cloudbase/garm-provider-common/util/exec/exec_windows.go index 0c17839c..dfcc6225 100644 --- a/vendor/github.com/cloudbase/garm-provider-common/util/exec/exec_windows.go +++ b/vendor/github.com/cloudbase/garm-provider-common/util/exec/exec_windows.go @@ -1,3 +1,17 @@ +// Copyright 2023 Cloudbase Solutions SRL +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + package exec import ( diff --git a/vendor/github.com/cloudbase/garm-provider-common/util/seal.go b/vendor/github.com/cloudbase/garm-provider-common/util/seal.go index efb10860..0033ce47 100644 --- a/vendor/github.com/cloudbase/garm-provider-common/util/seal.go +++ b/vendor/github.com/cloudbase/garm-provider-common/util/seal.go @@ -1,3 +1,17 @@ +// Copyright 2023 Cloudbase Solutions SRL +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + package util import ( diff --git a/vendor/github.com/cloudbase/garm-provider-common/util/util.go b/vendor/github.com/cloudbase/garm-provider-common/util/util.go index 8bc4c351..36ce09ba 100644 --- a/vendor/github.com/cloudbase/garm-provider-common/util/util.go +++ b/vendor/github.com/cloudbase/garm-provider-common/util/util.go @@ -32,10 +32,8 @@ import ( "unicode/utf16" runnerErrors "github.com/cloudbase/garm-provider-common/errors" + "github.com/cloudbase/garm-provider-common/params" - commonParams "github.com/cloudbase/garm-provider-common/params" - - "github.com/google/go-github/v55/github" "github.com/google/uuid" gorillaHandlers "github.com/gorilla/handlers" "github.com/pkg/errors" @@ -50,24 +48,24 @@ const alphanumeric = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv var rxEmail = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$") var ( - OSToOSTypeMap map[string]commonParams.OSType = map[string]commonParams.OSType{ - "almalinux": commonParams.Linux, - "alma": commonParams.Linux, - "alpine": commonParams.Linux, - "archlinux": commonParams.Linux, - "arch": commonParams.Linux, - "centos": commonParams.Linux, - "ubuntu": commonParams.Linux, - "rhel": commonParams.Linux, - "suse": commonParams.Linux, - "opensuse": commonParams.Linux, - "fedora": commonParams.Linux, - "debian": commonParams.Linux, - "flatcar": commonParams.Linux, - "gentoo": commonParams.Linux, - "rockylinux": commonParams.Linux, - "rocky": commonParams.Linux, - "windows": commonParams.Windows, + OSToOSTypeMap map[string]params.OSType = map[string]params.OSType{ + "almalinux": params.Linux, + "alma": params.Linux, + "alpine": params.Linux, + "archlinux": params.Linux, + "arch": params.Linux, + "centos": params.Linux, + "ubuntu": params.Linux, + "rhel": params.Linux, + "suse": params.Linux, + "opensuse": params.Linux, + "fedora": params.Linux, + "debian": params.Linux, + "flatcar": params.Linux, + "gentoo": params.Linux, + "rockylinux": params.Linux, + "rocky": params.Linux, + "windows": params.Windows, } githubArchMapping map[string]string = map[string]string{ @@ -86,9 +84,9 @@ var ( } // - githubOSTag = map[commonParams.OSType]string{ - commonParams.Linux: "Linux", - commonParams.Windows: "Windows", + githubOSTag = map[params.OSType]string{ + params.Linux: "Linux", + params.Windows: "Windows", } ) @@ -119,7 +117,7 @@ func ResolveToGithubOSType(osType string) (string, error) { // ResolveToGithubTag returns the default OS tag that self hosted runners automatically // (and forcefully) adds to every runner that gets deployed. We need to keep track of those // tags internally as well. -func ResolveToGithubTag(os commonParams.OSType) (string, error) { +func ResolveToGithubTag(os params.OSType) (string, error) { ghOS, ok := githubOSTag[os] if !ok { return "", runnerErrors.NewNotFoundError("os %s is unknown", os) @@ -178,37 +176,34 @@ func ConvertFileToBase64(file string) (string, error) { return base64.StdEncoding.EncodeToString(bytes), nil } -func OSToOSType(os string) (commonParams.OSType, error) { +func OSToOSType(os string) (params.OSType, error) { osType, ok := OSToOSTypeMap[strings.ToLower(os)] if !ok { - return commonParams.Unknown, fmt.Errorf("no OS to OS type mapping for %s", os) + return params.Unknown, fmt.Errorf("no OS to OS type mapping for %s", os) } return osType, nil } -func GetTools(osType commonParams.OSType, osArch commonParams.OSArch, tools []*github.RunnerApplicationDownload) (github.RunnerApplicationDownload, error) { +func GetTools(osType params.OSType, osArch params.OSArch, tools []params.RunnerApplicationDownload) (params.RunnerApplicationDownload, error) { // Validate image OS. Linux only for now. switch osType { - case commonParams.Linux: - case commonParams.Windows: + case params.Linux: + case params.Windows: default: - return github.RunnerApplicationDownload{}, fmt.Errorf("unsupported OS type: %s", osType) + return params.RunnerApplicationDownload{}, fmt.Errorf("unsupported OS type: %s", osType) } switch osArch { - case commonParams.Amd64: - case commonParams.Arm: - case commonParams.Arm64: + case params.Amd64: + case params.Arm: + case params.Arm64: default: - return github.RunnerApplicationDownload{}, fmt.Errorf("unsupported OS arch: %s", osArch) + return params.RunnerApplicationDownload{}, fmt.Errorf("unsupported OS arch: %s", osArch) } // Find tools for OS/Arch. for _, tool := range tools { - if tool == nil { - continue - } - if tool.OS == nil || tool.Architecture == nil { + if tool.GetOS() == "" || tool.GetArchitecture() == "" { continue } @@ -221,11 +216,11 @@ func GetTools(osType commonParams.OSType, osArch commonParams.OSArch, tools []*g if err != nil { continue } - if *tool.Architecture == ghArch && *tool.OS == ghOS { - return *tool, nil + if tool.GetArchitecture() == ghArch && tool.GetOS() == ghOS { + return tool, nil } } - return github.RunnerApplicationDownload{}, fmt.Errorf("failed to find tools for OS %s and arch %s", osType, osArch) + return params.RunnerApplicationDownload{}, fmt.Errorf("failed to find tools for OS %s and arch %s", osType, osArch) } // GetRandomString returns a secure random string diff --git a/vendor/modules.txt b/vendor/modules.txt index 2106e6b5..098e3341 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -14,7 +14,7 @@ github.com/cespare/xxhash/v2 # github.com/chzyer/readline v1.5.1 ## explicit; go 1.15 github.com/chzyer/readline -# github.com/cloudbase/garm-provider-common v0.0.0-20230924074517-dd3e26769a05 +# github.com/cloudbase/garm-provider-common v0.1.0 ## explicit; go 1.20 github.com/cloudbase/garm-provider-common/cloudconfig github.com/cloudbase/garm-provider-common/defaults