Skip to content

Commit

Permalink
[WIP] Initial working version. Docs are still WIP, and no tests yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
scnerd committed Aug 31, 2022
0 parents commit 6eb9034
Show file tree
Hide file tree
Showing 27 changed files with 1,335 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[bumpversion]
current_version = 0.1.0
commit = True
tag = True

[bumpversion:file:setup.cfg]

[bumpversion:file:docker-printer/__init__.py]

[bumpversion:file:docs/conf.py]
18 changes: 18 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copied almost verbatim from https://github.com/marketplace/actions/sphinx-build
name: sphinx
on:
- push

jobs:
docs_build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ammaraskar/sphinx-action@master
with:
docs-folder: "docs/"

- uses: actions/upload-artifact@v1
with:
name: DocumentationHTML
path: docs/_build/html/
20 changes: 20 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: pre-commit

on:
pull_request:
push:
branches:
- main
- dev

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
- uses: pre-commit/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
27 changes: 27 additions & 0 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Upload Python Package

on:
release:
types: [published]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
147 changes: 147 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
### Example user template template
### Example user template

# IntelliJ project files
.idea
*.iml
out
gen
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
args: ['--unsafe'] # Temporary workaround while we still have cloudformation files
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
additional_dependencies: ['click!=8.1.0']
Empty file added README.md
Empty file.
2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add `setup` feature for modules
- Add build profiles to control the generation of the bakefile(s)
Empty file added docker_printer/__init__.py
Empty file.
67 changes: 67 additions & 0 deletions docker_printer/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import logging
import sys
from logging.config import dictConfig

log = logging.getLogger(__name__)


def main():
dictConfig(
dict(
version=1,
formatters=dict(
brief=dict(
format=logging.BASIC_FORMAT,
),
bare=dict(
format="%(message)s",
),
),
handlers=dict(
console={
"class": "logging.StreamHandler",
"formatter": "brief",
"level": logging.DEBUG,
"stream": sys.stdout,
},
console_bare={
"class": "logging.StreamHandler",
"formatter": "bare",
"level": logging.DEBUG,
"stream": sys.stderr,
},
),
loggers=dict(
rearc_cli=dict(
level=logging.DEBUG,
propagate=False,
handlers=["console_bare"],
),
rearc_data_utils=dict(
level=logging.DEBUG,
propagate=True,
),
jobs=dict(
level=logging.DEBUG,
propagate=True,
),
common=dict(
level=logging.DEBUG,
propagate=True,
),
__main__=dict(
level=logging.DEBUG,
propagate=True,
),
),
root=dict(handlers=["console"]),
)
)

from docker_printer.cli import cli

cli()


if __name__ == "__main__":
main()
73 changes: 73 additions & 0 deletions docker_printer/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import shutil
import subprocess
from pathlib import Path

import click

from .models import TargetCollection, BuildConfig, BuildConfigCollection
from .utils import (
config_dir,
jinja_env,
yml_load,
preload_modules,
targets_file,
builds_file,
)


@click.group()
def cli():
pass


@cli.command()
def synth():
_synth()


def _synth():
preload_modules()

targets = TargetCollection.parse_obj(yml_load(targets_file()))
build_configs = BuildConfigCollection.parse_obj(yml_load(builds_file()))

dockerfile = targets.render_dockerfile(jinja_env())
dockerfile_path = Path("Dockerfile.synth")

click.echo(f"Saving to {dockerfile_path}")
dockerfile_path.write_text(dockerfile)

for build_config in build_configs.__root__:
bakefile_path = Path(f"docker-bake.{build_config.name}.json")
bakefile = build_config.generate_bakefile(targets)
bakefile_path.write_text(bakefile)
click.echo(build_config.build_command)

return targets, build_configs


@cli.command()
@click.argument("name")
def build(name):
_, build_configs = _synth()

try:
config = next(cfg for cfg in build_configs.__root__ if cfg.name == name)
except StopIteration:
raise click.Abort(f"No build config found with name '{name}'")

subprocess.run(config.build_command)


@cli.command()
def init():
base_dir = config_dir()
if base_dir.exists():
click.echo(f"{base_dir} already exists, cannot initialize new project")
raise click.Abort()

base_dir.mkdir(exist_ok=False, parents=False)
(base_dir / "modules").mkdir(exist_ok=False, parents=False)
(base_dir / "templates").mkdir(exist_ok=False, parents=False)
(base_dir / "targets.yml.jinja2").touch(exist_ok=False)
(base_dir / "builds.yml.jinja2").touch(exist_ok=False)
Loading

0 comments on commit 6eb9034

Please sign in to comment.