-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Initial working version. Docs are still WIP, and no tests yet.
- Loading branch information
0 parents
commit 6eb9034
Showing
27 changed files
with
1,335 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.