IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
Bläddra i källkod

Sketched step execution implementation

tags/0.92
förälder
incheckning
69a9be66f1
3 ändrade filer med 39 tillägg och 17 borttagningar
  1. +1
    -9
      Fockerfile
  2. +4
    -0
      jail.py
  3. +34
    -8
      steps.py

+ 1
- 9
Fockerfile Visa fil

@@ -1,14 +1,6 @@
from: freebsd-12.1
base: freebsd-12.1
steps:
- run: |
pkg install python3 && \
pkg install py37-pip
jail:
name: xxx
mount.devfs: true
ip4.address: 127.0.0.2
interface: lo1
exec.start: /bin/sh /etc/rc
exec.stop: /bin/sh /etc/rc.shutdown

+ 4
- 0
jail.py Visa fil

@@ -0,0 +1,4 @@
import subprocess
def jail_run(path, command):
subprocess.check_output(['jail', '-c', 'path=' + path, 'command', '/bin/sh', '-c', command)

+ 34
- 8
steps.py Visa fil

@@ -1,5 +1,7 @@
import hashlib
import json
from jail import jail_run
import shutil
def filehash(fname):
@@ -15,25 +17,32 @@ def filehash(fname):
class RunStep(object):
def __init__(self, base, spec):
self.base = base
def __init__(self, spec):
if not isinstance(spec, list) and \
not isinstance(spec, str):
raise ValueError('Run spec must be a list or a string')
self.spec = spec
def hash(self):
def hash(self, base):
res = hashlib.sha256(
json.dumps(( self.base, self.spec ))
json.dumps(( base, self.spec ))
.encode('utf-8')).hexdigest()
return res
def execute(self, path):
spec = self.spec
if isinstance(spec, list)
spec = ' && ' .join(self.spec)
jail_run(path, spec)
class CopyStep(object):
def __init__(self, base, spec):
def __init__(self, spec):
if not isinstance(spec, list):
raise ValueError('CopyStep spec should be a list')
self.base = base
self.spec = spec
def hash(self):
def hash(self, base):
if len(self.spec) == 0:
fh = []
elif isinstance(self.spec[0], list):
@@ -41,6 +50,23 @@ class CopyStep(object):
else:
fh = [ filehash(self.spec[0]) ]
res = hashlib.sha256(
json.dumps(( self.base, fh, self.spec ))
json.dumps(( base, fh, self.spec ))
.encode('utf-8')).hexdigest()
return res
def execute(self, path):
lst = [ self.spec ] \
if not isinstance(self.spec[0], list) \
else self.spec
for a in lst:
shutil.copyfile(a[0], os.path.join(path, a[1]))
def create_step(spec):
if not isinstance(spec, dict):
raise ValueError('Step specification must be a dictionary')
if 'copy' in spec:
return CopyStep(spec['copy'])
elif 'run' in spec:
return RunStep(spec['run'])
raise ValueError('Unrecognized step spec: ' + json.dumps(spec))

Laddar…
Avbryt
Spara