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/
|
||||
WORKDIR /app/cloudflare-ddns
|
||||
@@ -15,7 +15,6 @@ RUN apt-get update && apt-get --no-install-recommends install -y \
|
||||
cron \
|
||||
libaugeas0 \
|
||||
make \
|
||||
python3.11 python3.11-dev python3.11-pip python3.11-venv \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
cp /app/cloudflare-ddns/cron/cronjob-ddns /etc/cron.d/cloudflare-ddns \
|
||||
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 )"
|
||||
|
||||
default: build
|
||||
.DEFAULT_GOAL := help
|
||||
|
||||
.PHONY: build
|
||||
build: stop
|
||||
docker build -t $(IMAGE_NAME) .
|
||||
|
||||
.PHONY: run
|
||||
run:
|
||||
docker run --rm --privileged=true -d -v /opt/cloudflare-ddns/config:/app/cloudflare-ddns/config $(IMAGE_NAME)
|
||||
|
||||
.PHONY: stop
|
||||
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: help
|
||||
help:
|
||||
@echo "Usage: make [target]"
|
||||
@echo ""
|
||||
@echo "Targets:"
|
||||
@echo " install Install the required dependencies"
|
||||
@echo " certbot Install certbot"
|
||||
@echo " uninstall Uninstall the installed dependencies"
|
||||
@echo ""
|
||||
|
||||
.PHONY: install
|
||||
install:
|
||||
@echo "Installing cloudflare-ddns"
|
||||
@scripts/install.sh
|
||||
|
||||
.PHONY: certbot
|
||||
certbot:
|
||||
@echo "Installing certbot"
|
||||
@scripts/certbot.sh
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@rm -rf /app/cloudflare-ddns
|
||||
@rm -rf /app/certbot
|
||||
@rm /etc/cron.d/cloudflare-ddns
|
||||
@rm /var/log/cloudflare_ddns.log
|
||||
@rm /var/log/cloudflare_ddns.log.*
|
||||
@echo "Done"
|
||||
.PHONY: uninstall
|
||||
uninstall:
|
||||
@scripts/uninstall.sh
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
requests==2.32.2
|
||||
certbot==2.11.0
|
||||
certbot-dns-cloudflare==1.18.0
|
||||
@@ -1,8 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 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 )"
|
||||
|
||||
@@ -1,19 +1,36 @@
|
||||
#!/bin/bash
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
|
||||
@echo off
|
||||
echo "Certbot and Cloudflare API tools installation"
|
||||
sudo apt update
|
||||
sudo apt install -y certbot python3-certbot-dns-cloudflare jq
|
||||
echo -e "Certbot and Cloudflare API tools installation started. \n"
|
||||
sudo apt -qq update
|
||||
PKG_LIST=(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 cp -r $DIR/../* /app/cloudflare-ddns
|
||||
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
|
||||
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 chmod 600 /app/cloudflare-ddns/config/env.json
|
||||
else
|
||||
echo -e "Environment configuration file is not overwritten. \n"
|
||||
fi
|
||||
else
|
||||
sudo mkdir -p /app/cloudflare-ddns/config
|
||||
@@ -21,6 +38,6 @@ else
|
||||
sudo chmod 600 /app/cloudflare-ddns/config/env.json
|
||||
fi
|
||||
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
|
||||
|
||||
export CLOUDFLARE_API_KEY=$API_KEY
|
||||
export CLOUDFLARE_DOMAIN=$DOMAIN_NAME
|
||||
export CLOUDFLARE_ZONE_ID=$ZONE_ID
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
# Run the script
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
#!/bin/bash
|
||||
@echo "Uninstalling Cloudflare DDNS and Certbot..."
|
||||
@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"
|
||||
|
||||
echo "Uninstalling Cloudflare DDNS and Certbot..."
|
||||
|
||||
read -p "Do you want to uninstall Certbot and Cloudflare API tools? (y/N): " uninstall
|
||||
uninstall=${uninstall:-n}
|
||||
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")
|
||||
PWD = os.path.dirname(os.path.abspath(__file__))
|
||||
TMP_PATH = os.path.join(PWD, "tmp")
|
||||
TMP_PATH = os.path.join(PWD, "../tmp")
|
||||
|
||||
|
||||
class DDNS:
|
||||
def __init__(self, config_path=DEFAULT_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()
|
||||
previous_ip = self.previous_ip()
|
||||
|
||||
@@ -36,7 +37,6 @@ class DDNS:
|
||||
logger.info(f"Previous IP: {previous_ip}")
|
||||
self.current_ip = current_ip
|
||||
self.cname_list = self.config["CLOUDFLARE_CNAME"]
|
||||
self.external_ip_path = os.path.join(TMP_PATH, "external_ip.txt")
|
||||
|
||||
self.HEADERS = {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
Reference in New Issue
Block a user