DavesCodeMusings / container-central

A minimalist, not quite ready for prime time solution to managing Docker containers.
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Add git integration for compose files #2

Closed DavesCodeMusings closed 2 years ago

DavesCodeMusings commented 2 years ago

Node Lite image has git built in. It would not be difficult to clone files from a git repo into the container-central/compose directory. Kind of like this...

docker exec -it container-central bash
cd /app/compose
git clone http://git.mypi.home/docker-compose-files.git .
  1. Store git repo url in a configuration variable.
  2. Create an express route for /images/clone (or something like that.)
  3. exec a child process with working dir of process.cwd() + '/compose'
  4. Create client side trigger. (source-repository icon, git url, file-refresh-outline icon to initiate.)
#!/usr/bin/env node

const { exec } = require('child_process');
const fs = require('fs');

const composeDir = '/home/pi/compose';
const gitUrl = 'http://git.home:3000/pi/docker-compose.git';

if (!fs.existsSync(composeDir)) {
  console.error(`No such directory: ${composeDir}`);
}
else {
  if (fs.existsSync(`${composeDir}/.git`)) {
    console.log('Pulling compose files.');
    exec(`git pull`, { cwd: composeDir }, (err, stdout, stderr) => {
      if (err) {
        console.error('Error 1201');
      }
    });
  }
  else {
    console.log('Cloning compose files.');
    exec(`git clone ${gitUrl} .`, { cwd: composeDir }, (err, stdout, stderr) => {
      if (err) {
        console.error('Error 1202');
      }
    });
  }
}
DavesCodeMusings commented 2 years ago

Implemented, but requires manual git clone for initial set up. Could be improved with automatic git clone when directory is empty.

DavesCodeMusings commented 2 years ago

Added ability to configure git URL. Updated Git Integration document.