terraform-provider-docker/CONTRIBUTING.md

201 lines
5.9 KiB
Markdown
Raw Normal View History

2020-12-24 10:27:35 -05:00
# Contributing
2021-06-02 01:54:29 -04:00
By participating in this project, you agree to abide our [code of conduct](/CODE_OF_CONDUCT.md).
## Write Issue
When you have a bug report or feature request or something, please create an issue from [here](https://github.com/kreuzwerker/terraform-provider-docker/issues/new/choose).
2021-06-02 01:54:29 -04:00
Before creating an issue, please check whether same or related issues exist.
Please use issue templates as much as possible.
### Guide of Bug report
* The code should be runnable for maintainers to reproduce the problem
* We can't reproduce the problem with partial code
* Don't include unknown input variables, local values, resources, etc
* If you can reproduce the problem with public Docker images, please don't use private Docker images
* The code should be simple as much as possible. The simple code helps us to understand and reproduce the problem
* Don't include unneeded resources to reproduce the problem
* Don't set unneeded attributes to reproduce the problem
2020-12-24 10:27:35 -05:00
2021-06-02 01:54:29 -04:00
## Set up your machine
2020-12-24 10:27:35 -05:00
`terraform-provider-docker` is written in [Go](https://golang.org/).
Prerequisites:
- `make`, `git`, `bash`
- [Go 1.18+](https://golang.org/doc/install)
2020-12-24 10:27:35 -05:00
- [Docker](https://www.docker.com/)
- [Terraform 0.12+](https://terraform.io/)
- [git-chglog](https://github.com/git-chglog/git-chglog)
- [svu](https://github.com/caarlos0/svu)
2020-12-24 10:27:35 -05:00
Clone `terraform-provider-docker` anywhere:
```sh
git clone git@github.com:kreuzwerker/terraform-provider-docker.git
```
Install the build dependencies, tools and commit message validation:
2020-12-24 10:27:35 -05:00
```sh
make setup
2020-12-24 10:27:35 -05:00
make build
```
## Test your change
You can create a branch for your changes and try to build from the source as you go:
```sh
make build
```
### Unit and acceptance tests
When you are satisfied with the changes, **tests**, and **documentation** updates, we suggest you run:
```sh
# unit tests
make test
# acceptance test
## setup the testing environment
make testacc_setup
## run a single test
chore/refactor tests (#201) * chore: format test configs for datasources * chore: outlines load test config helper and structure * docs(contributing): add command for resouce tests to have an example of the regex * refactor: move container test configs into separate files * fix: add insecure_skip_verify for image pulls to fix the local test setup with invalid certs * chore(ci): remove insecure registry adaption * chore: regenerate website * chore: update gitignore for scipts/testing dir * fix: replace nodejs services with go versions * fix: move testing program versions in separate files * test: reactivate flaky test from travis * chore: fix linter on all go files * fix(linter): testing go servers * chore(ci): add env for go version * chore(ci): name workflow steps also moves description of available docker versions in to acc dockerfile * Revert "test: reactivate flaky test from travis" This reverts commit b02654acc4d6b7d02c8f3ba090e6a3f248741b10. * docs: fix provider-ssh example * chore: use alpine als final image for tests * refactor: move test configs from folder into testname.tf files * refactor: image delete log is now debug and indented * refactor: image test config into seprate files * refactor: move network test config into seperate files * refactor: move plugin test config into seperate files * chore: rename registry image test file * refactor: move registry_image test config into seperate files * chore: format secret test configs * refactor: inline volume test configs * fix: remove unused volume label test function * refactor: move service test configs into seperate files * test: reactivate and fix service test * chore: simplify insecure skip verify add to http client * chore(ci): debug into service test * chore(ci): add testacc setup * chore: format tf config for provider test * chore(ci): add debug output for config.json * fix: check service auth for emptyness * fix: remove re-read of provider auth config because the bug occured only in CI as the meta object might be GCd * test: pass auth to service instead of provider * chore: reactivate all acc tests * test: outlines service inspect json check for full spec * test: add service inspect json checks * test: finish service inspect json checks * chore(service): move test helper to end to of the file * chore: move mapEquals to test helpers * test: add json inspect for config * chore: add debug inspect log for plugin, secret and volume * test: add json inspect for secret * test: add json inspect for image * test: add json inspect for network * test: add json inspect for plugin * test: add json inspect for volume * test: inline ds plugin test configs * test: inline network configs * test: move ds reg image configs into separate files * test: reactivates container upload checks * chore: adapt issues ref from old to new xw repo * fix: reactivate network ingress test and provide helpers for removing the default ingress network and leaving the swamr * docs: rerun website gen * test: fix reg image build and keep test * chore: add name to todo * chore: move ds network and plugin specs to file * chore: format provider test spec * chore: use simpler error message for empty strings
2021-05-31 03:11:49 -04:00
TF_LOG=INFO TF_ACC=1 go test -v ./internal/provider -timeout 60s -run ^TestAccDockerImage_data_private_config_file$
## run all test for a resource, e.g docker_container
TF_LOG=INFO TF_ACC=1 go test -v ./internal/provider -timeout 360s -run TestAccDockerContainer
2020-12-24 10:27:35 -05:00
## cleanup the local testing resources
make testacc_cleanup
```
feat/doc generation (#193) * chore: add tfplugindocs tool * feat: add tfplugin doc dependency and make target * chore: apply documentation generation * docs(contributing): update for documentation generation * fix: adapt website-lint target to new do folder * docs(network): update ds descriptions * docs: add template for index.md * docs: add network resource generation * chore(ci): updates paths for website checks * docs: add plugin data source generation * docs: add import cmd for network resource * docs: add plugin resource generation * feat: outlines remaining resources with example and import cmd * feat: add descriptions to docs * chore: add DevSkim ignores and fix capitalized errors * docs: complete ds registry image * docs: add container resource generation * docs: add lables description to missing resources * docs: remove computed:true from network data so the list is rendered in the description * Revert "docs: remove computed:true from network data" This reverts commit dce9b7a5a23dd8b4156bf6e33947225b5f719df2. * docs: add docker image descriptions to generate the docs * docs: add docker registry image descriptions to generate the docs * docs: add docker service descriptions to generate the docs * docs: add docker volume descriptions to generate the docs * docs(index): clarifies description so more docker resources are mentioned * docs(network): fixes required and read-only attributes so the ds can only be read by-name * docs(plugin): clarifies the ds docs attributes * docs: fix typo registry image ds * docs(config): clarifies attributes and enhances examples Provide a long example and import command * fix(config): make data non-sensitive Because only secrets data is * docs(containter): clarifies attributes and enhances examples with import * docs(config): fix typo * docs(image): clarifies attributes and remove import * docs(network): clarifies attributes and adapts import * docs(plugin): clarifies attributes and import * docs(registry_image): clarifies attributes and removes import * chore(secret): remove typo * docs(service): clarifies attributes and import * docs(volume): clarifies attributes and import * fix: correct md linter rules after doc gen * docs(volume): regenerated * docs: add config custom template * docs: add templates for all resources * docs(config): templates all sections and examples for better redability and structure * docs(config): fix md linter * docs(container): templates all sections and examples * docs(image): templates all sections and examples * docs(image): fix import resource by renaming * docs(network): templates all sections and examples * docs(service): templates all sections and examples * docs(volume): templates all sections and examples * fix(lint): replace website with doc directory * fix(ci): link check file extension check * fix: markdown links * chore: remove old website folder * chore: fix website-lint terrafmr dir and pattern * fix: lint fix target website folder * fix: website links * docs(provider): update examples with templates on auth and certs * docs(provider): add tf-plugin-docs line * docs(contributing): split doc generation section * docs: final brush up for readability and structure * chore(ci): add website-generation job to see if files changed and it should run locally again * chore(ci): remove explicit docker setup from website lint because it's installed by default
2021-05-21 08:30:56 -04:00
Furthermore, run the linters for the code:
```sh
# install all the dependencies
make setup
feat/doc generation (#193) * chore: add tfplugindocs tool * feat: add tfplugin doc dependency and make target * chore: apply documentation generation * docs(contributing): update for documentation generation * fix: adapt website-lint target to new do folder * docs(network): update ds descriptions * docs: add template for index.md * docs: add network resource generation * chore(ci): updates paths for website checks * docs: add plugin data source generation * docs: add import cmd for network resource * docs: add plugin resource generation * feat: outlines remaining resources with example and import cmd * feat: add descriptions to docs * chore: add DevSkim ignores and fix capitalized errors * docs: complete ds registry image * docs: add container resource generation * docs: add lables description to missing resources * docs: remove computed:true from network data so the list is rendered in the description * Revert "docs: remove computed:true from network data" This reverts commit dce9b7a5a23dd8b4156bf6e33947225b5f719df2. * docs: add docker image descriptions to generate the docs * docs: add docker registry image descriptions to generate the docs * docs: add docker service descriptions to generate the docs * docs: add docker volume descriptions to generate the docs * docs(index): clarifies description so more docker resources are mentioned * docs(network): fixes required and read-only attributes so the ds can only be read by-name * docs(plugin): clarifies the ds docs attributes * docs: fix typo registry image ds * docs(config): clarifies attributes and enhances examples Provide a long example and import command * fix(config): make data non-sensitive Because only secrets data is * docs(containter): clarifies attributes and enhances examples with import * docs(config): fix typo * docs(image): clarifies attributes and remove import * docs(network): clarifies attributes and adapts import * docs(plugin): clarifies attributes and import * docs(registry_image): clarifies attributes and removes import * chore(secret): remove typo * docs(service): clarifies attributes and import * docs(volume): clarifies attributes and import * fix: correct md linter rules after doc gen * docs(volume): regenerated * docs: add config custom template * docs: add templates for all resources * docs(config): templates all sections and examples for better redability and structure * docs(config): fix md linter * docs(container): templates all sections and examples * docs(image): templates all sections and examples * docs(image): fix import resource by renaming * docs(network): templates all sections and examples * docs(service): templates all sections and examples * docs(volume): templates all sections and examples * fix(lint): replace website with doc directory * fix(ci): link check file extension check * fix: markdown links * chore: remove old website folder * chore: fix website-lint terrafmr dir and pattern * fix: lint fix target website folder * fix: website links * docs(provider): update examples with templates on auth and certs * docs(provider): add tf-plugin-docs line * docs(contributing): split doc generation section * docs: final brush up for readability and structure * chore(ci): add website-generation job to see if files changed and it should run locally again * chore(ci): remove explicit docker setup from website lint because it's installed by default
2021-05-21 08:30:56 -04:00
# lint the go code
make golangci-lint
```
In case you need to run the GitHub actions setup locally in a docker container and run the tests there,
run the following commands:
```sh
docker build -f testacc.Dockerfile -t testacc-local .
docker run -it -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd):/test testacc-local bash
make testacc_setup
TF_LOG=DEBUG TF_ACC=1 go test -v ./internal/provider -run ^TestAccDockerContainer_nostart$
```
feat/doc generation (#193) * chore: add tfplugindocs tool * feat: add tfplugin doc dependency and make target * chore: apply documentation generation * docs(contributing): update for documentation generation * fix: adapt website-lint target to new do folder * docs(network): update ds descriptions * docs: add template for index.md * docs: add network resource generation * chore(ci): updates paths for website checks * docs: add plugin data source generation * docs: add import cmd for network resource * docs: add plugin resource generation * feat: outlines remaining resources with example and import cmd * feat: add descriptions to docs * chore: add DevSkim ignores and fix capitalized errors * docs: complete ds registry image * docs: add container resource generation * docs: add lables description to missing resources * docs: remove computed:true from network data so the list is rendered in the description * Revert "docs: remove computed:true from network data" This reverts commit dce9b7a5a23dd8b4156bf6e33947225b5f719df2. * docs: add docker image descriptions to generate the docs * docs: add docker registry image descriptions to generate the docs * docs: add docker service descriptions to generate the docs * docs: add docker volume descriptions to generate the docs * docs(index): clarifies description so more docker resources are mentioned * docs(network): fixes required and read-only attributes so the ds can only be read by-name * docs(plugin): clarifies the ds docs attributes * docs: fix typo registry image ds * docs(config): clarifies attributes and enhances examples Provide a long example and import command * fix(config): make data non-sensitive Because only secrets data is * docs(containter): clarifies attributes and enhances examples with import * docs(config): fix typo * docs(image): clarifies attributes and remove import * docs(network): clarifies attributes and adapts import * docs(plugin): clarifies attributes and import * docs(registry_image): clarifies attributes and removes import * chore(secret): remove typo * docs(service): clarifies attributes and import * docs(volume): clarifies attributes and import * fix: correct md linter rules after doc gen * docs(volume): regenerated * docs: add config custom template * docs: add templates for all resources * docs(config): templates all sections and examples for better redability and structure * docs(config): fix md linter * docs(container): templates all sections and examples * docs(image): templates all sections and examples * docs(image): fix import resource by renaming * docs(network): templates all sections and examples * docs(service): templates all sections and examples * docs(volume): templates all sections and examples * fix(lint): replace website with doc directory * fix(ci): link check file extension check * fix: markdown links * chore: remove old website folder * chore: fix website-lint terrafmr dir and pattern * fix: lint fix target website folder * fix: website links * docs(provider): update examples with templates on auth and certs * docs(provider): add tf-plugin-docs line * docs(contributing): split doc generation section * docs: final brush up for readability and structure * chore(ci): add website-generation job to see if files changed and it should run locally again * chore(ci): remove explicit docker setup from website lint because it's installed by default
2021-05-21 08:30:56 -04:00
### Update the documentation
Furthermore, run the generation and linters for the documentation:
```sh
# install all the dependencies
make setup
# generate or update the documentation
make website-generation
# lint the documentation
make website-link-check
make website-lint
# you can also use this command to fix most errors automatically
make website-lint-fix
```
The documentation is generated based on the tool [terraform-plugin-docs](https://github.com/hashicorp/terraform-plugin-docs):
- The content of the `Description` attribute is parsed of each resource
- All the templates for the resources are located in `templates`.
2020-12-24 10:27:35 -05:00
### Test against current terraform IaC descriptions
In order to extend the provider and test it with `terraform`, build the provider as mentioned above with:
```sh
# Testing in a local mirror which needs to have the following convention.
# See https://www.terraform.io/docs/commands/cli-config.html#provider-installation for details
export TESTING_MIRROR=testing-mirror/registry.terraform.io/kreuzwerker/docker/9.9.9/$(go env GOHOSTOS)_$(go env GOHOSTARCH)
mkdir -p ./$TESTING_MIRROR
# now we build into the provider into the local mirror
go build -o ./$TESTING_MIRROR/terraform-provider-docker_v9.9.9
```
Now we change into the `testing` directory (which is ignored as well) and set an explicit version of the provider we develop:
```hcl
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "9.9.9"
}
}
}
provider "docker" {
}
resource "docker_image" "foo" {
name = "nginx:latest"
keep_locally = true
}
resource "docker_container" "foo" {
name = "foo"
image = docker_image.foo.latest
}
```
2021-06-02 01:54:29 -04:00
As the next step we can init terraform by providing a local plugin directory:
2020-12-24 10:27:35 -05:00
```sh
# Which reflects the convention mentioned before
# See https://www.terraform.io/docs/commands/init.html#plugin-installation
terraform init -plugin-dir=../testing-mirror
terraform plan
terraform apply -auto-approve
```
### Developing on Windows
You can build and test on Windows without `make`. Run `go install` to
build and `Scripts\runAccTests.bat` to run the test suite.
Continuous integration for Windows is not available at the moment due
to lack of a CI provider that is free for open source projects *and*
supports running Linux containers in Docker for Windows. For example,
AppVeyor is free for open source projects and provides Docker on its
Windows builds, but only offers Linux containers on Windows as a paid
upgrade.
## Create a commit
Commit messages should be well formatted, and to make that "standardized", we
are using Conventional Commits.
You can follow the documentation on
[their website](https://www.conventionalcommits.org).
## Submit a pull request
Push your branch to your `terraform-provider-docker` fork and open a
pull request against the master branch.
2021-05-23 05:58:49 -04:00
## Releasing
Run one of the following commands (depending on the semver version you want to release):
```sh
make patch
make minor
make major
```
Those commands will automatically:
- Replace all occurrences of the latest release, e.g. `2.11.0` with the new one, e.g. `2.12.0`: ``
- Generate the `CHANGELOG.md`
- Regenerate the website (`make website-generation`)