From e495cb1e601987d0e72ebbabb0d9c12bf2658bf9 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Mon, 12 Jun 2023 18:41:44 +0200 Subject: [PATCH] add image-build doc --- README.md | 2 + doc/DevopsBuild.md | 2 +- doc/DevopsImageBuild.md | 113 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 doc/DevopsImageBuild.md diff --git a/README.md b/README.md index 284045e..5740d50 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ classDiagram DevopsBuild <|-- C4kBuild link DevopsBuild "./doc/DevopsBuild.md" + link DevopsImageBuild "./doc/DevopsImageBuild.md" ``` @@ -96,6 +97,7 @@ export PATH=$PATH:~/.local/bin ## Reference * [DevopsBuild](./doc/DevopsBuild.md) +* [DevopsImageBuild](./doc/DevopsImageBuild.md) diff --git a/doc/DevopsBuild.md b/doc/DevopsBuild.md index fb58899..99f3e42 100644 --- a/doc/DevopsBuild.md +++ b/doc/DevopsBuild.md @@ -50,7 +50,7 @@ def initialize(project): "mixin_types": [], } - build = DevopsTerraformBuild(project, config) + build = DevopsBuild(project, config) build.initialize_build_dir() diff --git a/doc/DevopsImageBuild.md b/doc/DevopsImageBuild.md new file mode 100644 index 0000000..7e0f164 --- /dev/null +++ b/doc/DevopsImageBuild.md @@ -0,0 +1,113 @@ +# DevopsImageBuild + +DevopsBuild stellt die build Grundlagen zur Verfügung. + +```mermaid +classDiagram + class DevopsImageBuild { + initialize_build_dir() - copy current directory & additional files to target + image() - build image localy. Sources for image build are expected at ./image + drun() - start your localy build image + dockerhub_login() - login to dockerhub + dockerhub_publish() - publish your image + test() - builds a test image. Sources for image test are expected at ./test + } + +``` + +## Input + +| name | description | default | +| ------------------------ | -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ | +| name | dedicated name of the build - also used as image name | module | +| module | module name - may result in a hierarchy like name/module | | +| stage | not used in this build | | +| project_root_path | relative path to projects root. Is used to locate the target dir | | +| build_dir_name | name of dir, build is executed in | target | +| build_types | list of special builds used. Value has to be contained["IMAGE"] | [] | +| mixin_types | mixins are orthoganl to builds and represent additional capabilities. Valid Values are ["RELEASE"] | [] | +| credentials_mappings | values for image_dockerhub_user & image_dockerhub_password can be read from gopass | [defaults](#credentials-mapping-defaults) | +| image_dockerhub_user | user to access docker-hub | IMAGE_DOCKERHUB_USER from env or credentials from gopass | +| image_dockerhub_password | password to access docker-hub | IMAGE_DOCKERHUB_PASSWORD from env or credentials from gopass | +| image_tag | tag for publishing the image | IMAGE_TAG from env | + + +### Credentials Mapping defaults + +```python +[ + { + "gopass_path": "meissa/web/docker.com", + "gopass_field": "login", + "name": "image_dockerhub_user", + }, + { + "gopass_path": "meissa/web/docker.com", + "name": "image_dockerhub_password", + }, +] +``` + +## Example Usage +### build.py + +```python +from subprocess import run +from pybuilder.core import task, init +from ddadevops import * + +name = 'my-project' +MODULE = 'my-module' +PROJECT_ROOT_PATH = '..' + +@init +def initialize(project): + project.build_depends_on("ddadevops>=4.0.0") + + input = { + "name": name, + "module": MODULE, + "stage": "notused", + "project_root_path": PROJECT_ROOT_PATH, + "build_types": ["IMAGE"], + "mixin_types": [], + } + + build = DevopsImageBuild(project, config) + build.initialize_build_dir() + + +@task +def image(project): + build = get_devops_build(project) + build.image() + + +@task +def drun(project): + build = get_devops_build(project) + build.drun() + + +@task +def test(project): + build = get_devops_build(project) + build.test() + + +@task +def publish(project): + build = get_devops_build(project) + build.dockerhub_login() + build.dockerhub_publish() +``` + +### call the build + +```bash +pyb image test publish +``` + +### full example + +... can be found [here](infrastructure/devops-build)