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

Add azure external provider #2

Merged
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
4 changes: 2 additions & 2 deletions config/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ type External struct {
func (e *External) ExecutablePath() (string, error) {
execPath := filepath.Join(e.ProviderDir, "garm-external-provider")
if !filepath.IsAbs(execPath) {
return "", fmt.Errorf("executable path must be an absolut epath")
return "", fmt.Errorf("executable path must be an absolute path")
}
return filepath.Join(e.ProviderDir, "garm-external-provider"), nil
}

func (e *External) Validate() error {
if e.ConfigFile != "" {
if _, err := os.Stat(e.ConfigFile); err != nil {
return fmt.Errorf("failed to access cofig file %s", e.ConfigFile)
return fmt.Errorf("failed to access config file %s", e.ConfigFile)
}
if !filepath.IsAbs(e.ConfigFile) {
return fmt.Errorf("path to config file must be an absolute path")
Expand Down
61 changes: 61 additions & 0 deletions contrib/providers.d/azure/cloudconfig/install_runner.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

set -ex
set -o pipefail

CALLBACK_URL="GARM_CALLBACK_URL"
BEARER_TOKEN="GARM_CALLBACK_TOKEN"
DOWNLOAD_URL="GH_DOWNLOAD_URL"
FILENAME="GH_FILENAME"
TARGET_URL="GH_TARGET_URL"
RUNNER_TOKEN="GH_RUNNER_TOKEN"
RUNNER_NAME="GH_RUNNER_NAME"
RUNNER_LABELS="GH_RUNNER_LABELS"

function call() {
PAYLOAD="$1"
curl -s -X POST -d "${PAYLOAD}" -H 'Accept: application/json' -H "Authorization: Bearer ${BEARER_TOKEN}" "${CALLBACK_URL}" || echo "failed to call home: exit code ($?)"
}

function sendStatus() {
MSG="$1"
call "{\"status\": \"installing\", \"message\": \"$MSG\"}"
}

function success() {
MSG="$1"
call "{\"status\": \"idle\", \"message\": \"$MSG\"}"
}

function fail() {
MSG="$1"
call "{\"status\": \"failed\", \"message\": \"$MSG\"}"
exit 1
}



sendStatus "downloading tools from ${DOWNLOAD_URL}"
curl -L -o "/home/runner/${FILENAME}" "${DOWNLOAD_URL}" || fail "failed to download tools"

mkdir -p /home/runner/actions-runner || fail "failed to create actions-runner folder"

sendStatus "extracting runner"
tar xf "/home/runner/${FILENAME}" -C /home/runner/actions-runner/ || fail "failed to extract runner"
chown runner:runner -R /home/runner/actions-runner/ || fail "failed to change owner"

sendStatus "installing dependencies"
cd /home/runner/actions-runner
sudo ./bin/installdependencies.sh || fail "failed to install dependencies"

sendStatus "configuring runner"
sudo -u runner -- ./config.sh --unattended --url "${TARGET_URL}" --token "${RUNNER_TOKEN}" --name "${RUNNER_NAME}" --labels "${RUNNER_LABELS}" --ephemeral || fail "failed to configure runner"

sendStatus "installing runner service"
./svc.sh install runner || fail "failed to install service"

sendStatus "starting service"
./svc.sh start || fail "failed to start service"

success "runner successfully installed"

29 changes: 29 additions & 0 deletions contrib/providers.d/azure/cloudconfig/userdata.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#cloud-config
package_upgrade: true
packages:
- curl
- tar
system_info:
default_user:
name: runner
home: /home/runner
shell: /bin/bash
groups:
- sudo
- adm
- cdrom
- dialout
- dip
- video
- plugdev
- netdev
sudo: ALL=(ALL) NOPASSWD:ALL
runcmd:
- /install_runner.sh
- rm -f /install_runner.sh
write_files:
- encoding: b64
content: RUNNER_INSTALL_B64
owner: root:root
path: /install_runner.sh
permissions: "755"
8 changes: 8 additions & 0 deletions contrib/providers.d/azure/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Azure service principal credentials
export AZURE_SUBSCRIPTION_ID="<SUBSCRIPTION_ID>"
export AZURE_TENANT_ID="<TENANT_ID>"
export AZURE_CLIENT_ID="<CLIENT_ID>"
export AZURE_CLIENT_SECRET="<CLIENT_SECRET>"

# GARM config
export LOCATION="westeurope"
Loading