diff --git a/package-lock.json b/package-lock.json index 33cdd54..9ff8e7d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "domcloud-bridge", - "version": "0.46.0", + "version": "0.47.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "domcloud-bridge", - "version": "0.46.0", + "version": "0.47.0", "license": "MIT", "dependencies": { "axios": "^1.6.8", diff --git a/package.json b/package.json index 19bde6b..29cddbc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "domcloud-bridge", - "version": "0.46.0", + "version": "0.47.0", "description": "Deployment runner for DOM Cloud", "main": "app.js", "engines": { diff --git a/src/controllers/podman.js b/src/controllers/docker.js similarity index 73% rename from src/controllers/podman.js rename to src/controllers/docker.js index 753f1b3..9258d7d 100644 --- a/src/controllers/podman.js +++ b/src/controllers/docker.js @@ -1,7 +1,7 @@ import express from 'express'; import { - podmanExec as executor -} from '../executor/podman.js'; + dockerExec as executor +} from '../executor/docker.js'; import { checkGet, checkPost @@ -11,21 +11,21 @@ export default function () { var router = express.Router(); router.get('/show', checkGet(['user']), async function (req, res, next) { try { - res.json([executor.checkPodmanEnabled(req.query.user.toString())]); + res.json([executor.checkDockerEnabled(req.query.user.toString())]); } catch (error) { next(error); } }); router.post('/add', checkPost(['user']), async function (req, res, next) { try { - res.json(await executor.enablePodman(req.body.user.toString())); + res.json(await executor.enableDocker(req.body.user.toString())); } catch (error) { next(error); } }); router.post('/del', checkPost(['user']), async function (req, res, next) { try { - res.json(await executor.disablePodman(req.body.user.toString())); + res.json(await executor.disableDocker(req.body.user.toString())); } catch (error) { next(error); } diff --git a/src/executor/podman.js b/src/executor/docker.js similarity index 68% rename from src/executor/podman.js rename to src/executor/docker.js index f1010d1..319aade 100644 --- a/src/executor/podman.js +++ b/src/executor/docker.js @@ -4,51 +4,51 @@ import { } from '../util.js'; import { existsSync } from 'fs'; -class PodmanExecutor { +class DockerExecutor { LOGINLINGERDIR = '/var/lib/systemd/linger'; constructor() { if (process.env.LOGINLINGERDIR) { - this.LOGINLINGERDIR = '/var/lib/systemd/linger'; + this.LOGINLINGERDIR = process.env.LOGINLINGERDIR; } } /** * @param {string} user */ - checkPodmanEnabled(user) { + checkDockerEnabled(user) { return existsSync(this.LOGINLINGERDIR + '/' + user); } /** * @param {string} user */ - async enablePodman(user) { - if (this.checkPodmanEnabled(user)) { + async enableDocker(user) { + if (this.checkDockerEnabled(user)) { return "Done unchanged"; } - return await executeLock('podman', async () => { + return await executeLock('docker', async () => { await spawnSudoUtil("SHELL_SUDO", ["root", "usermod", "--add-subuids", "100000-165535", "--add-subgids", "100000-165535", user]); await spawnSudoUtil("SHELL_SUDO", ["root", "loginctl", "enable-linger", user]); - return "Updated for podman"; + return "Updated for docker"; }); } /** * @param {string} user */ - async disablePodman(user) { - if (!this.checkPodmanEnabled(user)) { + async disableDocker(user) { + if (!this.checkDockerEnabled(user)) { return "Done unchanged"; } - return await executeLock('podman', async () => { + return await executeLock('docker', async () => { await spawnSudoUtil("SHELL_SUDO", ["root", "usermod", "--del-subuids", "100000-165535", "--del-subgids", "100000-165535", user]); await spawnSudoUtil("SHELL_SUDO", ["root", "loginctl", "disable-linger", user]); - return "Updated for podman"; + return "Updated for docker"; }); } } -export const podmanExec = new PodmanExecutor(); +export const dockerExec = new DockerExecutor(); diff --git a/src/executor/runnercode.js b/src/executor/runnercode.js index 9623046..f4a0dfa 100644 --- a/src/executor/runnercode.js +++ b/src/executor/runnercode.js @@ -1,5 +1,5 @@ import { getJavaVersion, getPythonVersion, getRubyVersion } from "../util.js"; -import { podmanExec } from "./podman.js"; +import { dockerExec } from "./docker.js"; /** * @param {string} key @@ -12,13 +12,19 @@ export async function runConfigCodeFeatures(key, value, writeLog, domaindata, ss let arg; switch (key) { case 'docker': - case 'podman': if (value === '' || value === 'on') { - await writeLog("$> Enabling podman features"); - await writeLog(await podmanExec.enablePodman(domaindata['Username'])); + await writeLog("$> Enabling docker features"); + await writeLog(await dockerExec.enableDocker(domaindata['Username'])); + await sshExec(`sed -i '/DOCKER_HOST=/d' ~/.bashrc`, false); + await sshExec(`echo "export DOCKER_HOST=unix:///run/user/$(id -u)/docker.sock" >> ~/.bashrc; source ~/.bashrc`); + await sshExec(`mkdir -p ~/.config/docker; echo '{"exec-opts": ["native.cgroupdriver=cgroupfs"]}' > ~/.config/docker/daemon.json`); + await sshExec(`dockerd-rootless-setuptool.sh install`); } else if (value === 'off') { - await writeLog("$> Disabling podman features"); - await writeLog(await podmanExec.disablePodman(domaindata['Username'])); + await writeLog("$> Disabling docker features"); + await sshExec(`dockerd-rootless-setuptool.sh uninstall`); + await sshExec(`sed -i '/DOCKER_HOST=/d' ~/.bashrc`); + await sshExec(`rm -rf ~/.config/docker`); + await writeLog(await dockerExec.disableDocker(domaindata['Username'])); } break; case 'python': diff --git a/src/index.js b/src/index.js index a2d150d..ffd3a52 100644 --- a/src/index.js +++ b/src/index.js @@ -12,7 +12,7 @@ import { } from './util.js'; import runner from './controllers/runner.js'; import virtualmin from './controllers/virtualmin.js'; -import podman from './controllers/podman.js'; +import docker from './controllers/docker.js'; const startTime = Date.now(); dotenv.config(); @@ -29,7 +29,7 @@ app.use('/named', named()); app.use('/nginx', nginx()); app.use('/iptables', iptables()); app.use('/screend', screend()); -app.use('/podman', podman()); +app.use('/docker', docker()); app.use('/runner', runner()); app.use('/virtualmin', virtualmin()); app.use(function (err, req, res, next) { diff --git a/src/whitelist/sites.conf b/src/whitelist/sites.conf index 072d8be..c83b72d 100644 --- a/src/whitelist/sites.conf +++ b/src/whitelist/sites.conf @@ -52,10 +52,10 @@ ziglang.org # .Net dotnet.microsoft.com dotnetcli.azureedge.net -# Podman -registry.access.redhat.com -registry.redhat.io +# Docker docker.io +registry.docker.io +registry-1.docker.io # WordPress api.wordpress.org dashboard.jetpack.com