Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TART_EXECUTOR_INSTALL_GITLAB_RUNNER: deprecate "true" #55

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,17 @@ that required paid sponsorship upon exceeding a free limit.

## Supported environment variables

| Name | Default | Description |
|---------------------------------------|----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `TART_EXECUTOR_SSH_USERNAME` | admin | SSH username to use when connecting to the VM |
| `TART_EXECUTOR_SSH_PASSWORD` | admin | SSH password to use when connecting to the VM |
| `TART_EXECUTOR_HEADLESS` | true | Run the VM in headless mode (`true`) or with GUI (`false`) |
| `TART_EXECUTOR_ALWAYS_PULL` | true | Always pull the latest version of the Tart image (`true`) or only when the image doesn't exist locally (`false`) |
| `TART_EXECUTOR_SOFTNET` | false | Whether to enable [Softnet](https://github.com/cirruslabs/softnet) software networking (`true`) or disable it (`false`) |
| `TART_EXECUTOR_HOST_DIR`<sup>1</sup> | false | Whether to mount a temporary directory from the host for performance reasons (`true`) or use a directory inside of a guest (`false`) |
| `TART_EXECUTOR_SHELL` | system default | Alternative [Unix shell](https://en.wikipedia.org/wiki/Unix_shell) to use (e.g. `bash -l`) |
| `TART_EXECUTOR_INSTALL_GITLAB_RUNNER` | false | Automatically install GitLab Runner [via Homebrew](https://docs.gitlab.com/runner/install/osx.html#homebrew-installation-alternative) or [manually using cURL](https://docs.gitlab.com/runner/install/osx.html#manual-installation-official), if Homebrew is not available |
| `TART_EXECUTOR_TIMEZONE` | | Timezone to set in the guest (or `auto` to pick up the timezone from host), see `systemsetup listtimezones` for a list of possible timezones |
| Name | Default | Description |
|---------------------------------------|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `TART_EXECUTOR_SSH_USERNAME` | admin | SSH username to use when connecting to the VM |
| `TART_EXECUTOR_SSH_PASSWORD` | admin | SSH password to use when connecting to the VM |
| `TART_EXECUTOR_HEADLESS` | true | Run the VM in headless mode (`true`) or with GUI (`false`) |
| `TART_EXECUTOR_ALWAYS_PULL` | true | Always pull the latest version of the Tart image (`true`) or only when the image doesn't exist locally (`false`) |
| `TART_EXECUTOR_SOFTNET` | false | Whether to enable [Softnet](https://github.com/cirruslabs/softnet) software networking (`true`) or disable it (`false`) |
| `TART_EXECUTOR_HOST_DIR`<sup>1</sup> | false | Whether to mount a temporary directory from the host for performance reasons (`true`) or use a directory inside of a guest (`false`) |
| `TART_EXECUTOR_SHELL` | system default | Alternative [Unix shell](https://en.wikipedia.org/wiki/Unix_shell) to use (e.g. `bash -l`) |
| `TART_EXECUTOR_INSTALL_GITLAB_RUNNER` | | Set to `brew` to automatically install GitLab Runner [via Homebrew](https://docs.gitlab.com/runner/install/osx.html#homebrew-installation-alternative) or to `curl` to install it [automatically using cURL](https://docs.gitlab.com/runner/install/osx.html#manual-installation-official) |
| `TART_EXECUTOR_TIMEZONE` | | Timezone to set in the guest (or `auto` to pick up the timezone from host), see `systemsetup listtimezones` for a list of possible timezones |

<sup>1</sup>: to use the directory mounting feature, both the host and the guest need to run macOS 13.0 (Ventura) or newer.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/bin/bash

# Set shell options to enable fail-fast behavior
#
# * -e: fail the script when an error occurs or command fails
# * -u: fail the script when attempting to reference unset parameters
# * -o pipefail: by default an exit status of a pipeline is that of its
# last command, this fails the pipe early if an error in
# any of its commands occurs
#
set -euo pipefail

GITLAB_RUNNER_URL="https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-arm64"
GITLAB_RUNNER_PATH="/usr/local/bin/gitlab-runner"

Expand Down
25 changes: 25 additions & 0 deletions internal/commands/prepare/install-gitlab-runner-brew.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Set shell options to enable fail-fast behavior
#
# * -e: fail the script when an error occurs or command fails
# * -u: fail the script when attempting to reference unset parameters
# * -o pipefail: by default an exit status of a pipeline is that of its
# last command, this fails the pipe early if an error in
# any of its commands occurs
#
set -euo pipefail

# Is GitLab Runner already installed?
if type gitlab-runner &> /dev/null
then
echo "GitLab Runner is already installed, skipping installation"

exit 0
fi

echo "Installing GitLab Runner via Homebrew..."

brew install gitlab-runner

echo "GitLab Runner was successfully installed!"
47 changes: 47 additions & 0 deletions internal/commands/prepare/install-gitlab-runner-curl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

# Set shell options to enable fail-fast behavior
#
# * -e: fail the script when an error occurs or command fails
# * -u: fail the script when attempting to reference unset parameters
# * -o pipefail: by default an exit status of a pipeline is that of its
# last command, this fails the pipe early if an error in
# any of its commands occurs
#
set -euo pipefail

GITLAB_RUNNER_URL="https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-arm64"
GITLAB_RUNNER_PATH="/usr/local/bin/gitlab-runner"

# Is GitLab Runner already installed?
if type gitlab-runner &> /dev/null
then
echo "GitLab Runner is already installed, skipping installation"

exit 0
fi

echo "Installing GitLab Runner using cURL..."

if ! sudo -n true &>/dev/null
then
echo "Failed to install GitLab Runner using cURL: passwordless sudo is required, but is not configured"

exit 1
fi

# /usr/local is empty on fresh macOS installations
# (for example, try ghcr.io/cirruslabs/macos-ventura-vanilla:latest)
if test ! -e /usr/local/bin
then
echo "Creating /usr/local/bin because it doesn't exist yet..."
sudo mkdir -p /usr/local/bin
fi

echo "Downloading GitLab Runner from $GITLAB_RUNNER_URL to $GITLAB_RUNNER_PATH..."
sudo curl --output "$GITLAB_RUNNER_PATH" "$GITLAB_RUNNER_URL"

echo "Making $GITLAB_RUNNER_PATH executable..."
sudo chmod +x "$GITLAB_RUNNER_PATH"

echo "GitLab Runner was successfully installed!"
33 changes: 30 additions & 3 deletions internal/commands/prepare/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
_ "embed"
"errors"
"fmt"
"github.com/alecthomas/units"
"github.com/cirruslabs/gitlab-tart-executor/internal/gitlab"
Expand All @@ -17,8 +18,16 @@ import (
"strconv"
)

//go:embed install-gitlab-runner.sh
var installGitlabRunnerScript string
var ErrFailed = errors.New("\"prepare\" stage failed")

//go:embed install-gitlab-runner-auto.sh
var installGitlabRunnerScriptAuto string

//go:embed install-gitlab-runner-brew.sh
var installGitlabRunnerBrewScript string

//go:embed install-gitlab-runner-curl.sh
var installGitlabRunnerCurlScript string

var concurrency uint64
var cpuOverrideRaw string
Expand Down Expand Up @@ -107,7 +116,25 @@ func runPrepareVM(cmd *cobra.Command, args []string) error {

log.Println("Was able to SSH!")

if config.InstallGitlabRunner {
var installGitlabRunnerScript string

switch config.InstallGitlabRunner {
case "brew":
installGitlabRunnerScript = installGitlabRunnerBrewScript
case "curl":
installGitlabRunnerScript = installGitlabRunnerCurlScript
case "true", "yes", "on":
log.Printf("%q value for TART_EXECUTOR_INSTALL_GITLAB_RUNNER will deprecated "+
"in next version, please use either \"brew\" or \"curl\"", config.InstallGitlabRunner)
installGitlabRunnerScript = installGitlabRunnerScriptAuto
case "":
// do not set installGitlabRunnerScript to avoid installing GitLab Runner
default:
return fmt.Errorf("%w: TART_EXECUTOR_INSTALL_GITLAB_RUNNER only accepts "+
"\"brew\" or \"curl\" arguments, got %q", ErrFailed, config.InstallGitlabRunner)
}

if installGitlabRunnerScript != "" {
log.Println("Installing GitLab Runner...")

session, err := ssh.NewSession()
Expand Down
2 changes: 1 addition & 1 deletion internal/tart/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Config struct {
AlwaysPull bool `env:"ALWAYS_PULL" envDefault:"true"`
HostDir bool `env:"HOST_DIR"`
Shell string `env:"SHELL"`
InstallGitlabRunner bool `env:"INSTALL_GITLAB_RUNNER"`
InstallGitlabRunner string `env:"INSTALL_GITLAB_RUNNER"`
Timezone string `env:"TIMEZONE"`
}

Expand Down