Skip to content

Commit

Permalink
Update remove logic
Browse files Browse the repository at this point in the history
  • Loading branch information
simongottschlag committed Nov 28, 2020
1 parent fdf9227 commit 567d3a4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[Unit]
Description=github-runner-script
Description=github-runner-start
After=network.target

[Service]
Type=oneshot
WorkingDirectory=/etc/github-runner
ExecStart=/etc/github-runner/github-runner.sh --action=REGISTER
ExecStop=/etc/github-runner/github-runner.sh --action=REMOVE

[Install]
WantedBy=multi-user.target
12 changes: 12 additions & 0 deletions templates/azure/github-runner/files/github-runner-stop.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=github-runner-stop
After=network.target

[Service]
Type=oneshot
WorkingDirectory=/etc/github-runner
RemainAfterExit=true
ExecStop=/etc/github-runner/github-runner.sh --action=REMOVE

[Install]
WantedBy=multi-user.target
2 changes: 2 additions & 0 deletions templates/azure/github-runner/files/github-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ if [[ "${ACTION}" == "REGISTER" ]]; then
elif [[ "${ACTION}" == "REMOVE" ]]; then
GITHUB_RUNNER_OUTPUT=$(${GITHUB_RUNNER_BINARY} --value-source AZURE_KEYVAULT --azure-keyvault-name ${AZURE_KEYVAULT_NAME} --organization-kvsecret ${GITHUB_ORGANIZATION_KVSECRET} --app-id-kvsecret ${GITHUB_APP_ID_KVSECRET} --installation-id-kvsecret ${GITHUB_INSTALLATION_ID_KVSECRET} --private-key-kvsecret ${GITHUB_PRIVATE_KEY_KVSECRET} --azure-auth ${AZURE_AUTHENTICATION_METHOD} --output JSON --token-type REMOVE)
GITHUB_RUNNER_REMOVE_TOKEN=$(echo ${GITHUB_RUNNER_OUTPUT} | jq -r .token)
set +e
${GITHUB_RUNNER_SERVICE_SCRIPT} uninstall
set -e
runuser -l ghrunner -c "${GITHUB_RUNNER_CONFIG_SCRIPT} remove --unattended --token ${GITHUB_RUNNER_REMOVE_TOKEN}"
fi
23 changes: 18 additions & 5 deletions templates/azure/github-runner/files/github-runner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,30 @@
group: root
mode: "0744"

- name: Copy github-runner.service
- name: Copy github-runner-start.service
copy:
src: github-runner.service
dest: /etc/systemd/system/github-runner.service
src: github-runner-start.service
dest: /etc/systemd/system/github-runner-start.service
owner: root
group: root
mode: "0644"

- name: Enable github-runner.service
- name: Enable github-runner-start.service
systemd:
name: github-runner.service
name: github-runner-start.service
enabled: yes

- name: Copy github-runner-stop.service
copy:
src: github-runner-stop.service
dest: /etc/systemd/system/github-runner-stop.service
owner: root
group: root
mode: "0644"

- name: Enable github-runner-stop.service
systemd:
name: github-runner-stop.service
enabled: yes

- name: Download github-runner
Expand Down
2 changes: 1 addition & 1 deletion templates/azure/github-runner/github-runner.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "azure-arm",
"use_azure_cli_auth": true,
"managed_image_resource_group_name": "{{user `AZURE_RESOURCE_GROUP_NAME`}}",
"managed_image_name": "azp-agent-{{isotime | clean_resource_name}}",
"managed_image_name": "github-runner-{{isotime | clean_resource_name}}",
"build_resource_group_name": "{{user `AZURE_RESOURCE_GROUP_NAME`}}",
"os_type": "Linux",
"image_publisher": "Canonical",
Expand Down

0 comments on commit 567d3a4

Please sign in to comment.