Skip to content

Commit 8d55ee9

Browse files
Merge pull request #51 from yc-actions/feature/ssh
add params to enable ssh login to the runner
2 parents 312f1ac + 7dcaed6 commit 8d55ee9

File tree

11 files changed

+9520
-44
lines changed

11 files changed

+9520
-44
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`cloud-init default 1`] = `
4+
[
5+
"#!/bin/bash",
6+
"mkdir actions-runner && cd actions-runner",
7+
"case $(uname -m) in aarch64) ARCH="arm64" ;; amd64|x86_64) ARCH="x64" ;; esac && export RUNNER_ARCH=\${ARCH}",
8+
"curl -O -L https://github.com/actions/runner/releases/download/v2.299.1/actions-runner-linux-\${RUNNER_ARCH}-2.299.1.tar.gz",
9+
"tar xzf ./actions-runner-linux-\${RUNNER_ARCH}-2.299.1.tar.gz",
10+
"export RUNNER_ALLOW_RUNASROOT=1",
11+
"./config.sh --url https://github.com/owner/repo --token githubRegistrationToken --labels label",
12+
"./run.sh",
13+
]
14+
`;
15+
16+
exports[`cloud-init with home dir 1`] = `
17+
[
18+
"#!/bin/bash",
19+
"cd "foo"",
20+
"export RUNNER_ALLOW_RUNASROOT=1",
21+
"./config.sh --url https://github.com/owner/repo --token githubRegistrationToken --labels label",
22+
"./run.sh",
23+
]
24+
`;
25+
26+
exports[`cloud-init with home dir and user and ssh key 1`] = `
27+
[
28+
"#cloud-config",
29+
"ssh_pwauth: 'no'",
30+
"users:",
31+
" - name: user",
32+
" sudo: ALL=(ALL) NOPASSWD:ALL",
33+
" shell: /bin/bash",
34+
" ssh_authorized_keys:",
35+
" - key",
36+
"runcmd:",
37+
" - cd "foo"",
38+
" - export RUNNER_ALLOW_RUNASROOT=1",
39+
" - >-",
40+
" ./config.sh --url https://github.com/owner/repo --token",
41+
" githubRegistrationToken --labels label",
42+
" - ./run.sh",
43+
"",
44+
]
45+
`;
46+
47+
exports[`cloud-init with user and ssh key 1`] = `
48+
[
49+
"#cloud-config",
50+
"ssh_pwauth: 'no'",
51+
"users:",
52+
" - name: user",
53+
" sudo: ALL=(ALL) NOPASSWD:ALL",
54+
" shell: /bin/bash",
55+
" ssh_authorized_keys:",
56+
" - key",
57+
"runcmd:",
58+
" - mkdir actions-runner && cd actions-runner",
59+
" - >-",
60+
" case $(uname -m) in aarch64) ARCH="arm64" ;; amd64|x86_64) ARCH="x64" ;;",
61+
" esac && export RUNNER_ARCH=\${ARCH}",
62+
" - >-",
63+
" curl -O -L",
64+
" https://github.com/actions/runner/releases/download/v2.299.1/actions-runner-linux-\${RUNNER_ARCH}-2.299.1.tar.gz",
65+
" - tar xzf ./actions-runner-linux-\${RUNNER_ARCH}-2.299.1.tar.gz",
66+
" - export RUNNER_ALLOW_RUNASROOT=1",
67+
" - >-",
68+
" ./config.sh --url https://github.com/owner/repo --token",
69+
" githubRegistrationToken --labels label",
70+
" - ./run.sh",
71+
"",
72+
]
73+
`;

