Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
ib-steffen committed Jun 11, 2017
1 parent 6ad066d commit e9c904a
Show file tree
Hide file tree
Showing 61 changed files with 2,222 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git
.infrabox
Dockerfile
.dockerignore
*.pyc
__pycache__
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.infrabox*
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include README.md
include LICENSE
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# cli
CLI for InfraBox
# InfraBox CLI
3 changes: 3 additions & 0 deletions bin/infrabox
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/python
import infraboxcli
infraboxcli.main()
6 changes: 6 additions & 0 deletions examples/1_hello_world/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM alpine

RUN adduser -S testuser
USER testuser

CMD echo "hello world"
10 changes: 10 additions & 0 deletions examples/1_hello_world/infrabox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": 1,
"jobs": [{
"type": "docker",
"name": "example1",
"docker_file": "Dockerfile",
"build_only": false,
"machine_config": "vm-1-2048"
}]
}
4 changes: 4 additions & 0 deletions examples/2_dependencies/Dockerfile_consumer
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM alpine
RUN adduser -S testuser
USER testuser
CMD cat /infrabox/inputs/producer/data.txt
4 changes: 4 additions & 0 deletions examples/2_dependencies/Dockerfile_producer
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM alpine
RUN adduser -S testuser
USER testuser
CMD echo "hello world" > /infrabox/output/data.txt
17 changes: 17 additions & 0 deletions examples/2_dependencies/infrabox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": 1,
"jobs": [{
"type": "docker",
"name": "producer",
"docker_file": "Dockerfile_producer",
"build_only": false,
"machine_config": "vm-1-2048"
}, {
"type": "docker",
"name": "consumer",
"docker_file": "Dockerfile_consumer",
"build_only": false,
"machine_config": "vm-1-2048",
"depends_on": ["producer"]
}]
}
9 changes: 9 additions & 0 deletions examples/3_testresult/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM alpine

ADD result.json /result.json
ADD entrypoint.sh /entrypoint.sh

RUN adduser -S tester
USER tester

CMD /entrypoint.sh
5 changes: 5 additions & 0 deletions examples/3_testresult/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh -e

# Run your tests and generate the result json file

cp /result.json /infrabox/upload/testresult
10 changes: 10 additions & 0 deletions examples/3_testresult/infrabox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": 1,
"jobs": [{
"type": "docker",
"name": "testresult",
"docker_file": "Dockerfile",
"build_only": false,
"machine_config": "vm-1-2048"
}]
}
21 changes: 21 additions & 0 deletions examples/3_testresult/result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": 1,
"tests": [{
"name": "test 1",
"suite": "Test suite",
"status": "ok",
"duration": 123,
"measurements": [{
"name": "Custom measurement",
"value": "123",
"unit": "hz"
}]
}, {
"name": "test 2",
"suite": "Test suite",
"status": "error",
"duration": 43,
"message": "TypeError: Again !?!",
"stack": "Traceback (most recent call last):\n File \"e.py\", line 7, in <module>\n raise TypeError(\"Again !?!\")"
}]
}
6 changes: 6 additions & 0 deletions examples/4_security_scan/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM debian

RUN useradd -ms /bin/bash user
USER user

CMD echo "hello world"
13 changes: 13 additions & 0 deletions examples/4_security_scan/infrabox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"jobs": [{
"type": "docker",
"name": "security_scan",
"docker_file": "Dockerfile",
"build_only": false,
"machine_config": "vm-1-2048",
"security": {
"scan_container": true
}
}]
}
6 changes: 6 additions & 0 deletions examples/5_keep/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM alpine

RUN adduser -S testuser
USER testuser

CMD echo "hello world"
4 changes: 4 additions & 0 deletions examples/5_keep/Dockerfile_consumer
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM alpine
RUN adduser -S testuser
USER testuser
CMD cat /infrabox/inputs/producer/data.txt
4 changes: 4 additions & 0 deletions examples/5_keep/Dockerfile_producer
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM alpine
RUN adduser -S testuser
USER testuser
CMD echo "hello world" > /infrabox/output/data.txt
18 changes: 18 additions & 0 deletions examples/5_keep/infrabox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": 1,
"jobs": [{
"type": "docker",
"name": "producer",
"docker_file": "Dockerfile_producer",
"build_only": false,
"machine_config": "vm-1-2048"
}, {
"type": "docker",
"name": "consumer",
"docker_file": "Dockerfile_consumer",
"build_only": false,
"machine_config": "vm-1-2048",
"keep": true,
"depends_on": ["producer"]
}]
}
22 changes: 22 additions & 0 deletions infrabox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"version": 1,
"jobs": [{
"type": "docker",
"name": "pyinfrabox",
"docker_file": "infrabox/pyinfrabox/Dockerfile",
"build_only": false,
"machine_config": "vm-1-2048"
}, {
"type": "docker",
"name": "infraboxcli-python2",
"docker_file": "infrabox/infraboxcli/Dockerfile_python2",
"build_only": false,
"machine_config": "vm-1-2048"
}, {
"type": "docker",
"name": "infraboxcli-python3",
"docker_file": "infrabox/infraboxcli/Dockerfile_python3",
"build_only": false,
"machine_config": "vm-1-2048"
}]
}
17 changes: 17 additions & 0 deletions infrabox/infraboxcli/Dockerfile_python2
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM alpine:3.4

