Skip to content

Commit

Permalink
add system install for gitlab runner
Browse files Browse the repository at this point in the history
Signed-off-by: Nikhil Sharma <nikhilsharma230303@gmail.com>
  • Loading branch information
NikhilSharmaWe authored and alexellis committed May 18, 2023
1 parent 370208e commit b8c2f3b
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
93 changes: 93 additions & 0 deletions cmd/system/gitlab_runner.go
@@ -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
}
1 change: 1 addition & 0 deletions cmd/system/install.go
Expand Up @@ -30,6 +30,7 @@ func MakeInstall() *cobra.Command {
command.AddCommand(MakeInstallNode())
command.AddCommand(MakeInstallTCRedirectTap())
command.AddCommand(MakeInstallRegistry())
command.AddCommand(MakeInstallGitLabRunner())

return command
}

0 comments on commit b8c2f3b

Please sign in to comment.