dda-devops-build/README.md

208 lines
5.5 KiB
Markdown
Raw Permalink Normal View History

2019-09-04 16:40:41 +00:00
# dda-devops-build
[![Slack](https://img.shields.io/badge/chat-clojurians-green.svg?style=flat)](https://clojurians.slack.com/messages/#dda-pallet/) | [<img src="https://meissa-gmbh.de/img/community/Mastodon_Logotype.svg" width=20 alt="team@social.meissa-gmbh.de"> team@social.meissa-gmbh.de](https://social.meissa-gmbh.de/@team) | [Website & Blog](https://domaindrivenarchitecture.org)
2020-07-02 10:44:25 +00:00
![release prod](https://github.com/DomainDrivenArchitecture/dda-devops-build/workflows/release%20prod/badge.svg)
2023-05-31 07:25:10 +00:00
dda-devops-build integrates all the tools we use to work with clouds & provide some nice functions around.
Tools we support are
* terraform: for setting up the plain infrastructure around.
* docker: for creating images
* c4k: for generating kubernetes manifests
* provs: for setting up small single-node k3s clusters
* gopass: for credential management on devops computers
* cloud providers: hetzner, digitalocean, aws
In addition we provide a ReleaseMixin for release related tasks like tag / publish & version-bump
```mermaid
classDiagram
class DevopsBuild {
name()
build_path()
initialize_build_dir()
}
class DevopsTerraformBuild {
initialize_build_dir()
post_build()
read_output_json()
plan()
plan_fail_on_diff()
apply(auto_approve=False)
refresh()
destroy(auto_approve=False)
2023-06-13 06:50:26 +00:00
tf_import(tf_import_name,tf_import_resource)
2023-05-31 07:25:10 +00:00
}
class DevopsImageBuild {
2023-06-13 06:50:26 +00:00
initialize_build_dir()
2023-05-31 07:25:10 +00:00
image()
drun()
dockerhub_login()
dockerhub_publish()
test()
}
class ReleaseMixin {
prepare_release()
tag_and_push_release()
}
class ProvsK3sBuild {
def update_runtime_config(dns_record)
write_provs_config()
provs_apply(dry_run=False)
}
class C4kBuild {
def update_runtime_config(dns_record)
def write_c4k_config()
def write_c4k_auth()
c4k_apply(dry_run=False)
}
DevopsBuild <|-- DevopsImageBuild
DevopsBuild <|-- DevopsTerraformBuild
DevopsBuild <|-- ReleaseMixin
DevopsBuild <|-- ProvsK3sBuild
DevopsBuild <|-- C4kBuild
2023-07-19 12:47:40 +00:00
link DevopsBuild "dda-devops-build/src/doc/DevopsBuild.md"
link DevopsImageBuild "dda-devops-build/src/doc/DevopsImageBuild.md"
link DevopsTerraformBuild "dda-devops-build/src/doc/DevopsTerraformBuild.md"
link ReleaseMixin "dda-devops-build/src/doc/ReleaseMixin.md"
link ProvsK3sBuild "dda-devops-build/src/doc/ProvsK3sBuild.md"
link C4kBuild "dda-devops-build/src/doc/C4kBuild.md"
2023-06-01 07:28:43 +00:00
2023-05-31 07:25:10 +00:00
```
Principles we follow are:
* Seperate build artefacts from version controlled code
* Domain Driven Design - in order to stay sustainable
2020-04-16 16:40:51 +00:00
2023-06-01 07:28:43 +00:00
## Installation
2020-04-16 16:40:51 +00:00
2023-05-31 07:25:10 +00:00
Ensure that yout python3 version is at least Python 3.10
2020-01-28 10:57:38 +00:00
```
sudo apt install python3-pip
2023-05-31 07:25:10 +00:00
pip3 install -r requirements.txt
2020-01-28 10:57:38 +00:00
export PATH=$PATH:~/.local/bin
```
2019-09-04 16:40:41 +00:00
2023-06-01 07:28:43 +00:00
## Reference
* [DevopsBuild](./doc/DevopsBuild.md)
2023-06-12 16:41:44 +00:00
* [DevopsImageBuild](./doc/DevopsImageBuild.md)
2023-06-13 11:33:20 +00:00
* [DevopsTerraformBuild](./doc/DevopsTerraformBuild.md)
* [AwsProvider](doc/DevopsTerraformBuildWithAwsProvider.md)
* [DigitaloceanProvider](doc/DevopsTerraformBuildWithDigitaloceanProvider.md)
* [HetznerProvider](doc/DevopsTerraformBuildWithHetznerProvider.md)
* [ReleaseMixin](./doc/ReleaseMixin.md)
2023-06-13 15:22:44 +00:00
* [ProvsK3sBuild](doc/ProvsK3sBuild.md)
2023-06-13 15:38:15 +00:00
* [C4kBuild](doc/C4kBuild.md)
2023-06-01 07:28:43 +00:00
## Example Build
2020-04-16 16:40:51 +00:00
2020-11-12 16:37:55 +00:00
lets assume the following project structure
2020-04-02 09:48:24 +00:00
```
my-project
| -> my-module
| | -> build.py
| | -> some-terraform.tf
| -> an-other-module
| -> target (here will the build happen)
| | -> ...
```
2023-06-01 07:28:43 +00:00
```python
2020-04-02 09:48:24 +00:00
from pybuilder.core import task, init
from ddadevops import *
name = 'my-project'
MODULE = 'my-module'
PROJECT_ROOT_PATH = '..'
@init
def initialize(project):
2023-06-01 07:28:43 +00:00
project.build_depends_on("ddadevops>=4.0.0-dev")
config = {
"credentials_mapping": [
{
"gopass_path": environ.get("DIGITALOCEAN_TOKEN_KEY_PATH", None),
"name": "do_api_key",
},
{
"gopass_path": environ.get("HETZNER_API_KEY_PATH", None),
"name": "hetzner_api_key",
},
],
"name": name,
"module": MODULE,
"stage": environ["STAGE"],
"project_root_path": PROJECT_ROOT_PATH,
"build_types": ["TERRAFORM"],
"mixin_types": [],
"tf_provider_types": ["DIGITALOCEAN", "HETZNER"],
"tf_use_workspace": False,
"tf_terraform_semantic_version": "1.4.2",
"do_as_backend": True,
"do_bucket": "your-bucket",
}
build = DevopsTerraformBuild(project, config)
2020-04-02 09:48:24 +00:00
build.initialize_build_dir()
@task
def plan(project):
build = get_devops_build(project)
build.plan()
@task
def apply(project):
build = get_devops_build(project)
2023-06-01 07:28:43 +00:00
build.apply(True)
2020-04-18 13:25:40 +00:00
2020-06-03 10:14:33 +00:00
@task
2023-06-01 07:28:43 +00:00
def destroy(project):
2020-06-03 10:14:33 +00:00
build = get_devops_build(project)
2023-06-01 07:28:43 +00:00
build.destroy(True)
2020-06-03 10:14:33 +00:00
```
2023-07-06 16:11:29 +00:00
## Snapshot & Release
2020-07-06 07:50:53 +00:00
```
2023-07-06 16:11:29 +00:00
pyb dev publish upload
2023-07-07 13:42:53 +00:00
pip3 install --upgrade ddadevops --pre
2023-07-06 16:11:29 +00:00
2023-07-14 11:27:11 +00:00
pyb [patch|minor|major]
2023-07-07 13:42:53 +00:00
pip3 install --upgrade ddadevops
2020-07-06 07:50:53 +00:00
```
2019-11-06 17:16:52 +00:00
2023-07-06 16:08:01 +00:00
## Development & mirrors
Development happens at: https://repo.prod.meissa.de/meissa/dda-devops-build
Mirrors are:
* https://gitlab.com/domaindrivenarchitecture/dda-devops-build (issues and PR, CI)
* https://github.com/DomainDrivenArchitecture/dda-devops-build
2023-07-06 16:08:01 +00:00
For more details about our repository model see: https://repo.prod.meissa.de/meissa/federate-your-repos
## License
Copyright © 2021 meissa GmbH
Licensed under the [Apache License, Version 2.0](LICENSE) (the "License")