__tests__/config.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ test('basic Config ', () => {
2121
secondDiskImageId: '',
2222
secondDiskType: '',
2323
secondDiskSize: 0,
24+
user: '',
25+
sshPublicKey: '',
2426
resourcesSpec: {
2527
cores: 1,
2628
memory: 10 * 1024 ** 3,
@@ -49,6 +51,8 @@ test('add secondary disk', () => {
4951
secondDiskImageId: 'secondDiskImageId',
5052
secondDiskType: 'secondDiskType',
5153
secondDiskSize: parseMemory('30Gb'),
54+
user: '',
55+
sshPublicKey: '',
5256
resourcesSpec: {
5357
cores: 1,
5458
memory: parseMemory('8Gb'),
@@ -77,6 +81,8 @@ test('add secondary disk without image-id throw error', () => {
7781
secondDiskImageId: '',
7882
secondDiskType: 'secondDiskType',
7983
secondDiskSize: parseMemory('30Gb'),
84+
user: 'user',
85+
sshPublicKey: 'sshPublicKey',
8086
resourcesSpec: {
8187
cores: 1,
8288
memory: parseMemory('8Gb'),

__tests__/main.test.ts

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import {describe, test, expect} from '@jest/globals';
12
import * as cp from 'child_process';
23
import * as path from 'path';
34
import * as process from 'process';
4-
import {test} from '@jest/globals';
5+
import {buildUserDataScript} from '../src/main';
56

67
// This test will run only in fully configured env and creates real VM
78
// in the Yandex Cloud, so it will be disabled in CI/CD. You can enable it to test locally.
@@ -22,3 +23,65 @@ test.skip('test runs', () => {
2223
}
2324
console.log(res?.toString());
2425
});
26+
27+
describe('cloud-init', () => {
28+
test('default', () => {
29+
const actual = buildUserDataScript({
30+
githubRegistrationToken: 'githubRegistrationToken',
31+
label: 'label',
32+
owner: 'owner',
33+
repo: 'repo',
34+
runnerHomeDir: '',
35+
user: '',
36+
sshPublicKey: '',
37+
});
38+
expect(actual.length).toBe(8);
39+
expect(actual).toMatchSnapshot();
40+
expect(actual[0]).toBe('#!/bin/bash');
41+
});
42+
43+
test('with home dir', () => {
44+
const actual = buildUserDataScript({
45+
githubRegistrationToken: 'githubRegistrationToken',
46+
label: 'label',
47+
owner: 'owner',
48+
repo: 'repo',
49+
runnerHomeDir: 'foo',
50+
user: '',
51+
sshPublicKey: '',
52+
});
53+
expect(actual.length).toBe(5);
54+
expect(actual).toMatchSnapshot();
55+
expect(actual[0]).toBe('#!/bin/bash');
56+
});
57+
58+
test('with user and ssh key', () => {
59+
const actual = buildUserDataScript({
60+
githubRegistrationToken: 'githubRegistrationToken',
61+
label: 'label',
62+
owner: 'owner',
63+
repo: 'repo',
64+
runnerHomeDir: '',
65+
user: 'user',
66+
sshPublicKey: 'key',
67+
});
68+
expect(actual.length).toBe(23);
69+
expect(actual).toMatchSnapshot();
70+
expect(actual[0]).toBe('#cloud-config');
71+
});
72+
73+
test('with home dir and user and ssh key', () => {
74+
const actual = buildUserDataScript({
75+
githubRegistrationToken: 'githubRegistrationToken',
76+
label: 'label',
77+
owner: 'owner',
78+
repo: 'repo',
79+
runnerHomeDir: 'foo',
80+
user: 'user',
81+
sshPublicKey: 'key',
82+
});
83+
expect(actual.length).toBe(16);
84+
expect(actual).toMatchSnapshot();
85+
expect(actual[0]).toBe('#cloud-config');
86+
});
87+
});

action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ inputs:
8383
required: false
8484
description: 'Compute platform Id'
8585
default: 'standard-v3'
86+
87+
user:
88+
required: false
89+
description: 'User name to login with via ssh'
90+
ssh-public-key:
91+
required: false
92+
description: 'Public SSH key to login with'
8693
outputs:
8794
label:
8895
description: >-

0 commit comments

Comments
 (0)