Minimal multi-stage docker build

This commit is contained in:
timothymiller 2020-08-05 03:25:13 -04:00
parent a1e1348214
commit df6b8a381a
8 changed files with 73 additions and 81 deletions

View File

@ -3,7 +3,7 @@ name: Bug report
about: Create a report to help us improve about: Create a report to help us improve
title: '' title: ''
labels: '' labels: ''
assignees: '' assignees: 'timothymiller'
--- ---
@ -24,15 +24,15 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem. If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):** **Desktop (please complete the following information):**
- OS: [e.g. iOS] - OS: [e.g. Arch Linux]
- Browser [e.g. chrome, safari] - Browser [e.g. Chrome, Safari]
- Version [e.g. 22] - Version [e.g. 60]
**Smartphone (please complete the following information):** **Smartphone (please complete the following information):**
- Device: [e.g. iPhone6] - Device: [e.g. iPhone X]
- OS: [e.g. iOS8.1] - OS: [e.g. iOS 14.0]
- Browser [e.g. stock browser, safari] - Browser [e.g. stock browser, Safari]
- Version [e.g. 22] - Version [e.g. 60]
**Additional context** **Additional context**
Add any other context about the problem here. Add any other context about the problem here.

69
.gitignore vendored
View File

@ -1,3 +1,4 @@
# Private API keys for updating IPv4 & IPv6 addresses on Cloudflare
config.json config.json
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
@ -39,43 +40,6 @@ MANIFEST
pip-log.txt pip-log.txt
pip-delete-this-directory.txt pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook # Jupyter Notebook
.ipynb_checkpoints .ipynb_checkpoints
@ -86,19 +50,6 @@ ipython_config.py
# pyenv # pyenv
.python-version .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments # Environments
.env .env
.venv .venv
@ -107,21 +58,3 @@ venv/
ENV/ ENV/
env.bak/ env.bak/
venv.bak/ venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/

18
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,18 @@
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
".github": true,
".vscode": true,
"LICENSE": true,
"requirements.txt": true,
"build-docker-image.sh": true,
".gitignore": true,
"Dockerfile": false,
"start-sync.sh": false
},
"explorerExclude.backup": null
}

18
Dockerfile Normal file
View File

@ -0,0 +1,18 @@
# ---- Base ----
FROM python:alpine AS base
#
# ---- Dependencies ----
FROM base AS dependencies
# install dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt
#
# ---- Release ----
FROM dependencies AS release
# copy project file(s)
WORKDIR /
COPY cloudflare-ddns.py .
COPY config.json .
CMD ["python", "/cloudflare-ddns.py"]

1
build-docker-image.sh Executable file
View File

@ -0,0 +1 @@
docker build -t timothymiller/cloudflare-ddns:latest .

View File

@ -104,6 +104,27 @@ def cf_api(endpoint, method, config, headers={}, data=False):
return response.json() return response.json()
for ip in getIPs(): # Scheduling
print("Checking " + ip["type"] + " records") import time, traceback
commitRecord(ip)
def every(delay, task):
next_time = time.time() + delay
while True:
time.sleep(max(0, next_time - time.time()))
try:
task()
except Exception:
traceback.print_exc()
# in production code you might want to have this instead of course:
# logger.exception("Problem while executing repetitive task.")
# skip tasks if we are behind schedule:
next_time += (time.time() - next_time) // delay * delay + delay
def updateIPs():
for ip in getIPs():
print("Checking " + ip["type"] + " records")
commitRecord(ip)
updateIPs()
import threading
threading.Thread(target=lambda: every(60*15, updateIPs)).start()

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
requests==2.24.0

View File

@ -4,7 +4,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
python3 -m venv venv python3 -m venv venv
source ./venv/bin/activate source ./venv/bin/activate
pip install requests pip3 install requests
cd $DIR cd $DIR
python3 cloudflare-ddns.py python3 cloudflare-ddns.py