Browse Source

feat: docker package

dev
dnomd343 3 years ago
parent
commit
843cb196d3
  1. 35
      Dockerfile
  2. 32
      init.sh
  3. 42
      load.sh
  4. 1
      overture/update.sh
  5. 2
      src/process.c

35
Dockerfile

@ -1,4 +1,4 @@
FROM alpine:3.15
FROM alpine:3.15 as build
COPY . /tmp/ClearDNS
ENV OVERTURE_VERSION="v1.8"
ENV DNSPROXY_VERSION="v0.41.3"
@ -30,16 +30,23 @@ mv ./AdGuardHome /tmp/release/ && \
cd /tmp/release/ && \
strip * && upx -9 *
#
#FROM alpine as asset
#COPY ./asset.sh /
#RUN apk --update add --no-cache curl wget && \
# sh /asset.sh
#
#FROM alpine
#COPY ["./overture/", "./init.sh", "/etc/overture/"]
#COPY --from=asset /tmp/asset/ /usr/bin/
#RUN mv /etc/overture/init.sh / && \
# mkdir -p /etc/cleardns && \
# sed -i '$i\0\t4\t*\t*\t*\t/etc/overture/update.sh' /var/spool/cron/crontabs/root
#CMD ["sh","/init.sh"]
FROM alpine:3.15 as asset
COPY . /tmp/ClearDNS
COPY --from=build /tmp/release /tmp/release
RUN \
wget https://res.dnomd343.top/Share/gfwlist/gfwlist.txt && \
wget https://res.dnomd343.top/Share/chinalist/chinalist.txt && \
wget https://res.dnomd343.top/Share/chinalist/china_ip.txt && \
tar czf asset.tar.gz gfwlist.txt chinalist.txt china_ip.txt && \
mkdir -p /tmp/asset/etc/ && mkdir -p /tmp/asset/usr/ && \
cp -r /tmp/ClearDNS/overture/ /tmp/asset/etc/ && \
mv asset.tar.gz /tmp/asset/etc/overture/ && \
mv /tmp/release/ /tmp/asset/usr/bin/ && \
mv /tmp/ClearDNS/load.sh /tmp/asset/usr/bin/load
FROM alpine:3.15
COPY --from=asset /tmp/asset /
RUN apk add --no-cache ca-certificates glib && \
echo -e "0\t4\t*\t*\t*\t/etc/overture/update.sh" > /var/spool/cron/crontabs/root
ENTRYPOINT ['cleardns']
CMD ['--debug']

32
init.sh

@ -1,32 +0,0 @@
[ -f "/etc/cleardns/custom.sh" ] && sh /etc/cleardns/custom.sh
mkdir -p /etc/cleardns/list
mkdir -p /etc/cleardns/upstream
mkdir -p /etc/cleardns/AdGuardHome
[ ! -s "/etc/cleardns/upstream/domestic.conf" ] && echo -e "223.5.5.5\n119.29.29.29\n114.114.114.114" > /etc/cleardns/upstream/domestic.conf
[ ! -s "/etc/cleardns/upstream/foreign.conf" ] && echo -e "8.8.4.4\n8.8.8.8" > /etc/cleardns/upstream/foreign.conf
cat /etc/cleardns/upstream/domestic.conf | sed 's/^[ \t]*//g' | sed 's/[ \t]*$//g' | tr -s '\n' | sed '/^#/d' | sed '/^\/\//d' > /etc/cleardns/upstream/domestic
cat /etc/cleardns/upstream/foreign.conf | sed 's/^[ \t]*//g' | sed 's/[ \t]*$//g' | tr -s '\n' | sed '/^#/d' | sed '/^\/\//d' > /etc/cleardns/upstream/foreign
cmd="dnsproxy -p 4053"
while read -r raw
do
cmd="$cmd -u $raw"
done < /etc/cleardns/upstream/domestic
eval "$cmd --cache --cache-size=4194304 --all-servers > /dev/null 2>&1 &"
cmd="dnsproxy -p 6053"
while read -r raw
do
cmd="$cmd -u $raw"
done < /etc/cleardns/upstream/foreign
eval "$cmd --cache --cache-size=4194304 --all-servers > /dev/null 2>&1 &"
rm -f /etc/cleardns/upstream/domestic
rm -f /etc/cleardns/upstream/foreign
/etc/overture/update.sh
/usr/sbin/crond
/usr/bin/AdGuardHome -p 80 -w /etc/cleardns/AdGuardHome --no-check-update

42
load.sh

@ -0,0 +1,42 @@
#!/bin/sh
mkdir -p /etc/cleardns/asset/
mkdir -p /etc/cleardns/AdGuardHome/
cleardns_dir="/etc/cleardns"
overture_dir="/etc/overture"
cd $overture_dir && tar xf asset.tar
[ ! -f "$cleardns_dir/gfwlist.txt" ] && cp "$overture_dir/gfwlist.txt" "$cleardns_dir/gfwlist.txt"
[ ! -f "$cleardns_dir/chinalist.txt" ] && cp "$overture_dir/chinalist.txt" "$cleardns_dir/chinalist.txt"
[ ! -f "$cleardns_dir/china_ip.txt" ] && cp "$overture_dir/china_ip.txt" "$cleardns_dir/china_ip.txt"
upstream_file="/etc/cleardns/upstream.json"
if [ ! -f "$upstream_file" ]; then
cat > $upstream_file << EOF
{
"domestic": {
"bootstrap": "223.5.5.5",
"primary": [
"tls://dns.alidns.com",
"https://doh.pub/dns-query"
],
"fallback": [
"223.5.5.5",
"119.29.29.29"
]
},
"foreign": {
"bootstrap": "8.8.8.8",
"primary": [
"tls://dns.google",
"https://dns.cloudflare.com/dns-query"
],
"fallback": [
"1.1.1.1",
"8.8.8.8"
]
}
}
EOF
fi
/etc/overture/update.sh&

1
overture/update.sh

@ -1,3 +1,4 @@
#!/bin/sh
ASSET_DIR="/etc/cleardns/asset"
[ -f "$ASSET_DIR/no_auto_update" ] && exit

2
src/process.c

@ -127,7 +127,7 @@ void get_sub_exit() { // catch child process exit
perror("[ClearDNS] Waitpid error");
server_exit(EXIT_WAIT_ERROR);
} else if (ret) { // process exit
fprintf(stderr, "[ClearDNS] Catch subprocess detach or exit. (pid = %d)\n", ret);
fprintf(stderr, "[ClearDNS] Catch subprocess exit. (pid = %d)\n", ret);
return;
}
fprintf(stderr, "[ClearDNS] Subprocess not found.\n"); // get SIGCHLD signal but not exited subprocess found

Loading…
Cancel
Save