first commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
1283
Cargo.lock
generated
Normal file
1283
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "cdd"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bollard = "0.19.4"
|
||||
tokio = "1.48.0"
|
||||
8
LICENSE
Normal file
8
LICENSE
Normal file
@@ -0,0 +1,8 @@
|
||||
Copyright © 2024-2025 RamiusLr
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
68
README.md
Normal file
68
README.md
Normal file
@@ -0,0 +1,68 @@
|
||||
cdd
|
||||
===
|
||||
|
||||
This is a tool to automate subdomain (record) creation at *Cloudflare DNS*,
|
||||
based on *Docker* labels.
|
||||
|
||||
`cdd` means *Cloudflare DNS for Docker*.
|
||||
|
||||
# Installation
|
||||
You just have to run the provided *Docker* image, and give it access to the
|
||||
*Docker* socket.
|
||||
|
||||
You can use the suggested `compose.yaml` here:
|
||||
```yaml
|
||||
services:
|
||||
cdd:
|
||||
container_name: cdd
|
||||
image: ramiuslr/cdd:latest # or build: . for dev setup
|
||||
environment:
|
||||
CLOUDFLARE_TOKEN: <your_token>
|
||||
CLOUDFLARE_ZONE: example.com
|
||||
CNAME: srv.example.com # a cname pointing to your server
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||
```
|
||||
|
||||
Or you can just download it from the releases, and execute it as a standalone
|
||||
binary. Feel free to create a custom rc or system script to declare it as a
|
||||
service.
|
||||
|
||||
# Usage
|
||||
Look at the example below:
|
||||
```yaml
|
||||
services:
|
||||
nginx:
|
||||
container_name: nginx
|
||||
restart: unless-stopped
|
||||
image: nginx
|
||||
labels:
|
||||
cloudflare.enable: true
|
||||
cloudflare.fqdn: "subdomain.example.com"
|
||||
cloudflare.proxied: true
|
||||
```
|
||||
|
||||
# How does it work ?
|
||||
At first start `cdd` scans every running container know by the docker daemon.
|
||||
For every properly labeled container, it checks if the A and AAAA records exist
|
||||
and are properly pointing to the CNAME defined in its environment.
|
||||
|
||||
Then it monitors every start event, each triggering a check, and record creation
|
||||
if necessary.
|
||||
|
||||
It also monitors container destruction, which triggers a timer (duration set via
|
||||
env variable) before it deletes the associated record. This timer mechanism is
|
||||
implemented to avoid deletion / recreation when a container restarts.
|
||||
|
||||
# Project status
|
||||
This is a pre-alpha software. Not all the functionnalities are implemented yet,
|
||||
you should not use this in production.
|
||||
|
||||
# Contributing
|
||||
Contributions are very welcome, feel free to open issues or pull requests.
|
||||
|
||||
# License
|
||||
This project is released under the MIT license.
|
||||
```console
|
||||
MIT License Copyright (c) 2024-2025 ramiuslr
|
||||
```
|
||||
32
src/main.rs
Normal file
32
src/main.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use bollard::Docker;
|
||||
use bollard::query_parameters::ListContainersOptionsBuilder;
|
||||
use tokio::runtime::Builder;
|
||||
|
||||
struct ContainerConfig {
|
||||
id: String,
|
||||
fqdn: String,
|
||||
proxied: bool,
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let rt = Builder::new_current_thread().enable_all().build()?;
|
||||
let docker = Docker::connect_with_socket_defaults()?;
|
||||
rt.block_on(list_containers(&docker))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn list_containers(docker: &Docker) -> Result<(), bollard::errors::Error> {
|
||||
let options = ListContainersOptionsBuilder::new().size(true).build();
|
||||
|
||||
let containers = docker.list_containers(Some(options)).await?;
|
||||
|
||||
for c in containers {
|
||||
for (key, value) in c.labels.as_ref().into_iter() {
|
||||
println!("{}", key);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user