RUN apk add --no-cache py-pip py-yaml
RUN pip install coverage

RUN adduser -S tester

COPY . /infraboxcli
RUN chown -R tester /infraboxcli

WORKDIR /infraboxcli

RUN pip install .

USER tester

CMD /infraboxcli/infrabox/infraboxcli/entrypoint.sh
17 changes: 17 additions & 0 deletions infrabox/infraboxcli/Dockerfile_python3
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM alpine:3.4

RUN apk add --no-cache python3
RUN pip3 install coverage

RUN adduser -S tester

COPY . /infraboxcli
RUN chown -R tester /infraboxcli

WORKDIR /infraboxcli

RUN pip3 install .

USER tester

CMD /infraboxcli/infrabox/infraboxcli/entrypoint.sh
14 changes: 14 additions & 0 deletions infrabox/infraboxcli/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh -e
find /infraboxcli -name \*.pyc -delete

# test help
echo "## Test --help"
infrabox --help

# test list
echo "## Test list"
infrabox list

# test validate
echo "## Test validate"
infrabox validate
17 changes: 17 additions & 0 deletions infrabox/pyinfrabox/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM stege/baseimage:1

RUN apk add --no-cache py-pip py-yaml git
RUN pip install coverage future

RUN adduser -S tester

COPY pyinfrabox /pyinfrabox
COPY infrabox/pyinfrabox/entrypoint.sh /pyinfrabox/entrypoint.sh

RUN chown -R tester /pyinfrabox

USER tester

WORKDIR /pyinfrabox

CMD /pyinfrabox/entrypoint.sh
14 changes: 14 additions & 0 deletions infrabox/pyinfrabox/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh -e

mkdir -p /infrabox/upload/badge
mkdir -p /infrabox/upload/markup

echo "## Run tests"
nosetests --with-coverage --cover-xml --cover-branches --cover-package=pyinfrabox --cover-tests tests/*

echo "## Download coverage"
git clone https://github.com/InfraBox/coverage.git /tmp/coverage

echo "## Create coverage result"
export PYTHONPATH=/
python /tmp/coverage/coverage.py --output /infrabox/upload/markup/coverage.json --input coverage.xml --badge /infrabox/upload/badge/coverage.json --format py-coverage
93 changes: 93 additions & 0 deletions infraboxcli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import argparse
import os
import sys

from infraboxcli.push import push
from infraboxcli.run import run
from infraboxcli.graph import graph
from infraboxcli.validate import validate
from infraboxcli.list_jobs import list_jobs
from infraboxcli.log import logger
from infraboxcli.init import init
from infraboxcli.pull import pull
from infraboxcli.version import version

def main():
parser = argparse.ArgumentParser(prog="infrabox")
parser.add_argument("--host", required=False, default="https://dashboard.infrabox.net")
sub_parser = parser.add_subparsers(help='sub-command help')

# version
version_init = sub_parser.add_parser('version', help='Show the current version')
version_init.set_defaults(version=version)

# init
parser_init = sub_parser.add_parser('init', help='Create a simple project')
parser_init.set_defaults(is_init=True)
parser_init.set_defaults(func=init)

# push
parser_push = sub_parser.add_parser('push', help='Push a local project to InfraBox')
parser_push.add_argument("--show-console", action='store_true', required=False,
help="Show the console output of the jobs")
parser_push.set_defaults(show_console=False)
parser_push.set_defaults(validate_only=False)
parser_push.set_defaults(func=push)

# push
parser_pull = sub_parser.add_parser('pull', help='Pull a remote job')
parser_pull.add_argument("--job-id", required=True)
parser_pull.set_defaults(func=pull)

# graph
parser_graph = sub_parser.add_parser('graph', help='Generate a graph of your local jobs')
parser_graph.add_argument("--output", required=True, type=str,
help="Path to the output file")
parser_graph.set_defaults(func=graph)

# validate
validate_graph = sub_parser.add_parser('validate', help='Validate infrabox.json')
validate_graph.set_defaults(func=validate)

# list
list_job = sub_parser.add_parser('list', help='List all available jobs')
list_job.set_defaults(func=list_jobs)

# run
parser_run = sub_parser.add_parser('run', help='Run your jobs locally')
parser_run.add_argument("--job-name", required=False, type=str,
help="Job name to execute")
parser_run.add_argument("--clean", action='store_true', required=False,
help="Runs 'docker-compose rm' before building")
parser_run.add_argument("-e", dest='environment', default=[], required=False,
action='append', type=str,
help="Add environment variable to jobs")
parser_run.set_defaults(clean=False)
parser_run.set_defaults(func=run)

# Parse args
args = parser.parse_args()

if 'version' in args:
print('infraboxcli %s' % version)
return

# Find infrabox.json
p = os.getcwd()

while p:
tb = os.path.join(p, 'infrabox.json')
if not os.path.exists(tb):
p = p[0:p.rfind('/')]
else:
args.project_root = p
args.infrabox_json = tb
args.project_name = os.path.basename(p)
break

if 'project_root' not in args and 'is_init' not in args:
logger.error("infrabox.json not found in current or any parent directory")
sys.exit(1)

# Run command
args.func(args)
Loading

0 comments on commit e9c904a

Please sign in to comment.