-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
287 additions
and
155 deletions.
There are no files selected for viewing
This file contains 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,21 @@ | ||
name: Publish to NPM | ||
on: | ||
release: | ||
types: [created] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Setup Node | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '18.x' | ||
registry-url: 'https://registry.npmjs.org' | ||
- name: Install dependencies and build 🔧 | ||
run: npm ci && npm run build | ||
- name: Publish package on NPM 📦 | ||
run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains 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 |
---|---|---|
@@ -1,28 +1,105 @@ | ||
### Cloudflare Domains Manager | ||
|
||
Inside the `configuration.yaml` file there is the mapping of every DNS record used in this repo.<br/> | ||
This tool is helpful to manage cloudflare domains using a versionate file.<br/> | ||
|
||
For use the script just run under the domains folder: | ||
## How to use? | ||
|
||
Create a folder for your new project: | ||
``` | ||
npm install | ||
npm run update | ||
``` | ||
Note:<br/> | ||
This script works only with domains managed by cloudflare.<br/> | ||
You have to create a `.env` file with Cloudflare credentials inside `domains` folder.<br/> | ||
In the configuration, `ttl=1` is the automatic ttl provided by cloudflare.<br/> | ||
In the configuration, `proxied=true` means the record will be proxed by cloudflare system.<br/> | ||
In the configuration, `deleted=true` means the record will be delete from cloudflare. Use it only when you need to delete a dns record. You can remove the dns from the yaml after the deletion.<br/> | ||
Please use load balancers mapping instead of explicit value in DNS records.<br/> | ||
If you have created a new domain in cloudflare you can run this command to get the mandatory zone_id for the configuration file: | ||
mkdir test-domains | ||
cd test-domains | ||
``` | ||
|
||
Create a new node app: | ||
``` | ||
npm init | ||
``` | ||
|
||
Install this package: | ||
``` | ||
npm i cloudflare-domains-manager | ||
``` | ||
|
||
Create a index.js with this content: | ||
``` | ||
const CloudflareDomainsManager = require ('cloudflare-domains-manager') | ||
const cdm = new CloudflareDomainsManager(); | ||
cdm.run(); | ||
``` | ||
|
||
Create a .env file with your clouflare data: | ||
``` | ||
CF_EMAIL=(your cloudflare email) | ||
CF_KEY= (your cloudflare token) | ||
``` | ||
node index.js action=list | ||
you can generate your cloudflare token here: https://dash.cloudflare.com/profile/api-tokens | ||
|
||
|
||
Edit the package.json adding these lines: | ||
``` | ||
"main": "index.js", | ||
"scripts": { | ||
"update": "node index.js action=update", | ||
"list": "node index.js action=list" | ||
} | ||
``` | ||
|
||
install the dependencies: | ||
``` | ||
npm install | ||
``` | ||
if you want to update a single domain instead of all, just add it as a parameter: | ||
|
||
you can now get a list of your domains with: | ||
``` | ||
npm run update uala.it | ||
npm run list | ||
``` | ||
Dry run mode is supported, just add it as a parameter: | ||
|
||
## The configuration file | ||
|
||
if it works, you can now create your `configuration.yaml` file starting with something like: | ||
``` | ||
npm run update uala.it --dry-run | ||
load_balancers: | ||
- example-lb: &example-lb example-lb.your-infrastructure.com | ||
- example-lb-ip: &example-lb-ip 172.0.0.10 | ||
domains: | ||
- name: example.com | ||
zone_id: Y0UR_Z0N3_1D | ||
dns_records: | ||
- name: example.com | ||
type: CNAME | ||
content: *example-lb | ||
ttl: 1 | ||
proxied: true | ||
- name: test.example.com | ||
type: A | ||
content: *example-lb-ip | ||
ttl: 1 | ||
proxied: true | ||
- name: www.example.com | ||
type: CNAME | ||
content: *example-lb | ||
ttl: 1 | ||
proxied: true | ||
- name: tobedeleted.example.com | ||
type: CNAME | ||
deleted: true | ||
content: *example-lb | ||
ttl: 1 | ||
proxied: true | ||
``` | ||
|
||
In the configuration: | ||
- `ttl=1` is the automatic ttl provided by cloudflare.<br/> | ||
- `proxied=true` means the record will be proxed by cloudflare system.<br/> | ||
- `deleted=true` means the record will be delete from cloudflare. Use it only when you need to delete a dns record. You can remove the dns from the yaml after the deletion.<br/> | ||
|
||
Please use load balancers mapping instead of explicit value in DNS records.<br/> | ||
|
||
|
||
## Commands list | ||
|
||
- `npm run list`: Get the list of all your domains in cloudflare | ||
- `npm run update`: Update all your cloudflare domains with the content of `configuration.yaml`. Domains that don't exist in the file will be ignored | ||
- `npm run update example.com`: Update only the domain `example.com` | ||
- `npm run update example.com --dry-run`: Update the domain `example.com` in dry-run mode (nothing will change in cloudflare) |
This file contains 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,28 @@ | ||
load_balancers: | ||
- example-lb: &example-lb example-lb.your-infrastructure.com | ||
- example-lb-ip: &example-lb-ip 172.0.0.10 | ||
domains: | ||
- name: example.com | ||
zone_id: Y0UR_Z0N3_1D | ||
dns_records: | ||
- name: example.com | ||
type: CNAME | ||
content: *example-lb | ||
ttl: 1 | ||
proxied: true | ||
- name: test.example.com | ||
type: A | ||
content: *example-lb-ip | ||
ttl: 1 | ||
proxied: true | ||
- name: www.example.com | ||
type: CNAME | ||
content: *example-lb | ||
ttl: 1 | ||
proxied: true | ||
- name: tobedeleted.example.com | ||
type: CNAME | ||
deleted: true | ||
content: *example-lb | ||
ttl: 1 | ||
proxied: true |
This file contains 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
Oops, something went wrong.