Skip to content

Commit

Permalink
Podman -> Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed May 10, 2024
1 parent 13e4e15 commit 1135627
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 31 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
10 changes: 5 additions & 5 deletions src/controllers/podman.js → src/controllers/docker.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
}
Expand Down
24 changes: 12 additions & 12 deletions src/executor/podman.js → src/executor/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
18 changes: 12 additions & 6 deletions src/executor/runnercode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getJavaVersion, getPythonVersion, getRubyVersion } from "../util.js";
import { podmanExec } from "./podman.js";
import { dockerExec } from "./docker.js";

/**
* @param {string} key
Expand All @@ -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':
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/whitelist/sites.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1135627

Please sign in to comment.