-
Notifications
You must be signed in to change notification settings - Fork 0
Add acme-buddy support #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
a5ea73f
Add acme function]
weshinsley 7ff2388
More acme
weshinsley 8ba5966
Whitespace
weshinsley 67204fe
Config and test
weshinsley f8a58ed
Lint
weshinsley 85111a1
More lint
weshinsley 759e94e
Fix list syntax
weshinsley 135d953
Better coverage
weshinsley 92c55c5
Disable one qa check
weshinsley 98b6b1f
Test acme_env
weshinsley 2fff464
Annoying cov
weshinsley dc45e52
Annoying cov
weshinsley fc3f152
Space
weshinsley 6ee8102
Test acme args
weshinsley 74f1f46
Cleanup
weshinsley 2442031
More lint
weshinsley d129546
Replace disable check
weshinsley 0453142
Remove?
weshinsley d474705
Fix current tests
weshinsley 55922fb
Take env instead of repopulating it
weshinsley 740ba31
lint
weshinsley c4fac8b
Better interface
weshinsley acaa73c
Path for config
weshinsley 4c3c523
Use list for path
weshinsley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,66 @@ | ||
| import os | ||
|
|
||
| import constellation | ||
| from constellation.config import ( | ||
| config_dict, | ||
| config_integer, | ||
| config_list, | ||
| config_string, | ||
| ) | ||
|
|
||
|
|
||
| class AcmeBuddyConfig: | ||
| def __init__(self, data, path: list[str]): | ||
| name = config_string(data, [*path, "image", "name"]) | ||
| repo = config_string(data, [*path, "image", "repo"]) | ||
| tag = config_string(data, [*path, "image", "tag"]) | ||
| self.ref = constellation.ImageReference(repo, name, tag) | ||
| self.port = config_integer(data, [*path, "port"]) | ||
| self.dns_provider = config_string(data, [*path, "dns_provider"]) | ||
| self.env = config_dict(data, [*path, "env"]) | ||
| if "ACME_BUDDY_STAGING" in os.environ: | ||
| self.env["ACME_BUDDY_STAGING"] = os.environ["ACME_BUDDY_STAGING"] | ||
| self.email = config_string(data, [*path, "email"]) | ||
| if "additional_domains" in config_dict(data, path): | ||
| self.additional_domains = config_list( | ||
| data, [*path, "additional_domains"] | ||
| ) | ||
|
|
||
|
|
||
| def acme_buddy_container( | ||
| cfg: AcmeBuddyConfig, name: str, proxy: str, volume: str, hostname: str | ||
| ) -> constellation.ConstellationContainer: | ||
| acme_mounts = [ | ||
| constellation.ConstellationVolumeMount(volume, "/tls"), | ||
| constellation.ConstellationBindMount( | ||
| "/var/run/docker.sock", | ||
| "/var/run/docker.sock", | ||
| ), | ||
| ] | ||
|
|
||
| domain_names = ",".join((hostname, *cfg.additional_domains)) | ||
|
|
||
| acme = constellation.ConstellationContainer( | ||
| name, | ||
| cfg.ref, | ||
| ports=[cfg.port], | ||
| mounts=acme_mounts, | ||
| environment=cfg.env, | ||
| args=[ | ||
| "--domain", | ||
| domain_names, | ||
| "--email", | ||
| cfg.email, | ||
| "--dns-provider", | ||
| cfg.dns_provider, | ||
| "--certificate-path", | ||
| "/tls/certificate.pem", | ||
| "--key-path", | ||
| "/tls/key.pem", | ||
| "--account-path", | ||
| "/tls/account.json", | ||
| "--reload-container", | ||
| proxy, | ||
| ], | ||
| ) | ||
| return acme | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,102 @@ | ||
| import types | ||
|
|
||
| from constellation.acme import acme_buddy_container | ||
| from constellation.config import config_acme | ||
|
|
||
|
|
||
| def test_acme_buddy_config_hdb(): | ||
| data = { | ||
| "acme_buddy": { | ||
| "email": "[email protected]", | ||
| "image": { | ||
| "repo": "ghcr.io/reside-ic", | ||
| "name": "acme-buddy", | ||
| "tag": "main", | ||
| }, | ||
| "port": 2112, | ||
| "dns_provider": "hdb", | ||
| "env": { | ||
| "HDB_ACME_USERNAME": "testuser", | ||
| "HDB_ACME_PASSWORD": "testpw", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| cfg = config_acme(data, "acme_buddy") | ||
| assert cfg.email == "[email protected]" | ||
| assert cfg.dns_provider == "hdb" | ||
| assert cfg.ref.repo == "ghcr.io/reside-ic" | ||
| assert cfg.ref.name == "acme-buddy" | ||
| assert cfg.ref.tag == "main" | ||
| assert cfg.port == 2112 | ||
| assert cfg.env["HDB_ACME_USERNAME"] == "testuser" | ||
| assert cfg.env["HDB_ACME_PASSWORD"] == "testpw" | ||
|
|
||
|
|
||
| def test_acme_buddy_config_cloudflare(monkeypatch): | ||
| monkeypatch.setenv("ACME_BUDDY_STAGING", "0") | ||
| data = { | ||
| "acme_buddy": { | ||
| "additional_domains": ["anotherhost.com"], | ||
| "email": "[email protected]", | ||
| "image": { | ||
| "repo": "ghcr.io/reside-ic", | ||
| "name": "acme-buddy", | ||
| "tag": "main", | ||
| }, | ||
| "port": 2112, | ||
| "dns_provider": "cloudflare", | ||
| "env": { | ||
| "CLOUDFLARE_DNS_API_TOKEN": "abcdefgh12345678", | ||
| }, | ||
| }, | ||
| } | ||
| cfg = config_acme(data, "acme_buddy") | ||
| assert cfg.email == "[email protected]" | ||
| assert cfg.dns_provider == "cloudflare" | ||
| assert cfg.ref.repo == "ghcr.io/reside-ic" | ||
| assert cfg.ref.name == "acme-buddy" | ||
| assert cfg.ref.tag == "main" | ||
| assert cfg.port == 2112 | ||
| assert cfg.additional_domains == ["anotherhost.com"] | ||
| assert cfg.env["CLOUDFLARE_DNS_API_TOKEN"] == "abcdefgh12345678" | ||
| assert cfg.env["ACME_BUDDY_STAGING"] == "0" | ||
|
|
||
|
|
||
| def test_acme_buddy_container(): | ||
| cfg = types.SimpleNamespace() | ||
| cfg.containers = {"acme-buddy": "acme-buddy"} | ||
| cfg.container_prefix = "prefix" | ||
| cfg.hostname = "example.com" | ||
| cfg.acme_buddy = types.SimpleNamespace( | ||
| dns_provider="cloudflare", | ||
| env={ | ||
| "CLOUDFLARE_DNS_API_TOKEN": "abcdefgh12345678", | ||
| "ACME_BUDDY_STAGING": "0", | ||
| }, | ||
| ref="ghcr.io/reside-ic/acme-buddy:main", | ||
| port=2112, | ||
| email="[email protected]", | ||
| additional_domains=["www.example.com"], | ||
| ) | ||
|
|
||
| proxy = types.SimpleNamespace() | ||
| proxy.name_external = lambda prefix: f"{prefix}-proxy" | ||
| tls_volume = "tls-volume" | ||
| acme = acme_buddy_container( | ||
| cfg.acme_buddy, | ||
| cfg.containers["acme-buddy"], | ||
| proxy.name_external(cfg.container_prefix), | ||
| tls_volume, | ||
| cfg.hostname, | ||
| ) | ||
|
|
||
| assert acme.environment["ACME_BUDDY_STAGING"] == "0" | ||
| assert acme.environment["CLOUDFLARE_DNS_API_TOKEN"] == "abcdefgh12345678" | ||
| assert acme.args[0] == "--domain" | ||
| assert acme.args[1] == "example.com,www.example.com" | ||
| assert acme.args[2] == "--email" | ||
| assert acme.args[3] == "[email protected]" | ||
| assert acme.args[4] == "--dns-provider" | ||
| assert acme.args[5] == "cloudflare" | ||
| assert acme.args[-1] == "prefix-proxy" |
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this an env var and not a config value? Is the idea that this allows you to test "real" configs with a fake acme buddy set up?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question - in acme buddy, either the
--stagingflag or existence of a non-emptyACME_BUDDY_STAGINGenvironment var achieve the same purpose - perhaps in constellation I should accept it as optional in both the config, and the environment...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I treat the
envpart of the config as a block, whatever it contains, soACME_BUDDY_STAGINGcan be passed in asacme_buddy: env: ACME_BUDDY_STAGING. If the environment variable is present, then that overwrites the config, which is I think the right way round.