Skip to content

Commit

Permalink
docs: add install and usage
Browse files Browse the repository at this point in the history
  • Loading branch information
grishy committed Jul 27, 2023
1 parent 8180647 commit d432969
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 7 deletions.
74 changes: 68 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,88 @@
<img src="./docs/logo_x2.png" alt="Appsmith Logo" width="350">
<img src="./docs/logo_x3.png" width="350">

![GitHub tag (with filter)](https://img.shields.io/github/v/tag/grishy/go-avahi-cname)
[![Go Report Card](https://goreportcard.com/badge/github.com/grishy/go-avahi-cname)](https://goreportcard.com/report/github.com/grishy/go-avahi-cname)
![Build Status](https://github.com/grishy/go-avahi-cname/actions/workflows/release.yml/badge.svg)

## About
## About go-avahi-cname

This project publishe CNAME records pointing to the local host over multicast DNS using the **Avahi** daemon found in all major Linux distributions.
Since Avahi is compatible with Apple's Bonjour, these names are usable from MacOS X and Windows too.

### Goals

- ✅ No dependencies
- ✅ Small footprint, less than 3MB binary
- ✅ Support x86_64 and ARM
- ✅ Release binaries and containers

### Architecture

![Architecture](./docs/arch.excalidraw.svg)

## Install and usage
## Usege and installation

All CNAMEs are specified as program arguments, no length limit.
You can use either just the name (`name1`), which will create a record as a subdomain for the current machine, or you can write the full FQDN (`name1.hostname.local.` domain with a dot on the end) format.

Example output on machine with hostname `lab`:

```plain
> ./go-avahi-cname git photo.local. example.lab.local.
2023/07/27 08:37:14 Creating publisher
2023/07/27 08:37:14 Formating CNAMEs:
2023/07/27 08:37:14 > 'git.lab.local.' (added current FQDN)
2023/07/27 08:37:14 > 'photo.local.'
2023/07/27 08:37:14 > 'example.lab.local.'
2023/07/27 08:37:14 Publishing every 5m0s and CNAME TTL=600s.
^C
2023/07/27 08:37:16 Closing publisher...
```

### Installation

#### Binary

Binary files can be taken as artifacts for [the Release](https://github.com/grishy/go-avahi-cname/releases). In this case, it would be better to create a systemd service.

#### Container

The images for each version are in [the Packages section](https://github.com/grishy/go-avahi-cname/pkgs/container/go-avahi-cname).
You need to provide the `/var/run/dbus/system_bus_socket` file to the container to be able to communicate with the host's Avahi daemon.

One-liner to run the container `v0.3.1`:

```bash
$ ./go-avahi-cname git.hostname.local [drone.hostname.local] [photo.hostname.local] [code.hostname.local]
> docker run --restart=unless-stopped -d -v /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket ghcr.io/grishy/go-avahi-cname:v0.3.1 name1 name2.lab.local.
5a19790e06cca93016af6651d7af4046c24095a6909ace2fe26c3451fb98ceee

> docker logs 5a19790e06cca93016af6651d7af4046c24095a6909ace2fe26c3451fb98ceee
2023/07/27 08:49:02 Creating publisher
2023/07/27 08:49:02 Formating CNAMEs:
2023/07/27 08:49:02 > 'name1.lab.local.' (added current FQDN)
2023/07/27 08:49:02 > 'name2.lab.local.'
2023/07/27 08:49:02 Publishing every 5m0s ans CNAME TTL=600s.
```

Ansible task to run the container:

```yaml
- name: go-avahi-cname | Start container
community.docker.docker_container:
name: "go-avahi-cname"
image: "ghcr.io/grishy/go-avahi-cname:v0.3.1"
restart_policy: unless-stopped
volumes:
- "/var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket" # access to avahi-daemon
command: "name1 name2 git"
```
## Source of inspiration
- https://gist.github.com/gdamjan/3168336
- https://web.archive.org/web/20151016190620/http://www.avahi.org/wiki/Examples/PythonPublishAlias
- https://pypi.org/project/mdns-publisher/
## License
Copyright © 2022 [Sergei G.](https://github.com/grishy).
Copyright © 2022 [Sergei G.](https://github.com/grishy)
This project is [MIT](./LICENSE) licensed.
File renamed without changes
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"fmt"
"log"
"os"
"os/signal"
Expand All @@ -11,7 +12,7 @@ import (
"github.com/miekg/dns"
)

const TTL = uint32(60 * 10) // in seconds
const TTL = uint32(10 * 60) // in seconds

func formatCname(hostnameFqdn string, cnames []string) []string {
log.Println("Formating CNAMEs:")
Expand Down Expand Up @@ -47,6 +48,7 @@ func publishing(ctx context.Context, publisher *publisher.Publisher, cnames []st
log.Fatalf("can't publish CNAMEs: %v", err)
}
case <-ctx.Done():
fmt.Println()
log.Println("Closing publisher...")
if err := publisher.Close(); err != nil {
log.Fatalf("Can't close publisher: %v", err)
Expand Down

0 comments on commit d432969

Please sign in to comment.