Last active
July 24, 2025 19:19
-
-
Save doctorpangloss/548c8c556e28d6379dee65dc4b839469 to your computer and use it in GitHub Desktop.
build upnpc into a static binary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`#!/bin/bash | |
# This script creates a Dockerfile in the current directory using a heredoc, | |
# then builds a Docker image to compile a static 'upnpc' binary from the official Git repository, | |
# and finally exports the binary to a local './output' directory. | |
# Create the Dockerfile using a heredoc | |
cat <<EOF > Dockerfile | |
FROM debian:bookworm AS builder | |
# Step 1: Install build tools and git. | |
RUN apt-get update && apt-get install -y build-essential git | |
# Step 2: Clone the official miniupnp repository. | |
RUN git clone https://github.com/miniupnp/miniupnp.git /build | |
WORKDIR /build/miniupnpc | |
# Step 3: Compile only the static binary. | |
# We explicitly call the 'build/upnpc-static' target to avoid building the shared library. | |
RUN make LDFLAGS=-static build/upnpc-static | |
FROM scratch AS exporter | |
# Copy only the compiled static binary from the builder stage and rename it to 'upnpc'. | |
# The compiled binary is located in the 'build' subdirectory. | |
COPY --from=builder /build/miniupnpc/build/upnpc-static /upnpc | |
EOF | |
# Build the Docker image and export the final binary to the './output' directory | |
echo "Dockerfile created. Starting Docker build..." | |
docker build --platform=linux/amd64 --output type=local,dest=./output -t static-miniupnpc-builder . | |
# Clean up the Dockerfile | |
rm Dockerfile | |
echo "Build complete. The static 'upnpc' binary is in the './output' directory." | |
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment