Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add system install for gitlab runner
Signed-off-by: Nikhil Sharma <nikhilsharma230303@gmail.com>
- Loading branch information
1 parent
370208e
commit b8c2f3b
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (c) arkade author(s) 2022. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
package system | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
|
||
"github.com/alexellis/arkade/pkg/env" | ||
"github.com/alexellis/arkade/pkg/get" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func MakeInstallGitLabRunner() *cobra.Command { | ||
command := &cobra.Command{ | ||
Use: "gitlab-runner", | ||
Short: "Install GitLab Runner", | ||
Long: `Install GitLab Runner for self-hosted CI.`, | ||
Example: ` arkade system install gitlab-runner | ||
arkade system install gitlab-runner --version <version>`, | ||
SilenceUsage: true, | ||
} | ||
|
||
command.Flags().StringP("version", "v", "", "The version or leave blank to determine the latest available version") | ||
command.Flags().String("path", "$HOME/gitlab-runner", "Installation path, where gitlab-runner binary file is downloaded") | ||
command.Flags().Bool("progress", true, "Show download progress") | ||
command.Flags().String("arch", "", "CPU architecture i.e. amd64") | ||
|
||
command.PreRunE = func(cmd *cobra.Command, args []string) error { | ||
return nil | ||
} | ||
|
||
command.RunE = func(cmd *cobra.Command, args []string) error { | ||
installPath, _ := cmd.Flags().GetString("path") | ||
version, _ := cmd.Flags().GetString("version") | ||
fmt.Printf("Installing GitLab Runner to %s\n", installPath) | ||
|
||
installPath = strings.ReplaceAll(installPath, "$HOME", os.Getenv("HOME")) | ||
|
||
arch, osVer := env.GetClientArch() | ||
|
||
if strings.ToLower(osVer) != "linux" { | ||
return fmt.Errorf("this app only supports Linux") | ||
} | ||
|
||
if cmd.Flags().Changed("arch") { | ||
arch, _ = cmd.Flags().GetString("arch") | ||
} | ||
|
||
dlArch := arch | ||
if arch == "x86_64" { | ||
dlArch = "amd64" | ||
} else if arch == "aarch64" { | ||
dlArch = "arm64" | ||
} else if arch == "armv7" || arch == "armv7l" { | ||
dlArch = "arm" | ||
} | ||
|
||
if version == "" { | ||
version = "latest" | ||
} else if !strings.HasPrefix(version, "v") { | ||
version = "v" + version | ||
} | ||
|
||
fmt.Printf("Installing version: %s for: %s\n", version, dlArch) | ||
|
||
dlURL := fmt.Sprintf("https://gitlab-runner-downloads.s3.amazonaws.com/%s/binaries/gitlab-runner-linux-%s", version, dlArch) | ||
|
||
fmt.Printf("Downloading from: %s\n", dlURL) | ||
|
||
progress, _ := cmd.Flags().GetBool("progress") | ||
outPath, err := get.DownloadFileP(dlURL, progress) | ||
if err != nil { | ||
return err | ||
} | ||
defer os.Remove(outPath) | ||
|
||
fmt.Printf("Downloaded to: %s\n", outPath) | ||
|
||
if _, err := get.CopyFile(outPath, installPath); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
fmt.Printf("Binary file copied to: %s\n", installPath) | ||
|
||
return nil | ||
} | ||
|
||
return command | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters