Skip to content

Commit

Permalink
Refactor code structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
gjbae1212 committed Jul 24, 2020
1 parent 4fe0a3f commit 01196d8
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 10 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ test
assets
coverage.txt
local_env.sh
cloud-instance-dns
dist
cmd/dns/dist
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ In addition it could be searching private or public ip.
## Getting Started
### quickstart
```bash
$ bash local.sh build
$ cloud-instance-dns -c your-config.yaml

# Mac
$ ./dist/dns-darwin -c config.yaml

# Linux
$ ./dist/dns-linux -c config.yaml
```

### config(yaml)
Expand Down Expand Up @@ -124,7 +128,7 @@ You will search to dns records following rule patterns below, Assume having `hel

### install
```bash
# your-machine(mac ... and so on)
# your-machine
$ bash local.sh build
# linux
Expand Down
7 changes: 6 additions & 1 deletion .goreleaser.yml → cmd/dns/.goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ builds:
- linux
goarch:
- amd64
- 386
asmflags:
- all=-trimpath={{.Env.GOPATH}}
gcflags:
- all=-trimpath={{.Env.GOPATH}}
ldflags:
- -s -w
archives:
- replacements:
darwin: Darwin
Expand Down
24 changes: 24 additions & 0 deletions cmd/dns/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
MIT License
-----------

Copyright (c) 2019 gjbae1212@gmail.com
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.
171 changes: 171 additions & 0 deletions cmd/dns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# cloud-instance-dns

<p align="left">
<a href="https://circleci.com/gh/gjbae1212/cloud-instance-dns"><img src="https://circleci.com/gh/gjbae1212/cloud-instance-dns.svg?style=svg"></a>
<a href="https://hits.seeyoufarm.com"/><img src="https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fgjbae1212%2Fcloud-instance-dns"/></a>
<a href="/LICENSE"><img src="https://img.shields.io/badge/license-MIT-GREEN.svg" alt="license" /></a>
<a href="https://goreportcard.com/report/github.com/gjbae1212/cloud-instance-dns"><img src="https://goreportcard.com/badge/github.com/gjbae1212/cloud-instance-dns" alt="Go Report Card" /></a>
</p>

## OVERVIEW
**cloud-instance-dns** is DNS server that will look up public or private ip on AWS ec2 or GCP compute-engine.
**cloud-instance-dns** is supporting to search multi regions(zones) instances on clouds(AWS,GCP).
In addition it could be searching private or public ip.

## Getting Started
### quickstart
```bash

# Mac
$ ./dist/dns-darwin -c config.yaml

# Linux
$ ./dist/dns-linux -c config.yaml
```

### config(yaml)

------

#### spec
```yaml
domain: DNS domain # EX) localhost, dns.example.com, hello.example.com ...
nameserver: public domain for server running on`cloud-instance-dns` # server public domain(never ip) running `cloud-instance-dns`
port: port number
email: your email
prviate: false or true # if you'd like to answer private-ip -> true, but public-ip -> false
aws:
enable: true or false # if your'd use to aws -> true, but not -> false
access_key: your-aws-access-key
secret_access_key: your-aws-secret-access-key
regions:
- your-aws-region-1
- your-aws-region-2
gcp:
enable: true or false # if your'd use to gcp -> true, but not -> false
project_id: your-gcp-project-id
zones:
- your-gcp-zone-1
- your-gcp-zone-2
jwt: your-gcp-jwt-string
```
------
#### config example
- using AWS and GCP
```yaml
domain: hello.example.com
nameserver: ec2-1.1.1.1.region.compute.amazonaws.com
port: 53
email: gjbae1212@gmail.com
prviate: true
aws:
enable: true
access_key: blahblah
secret_access_key: blahblah
regions:
- ap-northeast-1
- ap-northeast-2
gcp:
enable: true
project_id: gcp-project-id
zones:
- asia-northeast1-a
- asia-northeast1-b
jwt: '{
blahblah
}'
```
- only AWS
```
domain: hello.example.com
nameserver: ec2-1.1.1.1.region.compute.amazonaws.com
port: 53
email: gjbae1212@gmail.com
prviate: true
aws:
enable: true
access_key: blahblah
secret_access_key: blahblah
regions:
- ap-northeast-1
- ap-northeast-2
gcp:
enable: false
```
- only GCP
```
domain: hello.example.com
nameserver: ec2-1.1.1.1.region.compute.amazonaws.com
port: 53
email: gjbae1212@gmail.com
prviate: true
aws:
enable: false
gcp:
enable: true
project_id: gcp-project-id
zones:
- asia-northeast1-a
- asia-northeast1-b
jwt: '{
blahblah
}'
```
------
### usage
You will search to dns records following rule patterns below, Assume having `hello.example.com` dns

