Skip to content

Commit

Permalink
Merge branch 'master' into multi-domains
Browse files Browse the repository at this point in the history
  • Loading branch information
realshaunoneill committed Mar 19, 2024
2 parents fab70c4 + c7f7da3 commit b9682ed
Show file tree
Hide file tree
Showing 13 changed files with 3,213 additions and 310 deletions.
23 changes: 23 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { resolve } = require('node:path');

const project = resolve(__dirname, 'tsconfig.json');

module.exports = {
root: true,
extends: [require.resolve('@realshaunoneill/style-guide/eslint/node')],
parserOptions: {
project,
},
ignorePatterns: ['.eslintrc.js'],
settings: {
'import/resolver': {
typescript: {
project,
},
},
},
rules: {
'no-console': 'off',
'operator-linebreak': 'off',
},
};
24 changes: 24 additions & 0 deletions .github/composite-actions/install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 'Install'
description: 'Sets up Node, and installs dependencies'

inputs:
fetch-depth:
default: '1'
required: false
persist-credentials:
default: true
required: false

runs:
using: composite
steps:
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies
shell: bash
run: |
corepack enable
npm install --include dev
14 changes: 5 additions & 9 deletions .github/workflows/docker-image-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@ name: Docker Image CI

on:
push:
branches: [ "master" ]
branches: ['master']

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Set up QEMU
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to Docker Hub
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
- name: Build and push
uses: docker/build-push-action@v4
with:
push: true
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Quality

on:
pull_request:
push:
branches:
- 'canary'
- 'main'
- '*'

jobs:
eslint:
name: 'ESLint'
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3

- name: Install
uses: ./.github/composite-actions/install

- name: Run ESLint check
run: npm run lint
2 changes: 1 addition & 1 deletion .github/workflows/version-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
- uses: actions/checkout@v2
# Bump version on merging Pull Requests with specific labels.
# (bump:major,bump:minor,bump:patch)
- uses: haya14busa/action-bumpr@v1
- uses: haya14busa/action-bumpr@v1
36 changes: 27 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
# Cloudflare DDNS Service :cloud: :arrows_counterclockwise:

