Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added docker configuration and pihole to smartdns converter #144

Merged
merged 1 commit into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ Cargo.lock
# web ui
node_modules
dist

.idea/
3 changes: 3 additions & 0 deletions contrib/docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
smartdns.conf
pihole.txt
smartdns-ads.txt
44 changes: 44 additions & 0 deletions contrib/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
ARG VERSION=0.6.1

FROM debian:stable as downloader

ARG VERSION

RUN apt-get update && apt-get install -y curl
RUN mkdir -p /app/x86 /app/arm64 /app/armv7 /app/extracted/x86 /app/extracted/arm64 /app/extracted/armv7


RUN curl -L https://github.com/mokeyish/smartdns-rs/releases/download/$VERSION/smartdns-x86_64-unknown-linux-musl.tar.gz -o /app/x86/smartdns.tar.gz
RUN ls -lisa /app/x86
RUN tar -xvf /app/x86/smartdns.tar.gz -C /app/extracted/x86

RUN curl -L https://github.com/mokeyish/smartdns-rs/releases/download/$VERSION/smartdns-aarch64-unknown-linux-musl.tar.gz -o /app/arm64/smartdns.tar.gz

RUN tar -xvf /app/arm64/smartdns.tar.gz -C /app/extracted/arm64
RUN curl -L https://github.com/mokeyish/smartdns-rs/releases/download/$VERSION/smartdns-arm-unknown-linux-musleabihf.tar.gz -o /app/armv7/smartdns.tar.gz

RUN tar -xvf /app/armv7/smartdns.tar.gz -C /app/extracted/armv7

FROM alpine as base

WORKDIR /app
RUN apk add bash
COPY docker-entrypoint.sh /app/entrypoint.sh
FROM base as amd64

COPY --from=downloader /app/extracted/x86/* /app/

FROM base as armv7

COPY --from=downloader /app/extracted/armv7/* /app/

FROM base as arm64

COPY --from=downloader /app/extracted/arm64/* /app/


FROM ${TARGETARCH}${TARGETVARIANT} as final


EXPOSE 8000
CMD ["bash", "/app/entrypoint.sh"]
14 changes: 14 additions & 0 deletions contrib/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "3"
services:
dns:
image: smartdns-rs
build:
context: .
dockerfile: Dockerfile
ports:
- "53:53"
- "53:53/udp"
volumes:
- ./smartdns.conf:/app/smartdns.conf
#environment:
#- PARAMS= # Pass additional flags to the smartdns binary
14 changes: 14 additions & 0 deletions contrib/docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

if [[ ! -f /app/smartdns.conf ]]; then
echo "File /app/smartdns.conf is empty. It must be set in order to get started You can find additional information
here:"
echo "https://pymumu.github.io/smartdns/en/config/basic-config/"
exit 1
fi

# Init with default parameter
if [[ -z "${PARAMS}" ]];then
PARAMS="run -c /app/smartdns.conf"
fi
/app/smartdns $PARAMS
23 changes: 23 additions & 0 deletions contrib/docker/pihole-to-smartdns.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

# Converts a pihole adlist like https://raw.githubusercontent.com/StevenBlack/hosts/master/data/StevenBlack/hosts to
# a smartdns compatible format. Download the respective adlist and save it as pihole.txt in the same folder as this script.
# Run this script and copy the content of the generated smartdns-ads.txt to your smartdns.conf file.

output=''
block_prefix="address /"
block_suffix="/0.0.0.0"

while read p; do

trimmed_output=$(echo $p| sed 's/^[ \t]*//;s/[ \t]*$//')
# If line is not a comment and not empty
if [[ $p != \#* && ! -z $trimmed_output ]] ; then
output+=$block_prefix$(echo $trimmed_output | cut -d ' ' -f 2)$block_suffix
else
output+=$(echo $trimmed_output)
fi
output+='\n'
done <pihole.txt

echo -e $output > smartdns-ads.txt