diff --git a/Dockerfile b/Dockerfile index 5b94bcb..e3a5a58 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,22 @@ ARG REPO=library FROM ${REPO}/python:3-alpine +# TODO: Copy from docker hub image ARG ARCH=x86_64 COPY ./build/qemu-${ARCH}-static /usr/bin/ - RUN mkdir -p /src WORKDIR /src -COPY ./requirements.txt ./ -RUN pip install -r ./requirements.txt +# Get Cloudflare example script +ENV CF_VERSION=2.6.0 +ADD https://raw.githubusercontent.com/cloudflare/python-cloudflare/$CF_VERSION/examples/example_update_dynamic_dns.py ./update_ddns.py +RUN chmod +x ./update_ddns.py -COPY ./start.sh ./ -COPY ./update_ddns.py ./update_ddns.py +RUN pip install cloudflare==$CF_VERSION ENV DOMAIN="" USER nobody -CMD [ "/src/start.sh" ] +ENTRYPOINT [ "/src/update_ddns.py" ] diff --git a/Makefile b/Makefile index ec80dfe..a481c9c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ DOCKER_TAG ?= cloudflare-ddns-dev-${USER} +.PHONY: clean all .PHONY: default default: test @@ -7,11 +8,6 @@ default: test test: @echo ok -.PHONY: update -update: - curl -o update_ddns.py https://raw.githubusercontent.com/cloudflare/python-cloudflare/master/examples/example_update_dynamic_dns.py - chmod +x update_ddns.py - .PHONY: build build: build/qemu-x86_64-static docker build . -t ${DOCKER_TAG} @@ -35,7 +31,8 @@ cross-build-arm64: build/qemu-aarch64-static .PHONY: run run: build - docker run --rm -e DOMAIN=${DOMAIN} \ + docker run --rm \ -e CF_API_EMAIL=${CF_API_EMAIL} \ -e CF_API_KEY=${CF_API_KEY} \ - ${DOCKER_TAG} + ${DOCKER_TAG} \ + "${DOMAIN}" diff --git a/README.md b/README.md index 04591a1..7dca0ef 100644 --- a/README.md +++ b/README.md @@ -4,18 +4,25 @@ Simple Docker image to dynamically update a Cloudflare DNS record. ## Usage -All parameters are passed to the script using env variables, so export the following: +There are two things to configure. First, the domain that you wish to update needs to be provided as a command line argument. This can be done by adding it to the end of your run command (example in the Makefile) or by adding it as a command to your compose file. Eg: - DOMAIN=sub.example.com - CF_API_EMAIL=admin@example.com + ddns: + image: IamTheFij/cloudflare-ddns + command: ["example.com"] + +Your Cloudflare credentials can be passed in any way that [python-cloudflare](https://github.com/cloudflare/python-cloudflare) allows. Generally, either via envioronment variables: + + CF_API_EMAIL=admin@example.com # Do not set if using an API Token CF_API_KEY=00000000000000000000 + CF_API_CERTKEY='v1.0-...' + +Or by providing a file mounted to the working directory in the image, `/src/.cloudflare.cfg` that contains something like: + + [CloudFlare] + emal = admin@example.com # Do not set if using an API Token + token = 00000000000000000000 + certtoken = v1.0-... Then run. To execute from this directory, you can use the convenient Make target. make run - -## Development - -The script is straight from the examples provided by Cloudflare on their Github. The latest version can be downloaded using: - - make update diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 0a9630a..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -cloudflare diff --git a/start.sh b/start.sh deleted file mode 100755 index 2993157..0000000 --- a/start.sh +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/sh - -exec /src/update_ddns.py $DOMAIN