From 0b80fb9a4af73afdd7dc8a1ca021bc4a1a7bde4f Mon Sep 17 00:00:00 2001 From: Jonas Forsberg Date: Thu, 13 Apr 2023 14:45:03 +0200 Subject: [PATCH] initial commit --- .gitignore | 2 ++ Dockerfile | 15 +++++++++++++++ Makefile | 25 +++++++++++++++++++++++++ entrypoint.sh | 30 ++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 entrypoint.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a703a4a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +tmp/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..56a80f0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +ARG VERSION +FROM registry.opensuse.org/opensuse/tumbleweed:${VERSION} + +VOLUME /config + + +RUN zypper --non-interactive install --no-recommends \ + dnsmasq \ + && zypper clean -a \ + rm /var/log/zypper.log + +COPY entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] +CMD ["start"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cdeafb8 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +.PHONY: default build clean release + +-include .env + +VERSION=20230411 +IMAGENAME=dnsmasq +REPO=docker.io/bardak + +SHELL := /bin/bash + +default: build + +guard: + @ if [ -z "$(git status --porcelain)" ]; then echo "git repo not clean"; exit 1; fi + +build: + podman build --build-arg VERSION=$(VERSION) --tag ${REPO}/${IMAGENAME}:$(VERSION) . + +clean: + podman image rm ${REPO}/${IMAGENAME}:$(VERSION) + +release: guard clean build + git tag v$(VERSION) + git push origin v$(VERSION) + podman push --creds $(USERNAME):$(PASSWORD) ${REPO}/${IMAGENAME}:$(VERSION) diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..e54f4b4 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +if [[ ! -f /config/dnsmasq.conf ]]; then + echo "* Creating /config/dnsmasq.conf" + sed 's/^conf-dir=\/etc\//conf-dir=\/config\//g' /etc/dnsmasq.conf > /config/dnsmasq.conf +fi +if [[ ! -f /config/hosts/hosts ]]; then + echo "* Creating /config/hosts/hosts" + mkdir /config/hosts + cp /etc/hosts /config/hosts/hosts +fi +if [[ ! -f /config/resolv.conf ]]; then + echo "* Creating /config/resolv.conf" + cp /etc/resolv.conf /config/resolv.conf +fi +if [[ ! -d /config/dnsmasq.d ]]; then + echo "* Creating /config/dnsmasq.d" + mkdir /config/dnsmasq.d +fi + +if [[ "$1" == "start" ]]; then + /usr/sbin/dnsmasq \ + --conf-fil=/config/dnsmasq.conf \ + --no-daemon --no-hosts \ + --keep-in-foreground \ + --resolv-file=/config/resolv.conf \ + --hostsdir=/config/hosts +else + exec "$@" +fi