Skip to content

Commit

Permalink
Attempt to work around wonky sg with sudo
Browse files Browse the repository at this point in the history
  • Loading branch information
addyess committed Sep 24, 2024
1 parent a8737fe commit e41e1ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 7 additions & 6 deletions dist/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5492,10 +5492,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
const os = __importStar(__nccwpck_require__(2087));
const utils_1 = __nccwpck_require__(2828);
const semver_1 = __importDefault(__nccwpck_require__(1383));
const ts_dedent_1 = __importDefault(__nccwpck_require__(3604));
const ignoreFail = { "ignoreReturnCode": true };
const user = os.userInfo().username;
const os_release = () => __awaiter(void 0, void 0, void 0, function* () {
// Read os-release file into an object
let stdout_buf = '';
Expand Down Expand Up @@ -5537,8 +5539,7 @@ function get_microk8s_group() {
}
function exec_as_microk8s(cmd, options = {}) {
return __awaiter(this, void 0, void 0, function* () {
const microk8s_group = get_microk8s_group();
return yield exec.exec('sg', [microk8s_group, '-c', cmd], options);
return yield exec.exec(`sudo -u ${user} -E ${cmd}`, [], options);
});
}
function retry_until_rc(cmd, expected_rc = 0, maxRetries = 12, timeout = 10000) {
Expand Down Expand Up @@ -5598,7 +5599,7 @@ function microk8s_init(channel, addons, container_registry_url) {
// Add the given addons if any were given.
yield exec_as_microk8s("microk8s status --wait-ready --timeout=600");
if (addons) {
yield exec_as_microk8s("sudo microk8s enable " + addons);
yield exec.exec(`sudo microk8s enable ${addons}`);
}
let stdout_buf = '';
const options = {
Expand Down Expand Up @@ -5738,7 +5739,7 @@ function run() {
yield exec.exec("sudo lxd init --auto");
yield exec.exec("sudo chmod a+wr /var/snap/lxd/common/lxd/unix.socket");
yield exec.exec("lxc network set lxdbr0 ipv6.address none");
yield exec.exec('bash', ['-c', 'sudo usermod -a -G lxd $USER']);
yield exec.exec(`sudo usermod -a -G lxd ${user}`);
core.endGroup();
core.startGroup("Install tox");
yield install_tox(tox_version);
Expand Down Expand Up @@ -5784,7 +5785,7 @@ function run() {
}
core.endGroup();
core.startGroup("Initialize microk8s");
yield exec.exec('bash', ['-c', `sudo usermod -a -G ${microk8s_group} $USER`]);
yield exec.exec(`sudo usermod -a -G ${microk8s_group} ${user}`);
if (!(yield microk8s_init(channel, microk8s_addons, container_registry_url))) {
return;
}
Expand Down Expand Up @@ -5836,7 +5837,7 @@ function run() {
core.startGroup("Bootstrap controller");
bootstrap_command = `${bootstrap_command} --bootstrap-constraints="${bootstrap_constraints}"`;
if (group !== "") {
yield exec.exec('sg', [group, '-c', bootstrap_command]);
yield exec.exec(`sudo -u ${user} -E ${bootstrap_command}`);
}
else {
yield exec.exec(bootstrap_command);
Expand Down
13 changes: 7 additions & 6 deletions src/bootstrap/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as os from 'os'
import { retryAsyncDecorator } from 'ts-retry/lib/cjs/retry/utils';
import semver from 'semver';
import dedent from 'ts-dedent';
Expand All @@ -11,6 +12,7 @@ declare var process : {
}

const ignoreFail: exec.ExecOptions = {"ignoreReturnCode": true}
const user = os.userInfo().username

const os_release = async () => {
// Read os-release file into an object
Expand Down Expand Up @@ -54,8 +56,7 @@ function get_microk8s_group() {


async function exec_as_microk8s(cmd: string, options = {}) {
const microk8s_group = get_microk8s_group();
return await exec.exec('sg', [microk8s_group, '-c', cmd], options);
return await exec.exec(`sudo -u ${user} -E ${cmd}`, [], options);
}

async function retry_until_rc(cmd: string, expected_rc=0, maxRetries=12, timeout=10000) {
Expand Down Expand Up @@ -120,7 +121,7 @@ async function microk8s_init(channel, addons, container_registry_url:string) {
// Add the given addons if any were given.
await exec_as_microk8s("microk8s status --wait-ready --timeout=600");
if (addons) {
await exec_as_microk8s("sudo microk8s enable " + addons);
await exec.exec(`sudo microk8s enable ${addons}`);
}
let stdout_buf = '';
const options = {
Expand Down Expand Up @@ -261,7 +262,7 @@ async function run() {
await exec.exec("sudo lxd init --auto");
await exec.exec("sudo chmod a+wr /var/snap/lxd/common/lxd/unix.socket");
await exec.exec("lxc network set lxdbr0 ipv6.address none");
await exec.exec('bash', ['-c', 'sudo usermod -a -G lxd $USER']);
await exec.exec(`sudo usermod -a -G lxd ${user}`);
core.endGroup();
core.startGroup("Install tox");
await install_tox(tox_version);
Expand Down Expand Up @@ -309,7 +310,7 @@ async function run() {
}
core.endGroup();
core.startGroup("Initialize microk8s");
await exec.exec('bash', ['-c', `sudo usermod -a -G ${microk8s_group} $USER`]);
await exec.exec(`sudo usermod -a -G ${microk8s_group} ${user}`);
if(!await microk8s_init(channel, microk8s_addons, container_registry_url)) {
return;
}
Expand Down Expand Up @@ -358,7 +359,7 @@ async function run() {
core.startGroup("Bootstrap controller");
bootstrap_command = `${bootstrap_command} --bootstrap-constraints="${bootstrap_constraints}"`
if (group !== "") {
await exec.exec('sg', [group, '-c', bootstrap_command]);
await exec.exec(`sudo -u ${user} -E ${bootstrap_command}`);
} else {
await exec.exec(bootstrap_command);
}
Expand Down

0 comments on commit e41e1ae

Please sign in to comment.