DNA¶
Initialization¶
When an instance is created for the first time, it is initialized by
creating a .dna
folder in the current working directory. An nginx
mapping is added to include configs in .dna/nginx
, a socat container
is created to proxy requests made to services managed by this DNA instance
(the containers are connected via an internal bridge network), and a
SQLite
database is created inside .dna
.
dna.DNA
¶
-
class
dna.
DNA
(service_name, default=None, cb_args=[])[source]¶ This is the main DNA class, which does all the heavy lifting
- Parameters
service_name (str) – the name of this DNA instance (up to you)
default (str) – the default domain this DNA instance runs on (used by
nginx
)cb_args (list[str]) – additional arguments to be used whenever
certbot
is called
-
set_print
(func)[source]¶ Set the print function to
func
- Parameters
func (func) – a print-like function
-
pull_image
(image, tag=None, stream=False)[source]¶ Pull and save a Docker image by name or URL
- Parameters
image (str) – the name or url of the image to pull
tag (str) – the initial tag to assign to the image (defaults to
None
, which assigns that taglatest
)stream (bool) – flag to yield pull output (defaults to
False
)
-
build_image
(stream=False, **options)[source]¶ Build a Docker image using the given options
- Parameters
stream (bool) – flag to yield build output (defaults to
False
)options (kwargs) – options to use to the build the image (ideally contains at least a path to a build context, as well as a Dockerfile)
-
run_deploy
(service, image, port, **docker_options)[source]¶ Deploys a service to a container, binds that container port to socat, saves the service in the database, and re-propagates the services in this DNA instance.
- Parameters
service (str) – the name of the service
image (str) – the name of the Docker image containing this service
port (str) – the port inside the container that the service front-end runs on
docker_options (kwargs) – other options to pass to docker on deploy
-
propagate_services
()[source]¶ Populates
self.services
with the services managed by this DNA instanceFor the names of all the docker containers connected to this service’s socat bridge, calls
get_service_info()
.Warning
If a service was deployed using DNA but the socat bridge does not yield it (the container is off or was deleted), the service will not be propagated.
-
get_service_info
(service)[source]¶ Gets the requested service
- Parameters
service (str) – the name of the service to find
- Returns
a
Service
object representing the requested service
-
start_service
(service)[source]¶ Start the requested service, if it is stopped
- Parameters
service (str) – the name of the service to start
- Returns
whether the service was started successfully
-
add_domain
(service, domain, force_wildcard=False, force_provision=False, proxy_set_header={})[source]¶ Proxy
domain
toservice
, if it is not already bound to another service- Parameters
service (str) – the name of the service
domain (str) – the url to proxy to the service front-end
force_wildcard (bool) – forcibly use a wildcard SSL certificate only (defaults to
False
)force_provision (bool) – forcibly provision a certificate even if another match exists (defaults to
False
)proxy_set_header (dict) – a dictionary of proxy headers to pass into nginx
Important
If
force_wildcard
andforce_provision
are bothTrue
, then a certificate will be provisioned fordomain
as well as*.domain
-
remove_domain
(service, domain)[source]¶ Remove
domain
fromservice
, if it is bound to it- Parameters
service (str) – the name of the service
domain (str) – the url to unbind from the service
Note
Relevant
nginx
configs will be deleted, but notcertbot
certificates.
-
stop_service
(service)[source]¶ Stop the requested service, if it is not stopped
- Parameters
service (str) – the name of the service to stop
- Returns
whether the service was stopped successfully
-
delete_service
(service)[source]¶ Unproxy all domains attached to
service
, unbindservice
from socat, stop and delete theservice
’s Docker container, and remove it from the database.- Parameters
service (str) – the name of the service
-
docker_logs
(service)[source]¶ Get the docker logs for
service
- Parameters
service (str) – the name of the service
- Returns
a string of log messages
-
nginx_logs
(service, error=False)[source]¶ Get the nginx logs for
service
- Parameters
service (str) – the name of the service
error (bool) – return the nginx error logs instead of access (defaults to
False
)
- Returns
a string of log messages