Skip to content

Commit

Permalink
Merge pull request #16 from OpenCHAMI/alovelltroy/quickstart
Browse files Browse the repository at this point in the history
Alovelltroy/quickstart
  • Loading branch information
alexlovelltroy authored May 6, 2024
2 parents 2049fea + 7cf9f0b commit 0c15525
Show file tree
Hide file tree
Showing 20 changed files with 274 additions and 207 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/build_containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
with:
# list of Docker images to use as base name for tags
images: |
ghcr.io/openchami/dnsmasq
ghcr.io/openchami/dnsmasq
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
Expand All @@ -31,8 +32,6 @@ jobs:
type=sha
- name: setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Login to github container repo
uses: docker/login-action@v3
with:
Expand All @@ -42,9 +41,8 @@ jobs:
- name: Build and push
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
platforms: linux/amd64
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# syntax=docker/dockerfile:1.4

## Build iPXE binaries from source
FROM cgr.dev/chainguard/wolfi-base AS builder
RUN apk add git gcc binutils make perl xz xz-dev build-base
RUN mkdir -p /tmp
WORKDIR /tmp
RUN git clone https://github.com/ipxe/ipxe.git
WORKDIR /tmp/ipxe/src/
RUN make bin/undionly.kpxe && \
make bin-x86_64-efi/ipxe.efi && \
cp -a bin/undionly.kpxe /tmp/ && \
cp -a bin-x86_64-efi/ipxe.efi /tmp/

## Build dnsmasq-dhcp container image
FROM cgr.dev/chainguard/wolfi-base

RUN apk add dnsmasq

# Create the directory to store leases
RUN mkdir -p /var/lib/misc

# Create the directory to store the tftp files
RUN mkdir -p /var/lib/tftpboot
#Copy PXE files from builder stage
COPY --from=builder /tmp/undionly.kpxe /var/lib/tftpboot/
COPY --from=builder /tmp/ipxe.efi /var/lib/tftpboot/ipxe-x86_64.efi

VOLUME /etc/dnsmasq

EXPOSE 53 53/udp
EXPOSE 67 67/udp


ENTRYPOINT ["dnsmasq", "-k", "--log-dhcp", "--log-facility=-", "-R", "-h", "-C", "/etc/dnsmasq/dnsmasq.conf" ]
23 changes: 23 additions & 0 deletions Dockerfile.updater
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# syntax=docker/dockerfile:1.4
FROM cgr.dev/chainguard/python:latest-dev as builder

WORKDIR /app

COPY requirements.txt .

RUN pip install -r requirements.txt --user

FROM cgr.dev/chainguard/python:latest

WORKDIR /app

# Make sure you update Python version in path
COPY --from=builder /home/nonroot/.local/lib/python3.12/site-packages /home/nonroot/.local/lib/python3.12/site-packages

COPY dnsmasq_updater.py .

# Copy the rest of the application code
COPY dnsmasq_updater.py .

# Set the command to run your Python application
ENTRYPOINT ["python", "/app/dnsmasq_updater.py"]
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Dynamic dnsmasq container

This container expects all configuration files to be mounted in via docker volumes.

See the [example directory](/examples/docker-compose/) for a recommended configuration file structure.

## Dynamic hosts

dnsmasq doesn't have a native facility to automatically update the configuration on changes. It requires a SIGHUP. However, it does have a facility that allows it to dynamically add hosts through the `--dhcp-hostsdir` option. The behavior may not be precisely what you expect. Here is the

> --dhcp-hostsdir=<path>
This is equivalent to --dhcp-hostsfile, except for the following. The path MUST be a directory, and not an individual file. Changed or new files within the directory are read automatically, without the need to send SIGHUP. If a file is deleted or changed after it has been read by dnsmasq, then the host record it contained will remain until dnsmasq receives a SIGHUP, or is restarted; ie host records are only added dynamically. The order in which the files in a directory are read is not defined.

## Manually reloading the container configuration

Docker supports sending signals to the main process in a container. From the [docker documentation](https://docs.docker.com/reference/cli/docker/container/kill/#send-a-custom-signal--to-a-container), there are several ways to send a SIGHUP to dnsmasq.

```bash
# The following commands are all equivalent
docker kill --signal=SIGHUP dnsmasq
docker kill --signal=HUP dnsmasq
docker kill --signal=1 dnsmasq
```

11 changes: 0 additions & 11 deletions dnsmasq-dhcpd-dynamic/Dockerfile

This file was deleted.

6 changes: 0 additions & 6 deletions dnsmasq-dhcpd-dynamic/dnsmasq.conf

This file was deleted.

101 changes: 0 additions & 101 deletions dnsmasq-dhcpd-dynamic/init.sh

This file was deleted.

74 changes: 0 additions & 74 deletions dnsmasq-dhcpd-dynamic/smd.py

This file was deleted.

10 changes: 0 additions & 10 deletions dnsmasq-dhcpd-dynamic/update_loop.sh

This file was deleted.

Loading

0 comments on commit 0c15525

Please sign in to comment.