[![Github Source](https://img.shields.io/badge/source-github-orange)](https://github.com/realshaunoneill/cloudflare-ddns)
[![Docker Image Size](https://img.shields.io/docker/image-size/realshaunoneill/cloudflare-ddns/latest)](https://hub.docker.com/r/realshaunoneill/cloudflare-ddns)
[![DockerHub Pulls](https://img.shields.io/docker/pulls/realshaunoneill/cloudflare-ddns)](https://hub.docker.com/r/realshaunoneill/cloudflare-ddns 'DockerHub pulls')

A Node.js-based Dynamic DNS (DDNS) service using Cloudflare as the DNS provider. This service automatically updates the IP address of a chosen domain with the current IP address of the machine running the service.

## Features :sparkles:

- Automatic IP address update with Cloudflare
- Configurable interval (using cron) for IP address checks and updates
- Simple setup and configuration
- The Docker image is small and efficient.
- Wildcard domains (*.example.org) are also supported.
- Wildcard domains (\*.example.org) are also supported.
- Supports all platforms.
- This service pulls the IP address from the [Cloudflare API](https://one.one.one.one/cdn-cgi/trace) instead of using a third-party service.

## Prerequisites :clipboard:

To use this service, you need to have either Node.js or Docker installed on your machine.

- A Cloudflare account with a domain name already set up and configured on Cloudflare.
- A Cloudflare API key with the following permissions:
- Zone:Zone:Read
- Zone:DNS:Edit


## Installation :computer:

There are two ways to run this service: using Docker or Node.js. The Docker image is recommended for most users, but if you want to run the service on a machine that doesn't have Docker installed, you can use Node.js instead.

### Using Docker :whale:

1. Create a new file called docker-compose.yml and copy the following contents into it:

```yaml
version: "3.8"
version: '3.8'
services:
cloudflare-ddns:
image: realshaunoneill/cloudflare-ddns:latest
Expand All @@ -42,34 +48,41 @@ There are two ways to run this service: using Docker or Node.js. The Docker imag
- WEBHOOK_URL=https://your-webhook-url
- WEBHOOK_METHOD=POST
```

2. Modify the environment variables to your liking. See Configuration for more information.
3. Run the service:

```shell
docker-compose up -d
```

### Using Node.js :computer:

1. Clone this repository to your local machine:

```shell
git clone https://github.com/your-username/your-repo.git
```

2. Install the dependencies:

```shell
npm install
```

3. Copy the .env.example file to .env and modify the values to your liking. See Configuration for more information.
The .env file is used to store your Cloudflare API key and other configuration options. It is ignored by Git, so you don't have to worry about accidentally committing your API key to the repository. You can copy the .env.example file to .env using the following command:
The .env file is used to store your Cloudflare API key and other configuration options. It is ignored by Git, so you don't have to worry about accidentally committing your API key to the repository. You can copy the .env.example file to .env using the following command:

```shell
cp .env.example .env
```

4. Run the service:

```shell
npm start
```

5. (Optional) If you want to run the service in the background, you can use a process manager like [PM2](https://pm2.keymetrics.io/):

```shell
Expand All @@ -78,6 +91,7 @@ The .env file is used to store your Cloudflare API key and other configuration o
```

## Configuration :wrench:

You can modify the following configuration settings in the .env file:

- CLOUDFLARE_API_KEY: Your Cloudflare API key or access token.
Expand All @@ -88,22 +102,26 @@ You can modify the following configuration settings in the .env file:
- WEBHOOK_METHOD: The HTTP method to use when sending the webhook (GET or POST).

## How to use cron

[Cron](https://en.wikipedia.org/wiki/Cron) is used to schedule the script execution.
You can use [crontab.guru](https://crontab.guru) as helper to get the cron job working.

```
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday 7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
```

## Contributing :handshake:

Contributions are welcome! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request.

## License :page_facing_up:
This project is licensed under the GPL-3.0 License.

This project is licensed under the GPL-3.0 License.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.8"
version: '3.8'
services:
cloudflare-ddns:
image: realshaunoneill/cloudflare-ddns:latest
Expand Down
32 changes: 20 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,41 @@
"name": "cloudflare-ddns",
"version": "1.0.0",
"description": "Auto update a cloudflare DNS record with your public IP",
"main": "index.js",
"type": "module",
"scripts": {
"start": "node ./src/index",
"dev": "node -r dotenv/config ./src/index"
},
"repository": {
"type": "git",
"url": "git@github.com-personal:realshaunoneill/cloudflare-ddns.git"
},
"keywords": [
"cloudflare",
"ddns",
"dns",
"updater"
],
"repository": {
"type": "git",
"url": "git@github.com-personal:realshaunoneill/cloudflare-ddns.git"
},
"license": "GPL-3.0",
"author": {
"name": "Shaun O'Neill",
"url": "https://www.shaunoneill.com"
},
"license": "GPL-3.0",
"type": "module",
"main": "index.js",
"scripts": {
"dev": "node -r dotenv/config ./src/index",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prettier-check": "prettier --check .",
"prettier-fix": "prettier --write .",
"start": "node ./src/index"
},
"prettier": "@realshaunoneill/style-guide/prettier",
"dependencies": {
"@realshaunoneill/style-guide": "^1.1.0",
"cron": "3.1.6",
"node-fetch": "3.3.2"
},
"devDependencies": {
"dotenv": "16.3.1",
"eslint-config-prettier": "9.0.0"
"eslint": "^8.57.0",
"eslint-config-prettier": "9.0.0",
"prettier": "^3.2.5"
}
}
8 changes: 0 additions & 8 deletions prettier.config.js

This file was deleted.

0 comments on commit b9682ed

Please sign in to comment.