From d11f8b124011ce00df6f006d53c8b6b29a986e95 Mon Sep 17 00:00:00 2001 From: mek <> Date: Mon, 10 Apr 2023 18:01:35 +0000 Subject: [PATCH] Cleaned up a few things and added a make test to do a quick build test FossilOrigin-Name: 1a21b01b33244f3d652dece381edfb2b3b36744ae4c0ae0fc861b882484b36a1 --- Makefile | 18 +++-- README.md | 2 +- alpine.md | 4 +- scripts/build-docker.sh | 26 ++++++++ ubi9+epel.md | 144 ---------------------------------------- ubuntu.md | 2 +- 6 files changed, 41 insertions(+), 155 deletions(-) create mode 100755 scripts/build-docker.sh delete mode 100644 ubi9+epel.md diff --git a/Makefile b/Makefile index c36f969..4df0361 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,22 @@ TANGLE=tclsh scripts/tangle.tcl -DOCKERFILES=ubi9+epel.dockerfile ubuntu.dockerfile fossil.dockerfile opensuse.dockerfile alpine.dockerfile +ALL=ubi9epel ubuntu fossil opensuse alpine -.SUFFIXES: .md .dockerfile +.SUFFIXES: .md .dockerfile .test .md.dockerfile: @$(TANGLE) -R $@ $< > $@ +.md.test: + $(TANGLE) -R $(@:%.test=%.dockerfile) $< | docker build -t mek:$@ -f - . -.PHONY: default default: all -.PHONY: all -all: $(DOCKERFILES) +all: $(ALL:%=%.dockerfile) + +test: $(ALL:%=%.test) -.PHONY: clean clean: @rm -f *~ - @rm -rf $(DOCKERFILES) + @rm -rf $(ALL:%=%.dockerfile) + +.PHONY: default all clean test + diff --git a/README.md b/README.md index ef8b504..bab6b44 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ I like to insure that my containers follow a few simple rules. ## Docker Files - * [ubi9+epel](ubi9+epel.md) + * [ubi9epel](ubi9epel.md) * Redhat's Universal Base Image (UBI) for RHEL9, with epel installed and read for use. * [ubuntu](ubuntu.md) * Yes, I use Ubuntu from time to time. diff --git a/alpine.md b/alpine.md index 7ab3ae1..cb51c62 100644 --- a/alpine.md +++ b/alpine.md @@ -109,5 +109,5 @@ WORKDIR ${baseDIR} ``` ## build and test `docker build -t mek:alpine -f alpine.dockerfile .` -`docker run --rm -it mek:alpine /bin/sh`` -``` \ No newline at end of file +`docker run --rm -it mek:alpine /bin/sh` +``` diff --git a/scripts/build-docker.sh b/scripts/build-docker.sh new file mode 100755 index 0000000..54f3dd0 --- /dev/null +++ b/scripts/build-docker.sh @@ -0,0 +1,26 @@ +#!/bin/sh +set -euax + +## check the usage and get the image to test +if [ $# -ne 1 ] ; then + echo 1>&2 "usage: $0 image" + exit 1 +fi +image=$1 + +# Get the toplevel directory of the git repo +repo_dir=`git rev-parse --show-toplevel` + +# See if the file for the image is available + +if [ ! -f "${repo_dir}/${image}.md" ] ; then + echo 1>&2 "could not find the file for ${image}" + exit 1 +fi + +# Let's try to build it. +echo "attempting to build ${image} in ${repo_dir}" +${repo_dir}/scripts/tangle.tcl -R "${image}.dockerfile" "${image}.md" | \ + docker build -t test:${image} -f - . + +exit 0 diff --git a/ubi9+epel.md b/ubi9+epel.md deleted file mode 100644 index 7213d6c..0000000 --- a/ubi9+epel.md +++ /dev/null @@ -1,144 +0,0 @@ -# A simple base docker image for RH's UBI9 Docker Image - -Redhat has recently made their Universal Base Image (UBI) availabe -on the Docker Registery (docker.io/libarary/redhat/ubi9). - -Of course, it doesn't have the ELPL repository enabled on it, which is -something I use consistently with the RHel based images. - -There are a few other things I liked to do with my docker images to help -make development and usage a bit more standardized. - -## UBI9+EPEL Docker Image - -### Setup FROM and enable a version choice. - -First let's set the where we'll pull from. I use `podman` and `docker` equally, so on I give the full path to the FROM image. - -An `ARG` for the version, `VER` is there. This can be overridden with `--build-arg 'VER='`. - -``` -<>= -ARG VER=latest -FROM docker.io/redhat/ubi9:${VER} -@ % def VER -``` - -### Setup user specific arguments. - -Setup a base username, uid, gid, and work directory with some defaults. All of these can be overridden with `-build-arg "ARG=VALUE"`. - -``` -<>= -ARG baseUSER="mat.kovach" -ARG baseUID=5000 -ARG baseGID=5000 -ARG baseDIR="/work" -@ -``` - -### Add user and work directory - -You'll need to be careful here to not change a current directory. For example, do not set baseDIR="/bin". - -Add the group, user, (with the home directory of the user ad the work directory) and insure the proper ownership on the work directory. - -``` -<>= -RUN groupadd -g ${baseGID} ${baseUSER} && \ - useradd -c 'work user' -m -u ${baseUID} \ - -g ${baseGID} -d ${baseDIR} ${baseUSER} && \ - chown -R ${baseUID}:${baseGID} ${baseDIR} -@ -``` - -### Add repos and update software. - -First, we'll add the EPEL repo. If you have additional repos you want to -enable, add them here. - -``` -<>= -RUN dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm && \ - /usr/bin/crb enable && \ - dnf update -y -@ -``` - -### Addtional root changes - -We are still root at this point, this is where we add software, make -additional changes, etc. - -``` -<>= -RUN dnf install -y ed joe tcl tcllib -@ -``` - -The different sections are setup based on how often they may be changed. -The more likely some will change, the further down they should be to help -minimize the layers that need to be rebuilt. - -### Make sure we the user, volume, and workdir setup - -``` -<>= -USER ${baseUSER} -VOLUME ${baseDIR} -WORKDIR ${baseDIR} -# you can add entry point, etc. here. -@ -``` - -### Pulling it all together - -``` -<>= -<> -<> -<> -<> -<> -<> -@ -``` - -## build and test - -`docker build -t mek:ubi9 -f ubi9-epel.dockerfile .` - -`docker run --rm -it mek:ubi9 /bin/bash` - -``` -$ docker run --rm -it mek:ubi9 /bin/bash -[mat.kovach@4bd996f669b2 ~]$ pwd -/work -[mat.kovach@4bd996f669b2 ~]$ id -a -uid=5000(mat.kovach) gid=5000(mat.kovach) groups=5000(mat.kovach) -$ dnf repolist -Not root, Subscription Management repositories not updated - -This system is not registered with an entitlement server. You can use subscription-manager to register. - -repo id repo name -epel Extra Packages for Enterprise Linux 9 - x86_64 -ubi-9-appstream-rpms Red Hat Universal Base Image 9 (RPMs) - AppStream -ubi-9-baseos-rpms Red Hat Universal Base Image 9 (RPMs) - BaseOS -ubi-9-codeready-builder Red Hat Universal Base Image 9 (RPMs) - CodeReady Builder -``` - -Now let's try using my current working directory inside the container. - -``` -$ docker run --rm -it -v $(PWD):/work mek:ubi9 /bin/bash -bash-5.1$ pwd -/work -bash-5.1$ ls -l *.md --rw-r--r-- 1 mat.kovach mat.kovach 3474 Apr 5 14:57 UBI9-DOCKER.md -bash-5.1$ touch test -bash-5.1$ exit -exit -Mats-MBP:docker mek$ ls -l test --rw-r--r--@ 1 mek staff 0 Apr 5 11:06 test -``` diff --git a/ubuntu.md b/ubuntu.md index 1ac2e75..b2cfc1e 100644 --- a/ubuntu.md +++ b/ubuntu.md @@ -66,7 +66,7 @@ additional changes, etc. <>= RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get -qq upgrade && \ - DEBIAN_FRONTEND=noninteractive apt-get -qq ed joe tcl + DEBIAN_FRONTEND=noninteractive apt-get -qq install ed joe tcl @ ```