]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
docker: copy local files into docker image
authorMatthew Newton <matthew-git@newtoncomputing.co.uk>
Fri, 3 May 2024 15:26:32 +0000 (16:26 +0100)
committerMatthew Newton <matthew-git@newtoncomputing.co.uk>
Wed, 22 May 2024 20:12:08 +0000 (21:12 +0100)
rather than always pulling from remote

scripts/docker/docker.mk
scripts/docker/etc/docker-entrypoint.sh.alpine [new file with mode: 0755]
scripts/docker/etc/docker-entrypoint.sh.deb [new file with mode: 0755]
scripts/docker/etc/docker-entrypoint.sh.rpm [new file with mode: 0755]
scripts/docker/m4/Dockerfile.alpine.m4
scripts/docker/m4/Dockerfile.deb.m4
scripts/docker/m4/Dockerfile.m4
scripts/docker/m4/Dockerfile.rpm.m4

index 917d47536c7c44bdfee135e7e2cbd6ab6b5c99b5..77e2310f70f8c10779c9a6373d4652192a025e72 100644 (file)
@@ -83,10 +83,14 @@ define ADD_DOCKER_RULES
     .PHONY: docker.${1}.build
     docker.${1}.build:
        @echo BUILD ${1} $(DOCKER_COMMIT)
-       $(Q)docker build $(DOCKER_BUILD_ARGS) \
+       $(Q)docker buildx build \
+               $(DOCKER_BUILD_ARGS) \
+               --progress=plain \
                --build-arg=release=$(DOCKER_COMMIT) \
                -t $(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):$(DOCKER_VERSION)-${1} \