- `(name or instacne-id).hello.example.com` will return instances matching name regardless cloud infra.
- `(num).(name or instacne-id).hello.example.com` will return a instance matching name and number.
- `(name or instacne-id).aws.hello.example.com` will return instances matching name at aws.
- `(num).(name or instacne-id).aws.hello.example.com` will return a instance matching name and number at aws.
- `(name or instacne-id).gcp.hello.example.com` will return instances matching name at gcp.
- `(num).(name or instacne-id).gcp.hello.example.com` will return a instance matching name and number at gcp.
- `(name or instacne-id).rr.hello.example.com` will return instances matching name with dns round robin.

### install
```bash
# your-machine
$ bash local.sh build
# linux
$ bash local.sh linux_build
# download
go to `https://github.com/gjbae1212/cloud-instance-dns/releases`

# homebrew
$ brew tap gjbae1212/cloud-instance-dns
$ brew install cloud-instance-dns
```

## Explanation
If you would be setup to **cloud-instance-dns**, Be several attention.

### AWS
- aws.enable of config.yaml should be true when you'd like to use.
- a aws_key must have permission to access ec2(ec2:DescribeInstances).
- ingress port running **cloud-instance-dns** must open(port of config.yaml).

### GCP
- gcp.enable of config.yaml should be true when you'd like to use.
- a gcp-jwt must have permission to access compute-engine(Compute Viewer).
- ingress port running **cloud-instance-dns** must open(port of config.yaml).

### Configure NS Record
If your **cloud-instance-dns** will register global DNS, you must input NS record from your domain.
Assume having `example.com` domain and you are running **cloud-instance-dns** on instance(assume public domain `ec2-1.1.1.1.region.compute.amazonaws.com`<must not be a IP>).
And then you will make `hello.example.com.` DNS.
```bash
# DNS Domain(domain in your yaml) #TTL # public hostname(nameserver in your yaml)
hello.example.com. 300 IN NS ec2-1.1.1.1.region.compute.amazonaws.com
```
NS record value must not be a IP. It is public domain or hostname<could dns resolve>.

### Test
- dig (name).hello.example.com @localhost --> using localhost dns.
- dig (name).hello.example.com @ec2-1.1.1.1.region.compute.amazonaws.com --> check A record using your public dns.
- dig NS hello.example.com --> check NS record using your public dns.
3 changes: 1 addition & 2 deletions main.go → cmd/dns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package main

import (
"flag"
"path/filepath"

"log"
"path/filepath"

"github.com/gjbae1212/cloud-instance-dns/server"
)
Expand Down
Binary file added dist/dns-darwin
Binary file not shown.
Binary file added dist/dns-linux
Binary file not shown.
7 changes: 5 additions & 2 deletions local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ function setenv

function build
{
go build
cd $CURRENT/cmd/dns
go build -trimpath -ldflags='-s -w' -o $CURRENT/dist/dns-darwin
}

function linux_build
{
GOOS=linux GOARCH=amd64 go build -o dist/cloud-instance-dns
cd $CURRENT/cmd/dns
GOOS=linux GOARCH=amd64 go build -trimpath -ldflags='-s -w' -o $CURRENT/dist/dns-linux
}

function release
{
# export GITHUB_TOKEN=blahblah
# before --> git tag -a 'version' -m ''
cd $CURRENT/cmd/dns
goreleaser release --rm-dist
}

Expand Down

0 comments on commit 01196d8

Please sign in to comment.