This repository contains the monorepo developed for Magalu Cloud (MGC). Each subdirectory within mgc/ corresponds to a Go module:
-
Core: Definition of data types used for the intermediate structure generated by the SDK after parsing either an OpenAPI spec or a static definition.
-
SDK: Implement the concrete data types defined by core to generate usable commands. The commands can be used by the CLI via Cobra commands, or by Terraform Plugin Provider to perform CRUD on resources.
-
CLI: Go CLI, using Cobra, with commands and actions defined by the SDK. The commands can either come from dynamic loaded OpenAPI spec or static modules, i.e: authentication.
Our code is written in Golang, however there are some utility scripts written in Python as well.
Looking for Terraform code? Check out the Terraform provider repository
To run the project, the main dependency needed is Go. To install, visit the official link with the instructions.
There are some utility scripts written in Python. For this, Poetry is used. Check Poetry.md for instructions.
Building needs goreleaser and can be done using Makefile targets.
If you have API spec changes, update them on specs, on the corresponding product and run the following commands:
- ⚡ to validate and prettify the specs
$ make prepare-specs- ⚡ this command will convert the oas file with 3.1.x version to 3.0.x version.
$ make downgrade-specs- ⚡ refresh specs
$ make refresh-specsAfter that (or if there are no further spec changes), build the CLI with:
$ make build-localIf all goes well, the output binary will be a platform-dependent directory, where it can be run:
$ cd dist/mgc_<your_platform>
$ ./mgcTo add a new API spec, see instructions.
Manually written APIs should be added to mgc/sdk/static, follow the
structure in the exiting modules (auth, config).
We use pre-commit to install git hooks and enforce lint, formatting, tests, commit messages and others. This tool depends on Python as well. On pre-commit we enforce:
- On
commit-msgfor all commits:- Conventional commit pattern with commitzen
- On
pre-commitfor Go files:- Complete set of golangci-lint:
errcheck,gosimple,govet,ineffasign,staticcheck,unused
- Complete set of golangci-lint:
- On
pre-commitfor Python files:flake8andblackenforcing pep code styles
brew install pre-commitpip install pre-commitFor other types of installation, check their official doc.
After installing, the developer must configure the git hooks inside its clone:
pre-commit installWe install the go linters via pre-commit, so it is automatically run by the
pre-commit git hook. However, if one wants to run standalone it can be done via:
pre-commit run golangci-lintRun pre-commit without any file modified:
pre-commit run -a