-               $(DIST_DIR)/${1}
+               -f $(DIST_DIR)/${1}/Dockerfile \
+               .
+
 endef
 
 $(foreach IMAGE,$(DOCKER_IMAGES), \
diff --git a/scripts/docker/etc/docker-entrypoint.sh.alpine b/scripts/docker/etc/docker-entrypoint.sh.alpine
new file mode 100755 (executable)
index 0000000..e0f9f6f
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+set -e
+
+PATH=/opt/sbin:/opt/bin:$PATH
+export PATH
+
+# this if will check if the first argument is a flag
+# but only works if all arguments require a hyphenated flag
+# -v; -SL; -f arg; etc will work, but not arg1 arg2
+if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then
+    set -- radiusd "$@"
+fi
+
+# check for the expected command
+if [ "$1" = 'radiusd' ]; then
+    shift
+    exec radiusd -f "$@"
+fi
+
+# debian people are likely to call "freeradius" as well, so allow that
+if [ "$1" = 'freeradius' ]; then
+    shift
+    exec radiusd -f "$@"
+fi
+
+# else default to run whatever the user wanted like "bash" or "sh"
+exec "$@"
diff --git a/scripts/docker/etc/docker-entrypoint.sh.deb b/scripts/docker/etc/docker-entrypoint.sh.deb
new file mode 100755 (executable)
index 0000000..93141b0
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+set -e
+
+# this if will check if the first argument is a flag
+# but only works if all arguments require a hyphenated flag
+# -v; -SL; -f arg; etc will work, but not arg1 arg2
+if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then
+    set -- freeradius "$@"
+fi
+
+# check for the expected command
+if [ "$1" = 'freeradius' ]; then
+    shift
+    exec freeradius -f "$@"
+fi
+
+# many people are likely to call "radiusd" as well, so allow that
+if [ "$1" = 'radiusd' ]; then
+    shift
+    exec freeradius -f "$@"
+fi
+
+# else default to run whatever the user wanted like "bash" or "sh"
+exec "$@"
diff --git a/scripts/docker/etc/docker-entrypoint.sh.rpm b/scripts/docker/etc/docker-entrypoint.sh.rpm
new file mode 100755 (executable)
index 0000000..900ad6b
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+set -e
+
+# this if will check if the first argument is a flag
+# but only works if all arguments require a hyphenated flag
+# -v; -SL; -f arg; etc will work, but not arg1 arg2
+if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then
+    set -- radiusd "$@"
+fi
+
+# check for the expected command
+if [ "$1" = 'radiusd' ]; then
+    shift
+    exec radiusd -f "$@"
+fi
+
+# debian people are likely to call "freeradius" as well, so allow that
+if [ "$1" = 'freeradius' ]; then
+    shift
+    exec radiusd -f "$@"
+fi
+
+# else default to run whatever the user wanted like "bash" or "sh"
+exec "$@"
index c03a26ad3e23d5cde4fc7db3c254d4ddb059d7ad..64c6c8ffd7e631c6854a75370f05ea17191bf466 100644 (file)
@@ -10,17 +10,23 @@ RUN apk add git gcc make
 #
 #  Create build directory
 #
-RUN mkdir -p /usr/local/src/repositories
-WORKDIR /usr/local/src/repositories
+RUN mkdir -p /usr/local/src/repositories/freeradius-server
+WORKDIR /usr/local/src/repositories/freeradius-server/
 
 #
-#  Shallow clone the FreeRADIUS source
+#  Copy the FreeRADIUS directory in
 #
-ARG source=https://github.com/FreeRADIUS/freeradius-server.git
-ARG release=v3.2.x
+COPY . .
+
+#
+#  Clean up tree - we want to build from the latest commit, not from
+#  any cruft left around on the local system
+#
+RUN git clean -fdxx \
+ && git reset --hard HEAD
+
+RUN [ -z "$release" ] || git checkout ${release}
 
-RUN git clone --depth 1 --single-branch --branch ${release} ${source}
-WORKDIR freeradius-server
 
 #
 #  Install build dependencies
@@ -75,8 +81,9 @@ RUN apk update \
     \
     && ln -s /opt/etc/raddb /etc/raddb
 
-COPY docker-entrypoint.sh /
-RUN chmod +x /docker-entrypoint.sh
+WORKDIR /
+COPY DOCKER_TOPDIR/etc/docker-entrypoint.sh.PKG_TYPE docker-entrypoint.sh
+RUN chmod +x docker-entrypoint.sh
 
 EXPOSE 1812/udp 1813/udp
 ENTRYPOINT ["/docker-entrypoint.sh"]
index a43273a6652014e003bb2b04139f07f2cc06f038..c8a5eec5c5db430d050f431693c9973544bdcd3b 100644 (file)
@@ -12,23 +12,27 @@ RUN apt-get install -y devscripts equivs git quilt gcc
 #
 #  Create build directory
 #
-RUN mkdir -p /usr/local/src/repositories
-WORKDIR /usr/local/src/repositories
+RUN mkdir -p /usr/local/src/repositories/freeradius-server
+WORKDIR /usr/local/src/repositories/freeradius-server/
 
 #
-#  Shallow clone the FreeRADIUS source
+#  Copy the FreeRADIUS directory in
 #
-ARG source=https://github.com/FreeRADIUS/freeradius-server.git
-ARG release=v3.2.x
+COPY . .
 
-RUN git clone --depth 1 --single-branch --branch ${release} ${source}
-WORKDIR freeradius-server
+#
+#  Clean up tree - we want to build from the latest commit, not from
+#  any cruft left around on the local system
+#
+RUN git clean -fdxx \
+ && git reset --hard HEAD
+
+RUN [ -z "$release" ] || git checkout ${release}
 
 #
 #  Install build dependencies
 #
-RUN git checkout ${release}; \
-    if [ -e ./debian/control.in ]; then \
+RUN if [ -e ./debian/control.in ]; then \
         debian/rules debian/control; \
     fi; \
     echo 'y' | mk-build-deps -irt'apt-get -yV' debian/control
@@ -36,12 +40,19 @@ RUN git checkout ${release}; \
 #
 #  Build the server
 #
-RUN make -j2 deb
+#  Work around fakeroot problems in Docker when building for different
+#  platforms - doesn't matter as we run as root in the container anyway.
+#
+#RUN make -j$(nproc) deb
+RUN debian/rules debian/control \
+ && dpkg-buildpackage --jobs=auto -b -uc
 
 #
 #  Clean environment and run the server
 #
 FROM ${from}
+ARG DEBIAN_FRONTEND=noninteractive
+
 COPY --from=build /usr/local/src/repositories/*.deb /tmp/
 
 ifelse(ifelse(
@@ -53,17 +64,18 @@ ARG freerad_uid=101
 ARG freerad_gid=101
 
 RUN groupadd -g ${freerad_gid} -r freerad \
   && useradd -u ${freerad_uid} -g freerad -r -M -d /etc/freeradius -s /usr/sbin/nologin freerad \
   && apt-get update \',
+ && useradd -u ${freerad_uid} -g freerad -r -M -d /etc/freeradius -s /usr/sbin/nologin freerad \
+ && apt-get update \',
 `RUN apt-get update \')
   && apt-get install -y /tmp/*.deb \
   && apt-get clean \
   && rm -r /var/lib/apt/lists/* /tmp/*.deb \
+ && apt-get install -y /tmp/*.deb \
+ && apt-get clean \
+ && rm -r /var/lib/apt/lists/* /tmp/*.deb \
     \
   && ln -s /etc/freeradius /etc/raddb
+ && ln -s /etc/freeradius /etc/raddb
 
-COPY docker-entrypoint.sh /
-RUN chmod +x /docker-entrypoint.sh
+WORKDIR /
+COPY scripts/docker/etc/docker-entrypoint.sh.PKG_TYPE docker-entrypoint.sh
+RUN chmod +x docker-entrypoint.sh
 
 EXPOSE 1812/udp 1813/udp
 ENTRYPOINT ["/docker-entrypoint.sh"]
index 873421ca230ffcbf92c7faebb6f6fa8805dad27c..f9890a1b00921397699ddc9cea0cd4eb689cbb2d 100644 (file)
@@ -8,6 +8,7 @@ dnl  they use are different - see the m4 directories for each.
 dnl
 divert(`-1')
 changequote(`[', `]')
+define([DOCKER_TOPDIR], [scripts/docker/])
 define([p_SET], [
        define([PKG_TYPE],      [$1])
        define([OS_NAME],       [$2])
index 52425c4320388426d9f39ba03c6353ea361d8266..0137483c4288aafa145dd495150f1de9bc0184a5 100644 (file)
@@ -28,17 +28,22 @@ RUN yum install -y rpmdevtools openssl dnf-utils
 #
 #  Create build directory
 #
-RUN mkdir -p /usr/local/src/repositories
-WORKDIR /usr/local/src/repositories
+RUN mkdir -p /usr/local/src/repositories/freeradius-server
+WORKDIR /usr/local/src/repositories/freeradius-server/
 
 #
-#  Shallow clone the FreeRADIUS source
+#  Copy the FreeRADIUS directory in
 #
-ARG source=https://github.com/FreeRADIUS/freeradius-server.git
-ARG release=v3.2.x
+COPY . .
 
-RUN git clone --depth 1 --single-branch --branch ${release} ${source}
-WORKDIR freeradius-server
+#
+#  Clean up tree - we want to build from the latest commit, not from
+#  any cruft left around on the local system
+#
+RUN git clean -fdxx \
+ && git reset --hard HEAD
+
+RUN [ -z "$release" ] || git checkout ${release}
 
 #
 #  Other requirements
@@ -88,9 +93,11 @@ ENV BUILDDIR=/root/rpmbuild
 RUN rpmdev-setuptree
 
 RUN ./configure
-RUN make freeradius-server-$(cat VERSION).tar.bz2
-RUN cp freeradius-server-$(cat VERSION).tar.bz2 $BUILDDIR/SOURCES/
+RUN cp VERSION /VERSION
+RUN make freeradius-server-$(cat /VERSION).tar.bz2
+RUN cp freeradius-server-$(cat /VERSION).tar.bz2 $BUILDDIR/SOURCES/
 RUN cp -r redhat/* $BUILDDIR/SOURCES/
+RUN sed -i "s/^Version:.*/Version: $(cat /VERSION)/" redhat/freeradius.spec
 RUN cp -r redhat/freeradius.spec $BUILDDIR/SPECS/
 WORKDIR $BUILDDIR
 
@@ -98,7 +105,7 @@ WORKDIR $BUILDDIR
 #  Build the server
 #
 ENV QA_RPATHS=0x0003
-RUN rpmbuild -bb --define '_release $release' "$BUILDDIR/SPECS/freeradius.spec"
+RUN rpmbuild -bb --define "_release $(cat /VERSION)" "$BUILDDIR/SPECS/freeradius.spec"
 
 RUN mkdir /root/rpms
 RUN mv $BUILDDIR/RPMS/*/*.rpm /root/rpms/
@@ -107,6 +114,7 @@ RUN mv $BUILDDIR/RPMS/*/*.rpm /root/rpms/
 #  Clean environment and run the server
 #
 FROM ${from}
+
 COPY --from=build /root/rpms /tmp/
 
 ifelse(OS_VER, `7', `', `dnl
@@ -150,8 +158,9 @@ RUN groupadd -g ${radiusd_gid} -r radiusd \
     && useradd -u ${radiusd_uid} -g radiusd -r -M -d /home/radiusd -s /sbin/nologin radiusd \')
     && yum install -y /tmp/*.rpm
 
-COPY docker-entrypoint.sh /
-RUN chmod +x /docker-entrypoint.sh
+WORKDIR /
+COPY DOCKER_TOPDIR/etc/docker-entrypoint.sh.PKG_TYPE docker-entrypoint.sh
+RUN chmod +x docker-entrypoint.sh
 
 EXPOSE 1812/udp 1813/udp
 ENTRYPOINT ["/docker-entrypoint.sh"]