mirror of
https://github.com/jung-geun/DynamicDNS-SSL.git
synced 2025-12-19 20:44:40 +09:00
Refactor Dockerfile to use Python 3.11-slim
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
FROM python:3.9-slim
|
FROM python:3.11-slim
|
||||||
|
|
||||||
RUN mkdir -p /app/cloudflare-ddns/
|
RUN mkdir -p /app/cloudflare-ddns/
|
||||||
WORKDIR /app/cloudflare-ddns
|
WORKDIR /app/cloudflare-ddns
|
||||||
@@ -15,7 +15,6 @@ RUN apt-get update && apt-get --no-install-recommends install -y \
|
|||||||
cron \
|
cron \
|
||||||
libaugeas0 \
|
libaugeas0 \
|
||||||
make \
|
make \
|
||||||
python3.11 python3.11-dev python3.11-pip python3.11-venv \
|
|
||||||
&& rm -rf /var/lib/apt/lists/* \
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
cp /app/cloudflare-ddns/cron/cronjob-ddns /etc/cron.d/cloudflare-ddns \
|
cp /app/cloudflare-ddns/cron/cronjob-ddns /etc/cron.d/cloudflare-ddns \
|
||||||
pip install --no-cache-dir -r requirements.txt \
|
pip install --no-cache-dir -r requirements.txt \
|
||||||
|
|||||||
42
Makefile
42
Makefile
@@ -1,41 +1,25 @@
|
|||||||
IMAGE_NAME = "cloudflare-ddns"
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||||
|
|
||||||
default: build
|
.DEFAULT_GOAL := help
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: help
|
||||||
build: stop
|
help:
|
||||||
docker build -t $(IMAGE_NAME) .
|
@echo "Usage: make [target]"
|
||||||
|
@echo ""
|
||||||
.PHONY: run
|
@echo "Targets:"
|
||||||
run:
|
@echo " install Install the required dependencies"
|
||||||
docker run --rm --privileged=true -d -v /opt/cloudflare-ddns/config:/app/cloudflare-ddns/config $(IMAGE_NAME)
|
@echo " certbot Install certbot"
|
||||||
|
@echo " uninstall Uninstall the installed dependencies"
|
||||||
.PHONY: stop
|
@echo ""
|
||||||
stop:
|
|
||||||
@container_id=$$(docker ps -q -f ancestor=$(IMAGE_NAME)); \
|
|
||||||
if [ -n "$$container_id" ]; then \
|
|
||||||
echo "Stopping container $$container_id"; \
|
|
||||||
docker stop $$container_id; \
|
|
||||||
else \
|
|
||||||
echo "No running container found for image $(IMAGE_NAME)"; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install:
|
install:
|
||||||
@echo "Installing cloudflare-ddns"
|
|
||||||
@scripts/install.sh
|
@scripts/install.sh
|
||||||
|
|
||||||
.PHONY: certbot
|
.PHONY: certbot
|
||||||
certbot:
|
certbot:
|
||||||
@echo "Installing certbot"
|
|
||||||
@scripts/certbot.sh
|
@scripts/certbot.sh
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: uninstall
|
||||||
clean:
|
uninstall:
|
||||||
@rm -rf /app/cloudflare-ddns
|
@scripts/uninstall.sh
|
||||||
@rm -rf /app/certbot
|
|
||||||
@rm /etc/cron.d/cloudflare-ddns
|
|
||||||
@rm /var/log/cloudflare_ddns.log
|
|
||||||
@rm /var/log/cloudflare_ddns.log.*
|
|
||||||
@echo "Done"
|
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
requests==2.32.2
|
requests==2.32.2
|
||||||
|
certbot==2.11.0
|
||||||
|
certbot-dns-cloudflare==1.18.0
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Certbot 및 Cloudflare API 도구 설치
|
# Certbot 및 Cloudflare API 도구 설치
|
||||||
sudo apt update
|
|
||||||
sudo apt install -y certbot python3-certbot-dns-cloudflare jq
|
|
||||||
|
|
||||||
# 필요한 변수 설정
|
# 필요한 변수 설정
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||||
|
|||||||
@@ -1,19 +1,36 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||||
|
|
||||||
@echo off
|
echo -e "Certbot and Cloudflare API tools installation started. \n"
|
||||||
echo "Certbot and Cloudflare API tools installation"
|
sudo apt -qq update
|
||||||
sudo apt update
|
PKG_LIST=(certbot python3-certbot-dns-cloudflare jq)
|
||||||
sudo apt install -y certbot python3-certbot-dns-cloudflare jq
|
for pkg in ${PKG_LIST[@]}; do
|
||||||
|
dpkg -l | grep -q $pkg
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "$pkg is already installed."
|
||||||
|
read -p "Do you want to reinstall it? (y/N): " reinstall
|
||||||
|
reinstall=${reinstall:-n}
|
||||||
|
if [ "$reinstall" == "y" ]; then
|
||||||
|
sudo apt install --reinstall -y $pkg
|
||||||
|
fi
|
||||||
|
echo -e "\n\n"
|
||||||
|
else
|
||||||
|
echo "$pkg is not installed."
|
||||||
|
sudo apt install -y $pkg
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
sudo mkdir -p /app/cloudflare-ddns
|
sudo mkdir -p /app/cloudflare-ddns
|
||||||
sudo cp -r $DIR/../* /app/cloudflare-ddns
|
sudo cp -r $DIR/../* /app/cloudflare-ddns
|
||||||
if [ -f /app/cloudflare-ddns/config/env.json ]; then
|
if [ -f /app/cloudflare-ddns/config/env.json ]; then
|
||||||
read -p "Environment configuration file already exists. Do you want to overwrite it? (y/n): " overwrite
|
read -p "Environment configuration file already exists. Do you want to overwrite it? (y/N): " overwrite
|
||||||
|
overwrite=${overwrite:-n}
|
||||||
if [ "$overwrite" == "y" ]; then
|
if [ "$overwrite" == "y" ]; then
|
||||||
sudo mv /app/cloudflare-ddns/config/env.json /app/cloudflare-ddns/config/env.json.bak
|
sudo mv /app/cloudflare-ddns/config/env.json /app/cloudflare-ddns/config/env.json.bak
|
||||||
sudo cp $DIR/../config/env_example.json /app/cloudflare-ddns/config/env.json
|
sudo cp $DIR/../config/env_example.json /app/cloudflare-ddns/config/env.json
|
||||||
sudo chmod 600 /app/cloudflare-ddns/config/env.json
|
sudo chmod 600 /app/cloudflare-ddns/config/env.json
|
||||||
|
else
|
||||||
|
echo -e "Environment configuration file is not overwritten. \n"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
sudo mkdir -p /app/cloudflare-ddns/config
|
sudo mkdir -p /app/cloudflare-ddns/config
|
||||||
@@ -21,6 +38,6 @@ else
|
|||||||
sudo chmod 600 /app/cloudflare-ddns/config/env.json
|
sudo chmod 600 /app/cloudflare-ddns/config/env.json
|
||||||
fi
|
fi
|
||||||
sudo cp $DIR/../cron/cronjob-ddns /etc/cron.d/cloudflare-ddns
|
sudo cp $DIR/../cron/cronjob-ddns /etc/cron.d/cloudflare-ddns
|
||||||
echo "Please modify the environment configuration file and save it in the /app/cloudflare-ddns/config/env.json path."
|
echo -e "Please modify the environment configuration file and save it in the /app/cloudflare-ddns/config/env.json path. \n"
|
||||||
|
|
||||||
echo "Certbot and Cloudflare API tools installation completed."
|
echo -e "Certbot and Cloudflare API tools installation completed. \n"
|
||||||
@@ -1,9 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export CLOUDFLARE_API_KEY=$API_KEY
|
|
||||||
export CLOUDFLARE_DOMAIN=$DOMAIN_NAME
|
|
||||||
export CLOUDFLARE_ZONE_ID=$ZONE_ID
|
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
# Run the script
|
# Run the script
|
||||||
|
|||||||
@@ -1,7 +1,18 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
@echo "Uninstalling Cloudflare DDNS and Certbot..."
|
|
||||||
@sudo rm -rf /app/cloudflare-ddns
|
echo "Uninstalling Cloudflare DDNS and Certbot..."
|
||||||
@sudo rm /etc/cron.d/cloudflare-ddns
|
|
||||||
@sudo rm /var/log/cloudflare_ddns.log
|
read -p "Do you want to uninstall Certbot and Cloudflare API tools? (y/N): " uninstall
|
||||||
@sudo rm /var/log/cloudflare_ddns.log.*
|
uninstall=${uninstall:-n}
|
||||||
@echo "Done"
|
echo -e "\n"
|
||||||
|
if [ "$uninstall" == "y" ]; then
|
||||||
|
echo "Uninstalling Certbot and Cloudflare API tools..."
|
||||||
|
sudo apt remove --purge -y certbot python3-certbot-dns-cloudflare jq
|
||||||
|
sudo rm -rf /app/cloudflare-ddns
|
||||||
|
sudo rm /etc/cron.d/cloudflare-ddns
|
||||||
|
sudo rm /var/log/cloudflare_ddns.log
|
||||||
|
sudo rm /var/log/cloudflare_ddns.log.*
|
||||||
|
echo "Done"
|
||||||
|
else
|
||||||
|
echo "Uninstallation is cancelled."
|
||||||
|
fi
|
||||||
|
|||||||
@@ -23,12 +23,13 @@ logger.addHandler(logging.StreamHandler())
|
|||||||
|
|
||||||
DEFAULT_CONFIG_PATH = os.path.join(os.path.dirname(__file__), "../config/env.json")
|
DEFAULT_CONFIG_PATH = os.path.join(os.path.dirname(__file__), "../config/env.json")
|
||||||
PWD = os.path.dirname(os.path.abspath(__file__))
|
PWD = os.path.dirname(os.path.abspath(__file__))
|
||||||
TMP_PATH = os.path.join(PWD, "tmp")
|
TMP_PATH = os.path.join(PWD, "../tmp")
|
||||||
|
|
||||||
|
|
||||||
class DDNS:
|
class DDNS:
|
||||||
def __init__(self, config_path=DEFAULT_CONFIG_PATH):
|
def __init__(self, config_path=DEFAULT_CONFIG_PATH):
|
||||||
self.config = self.load_config(config_path)
|
self.config = self.load_config(config_path)
|
||||||
|
self.external_ip_path = os.path.join(TMP_PATH, "external_ip")
|
||||||
current_ip = self.get_ip()
|
current_ip = self.get_ip()
|
||||||
previous_ip = self.previous_ip()
|
previous_ip = self.previous_ip()
|
||||||
|
|
||||||
@@ -36,7 +37,6 @@ class DDNS:
|
|||||||
logger.info(f"Previous IP: {previous_ip}")
|
logger.info(f"Previous IP: {previous_ip}")
|
||||||
self.current_ip = current_ip
|
self.current_ip = current_ip
|
||||||
self.cname_list = self.config["CLOUDFLARE_CNAME"]
|
self.cname_list = self.config["CLOUDFLARE_CNAME"]
|
||||||
self.external_ip_path = os.path.join(TMP_PATH, "external_ip.txt")
|
|
||||||
|
|
||||||
self.HEADERS = {
|
self.HEADERS = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|||||||
Reference in New Issue
Block a user