From 0f86904ddcba27bbb8d8cfc44bcc218057958367 Mon Sep 17 00:00:00 2001 From: LEI WANG Date: Thu, 29 Aug 2024 17:29:58 +0800 Subject: [PATCH] merge dockerfiles Signed-off-by: LEI WANG --- builder.go | 3 ++ dockerfile.go | 19 +++------ templates/ubuntu.Dockerfile | 26 ++++++++++--- templates/ubuntu12.Dockerfile | 73 ----------------------------------- 4 files changed, 29 insertions(+), 92 deletions(-) delete mode 100644 templates/ubuntu12.Dockerfile diff --git a/builder.go b/builder.go index 942b7df..b452d4e 100644 --- a/builder.go +++ b/builder.go @@ -286,6 +286,9 @@ func (b *builder) mountImg(ctx context.Context) error { if strings.HasPrefix(r.VersionID, "12.") { mkfsExt4Opts = append(mkfsExt4Opts, "-O", "^has_journal,^metadata_csum") } + if strings.HasPrefix(r.VersionID, "14.") { + mkfsExt4Opts = append(mkfsExt4Opts, "-O", "^metadata_csum") + } } logrus.Infof("mounting raw image") o, _, err := exec.RunOut(ctx, "losetup", "--show", "-f", b.diskRaw) diff --git a/dockerfile.go b/dockerfile.go index a79e20e..2ffd251 100644 --- a/dockerfile.go +++ b/dockerfile.go @@ -19,7 +19,6 @@ import ( "fmt" "io" "strconv" - "strings" "text/template" "github.com/sirupsen/logrus" @@ -28,9 +27,6 @@ import ( //go:embed templates/ubuntu.Dockerfile var ubuntuDockerfile string -//go:embed templates/ubuntu12.Dockerfile -var ubuntu12Dockerfile string - //go:embed templates/debian.Dockerfile var debianDockerfile string @@ -41,11 +37,10 @@ var alpineDockerfile string var centOSDockerfile string var ( - ubuntuDockerfileTemplate = template.Must(template.New("ubuntu.Dockerfile").Funcs(tplFuncs).Parse(ubuntuDockerfile)) - ubuntu12DockerfileTemplate = template.Must(template.New("ubuntu12.Dockerfile").Funcs(tplFuncs).Parse(ubuntu12Dockerfile)) - debianDockerfileTemplate = template.Must(template.New("debian.Dockerfile").Funcs(tplFuncs).Parse(debianDockerfile)) - alpineDockerfileTemplate = template.Must(template.New("alpine.Dockerfile").Funcs(tplFuncs).Parse(alpineDockerfile)) - centOSDockerfileTemplate = template.Must(template.New("centos.Dockerfile").Funcs(tplFuncs).Parse(centOSDockerfile)) + ubuntuDockerfileTemplate = template.Must(template.New("ubuntu.Dockerfile").Funcs(tplFuncs).Parse(ubuntuDockerfile)) + debianDockerfileTemplate = template.Must(template.New("debian.Dockerfile").Funcs(tplFuncs).Parse(debianDockerfile)) + alpineDockerfileTemplate = template.Must(template.New("alpine.Dockerfile").Funcs(tplFuncs).Parse(alpineDockerfile)) + centOSDockerfileTemplate = template.Must(template.New("centos.Dockerfile").Funcs(tplFuncs).Parse(centOSDockerfile)) ) type NetworkManager string @@ -95,11 +90,7 @@ func NewDockerfile(release OSRelease, img, password string, networkManager Netwo d.tmpl = debianDockerfileTemplate net = NetworkManagerIfupdown2 case ReleaseUbuntu: - if strings.HasPrefix(release.VersionID, "12.") { - d.tmpl = ubuntu12DockerfileTemplate - } else { - d.tmpl = ubuntuDockerfileTemplate - } + d.tmpl = ubuntuDockerfileTemplate if release.VersionID < "18.04" { net = NetworkManagerIfupdown2 } else { diff --git a/templates/ubuntu.Dockerfile b/templates/ubuntu.Dockerfile index 1589379..d634455 100644 --- a/templates/ubuntu.Dockerfile +++ b/templates/ubuntu.Dockerfile @@ -2,13 +2,18 @@ FROM {{ .Image }} USER root +{{ if le .Release.VersionID "14.04" }} +# restore initctl +RUN rm /sbin/initctl && dpkg-divert --rename --remove /sbin/initctl +# setup ttyS0 +RUN cp /etc/init/tty1.conf /etc/init/ttyS0.conf && sed -i s/tty1/ttyS0/g /etc/init/ttyS0.conf +{{ end }} + RUN ARCH="$([ "$(uname -m)" = "x86_64" ] && echo amd64 || echo arm64)"; \ apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ linux-image-virtual \ initramfs-tools \ - systemd-sysv \ - systemd \ {{- if .Grub }} grub-common \ grub2-common \ @@ -21,18 +26,29 @@ RUN ARCH="$([ "$(uname -m)" = "x86_64" ] && echo amd64 || echo arm64)"; \ {{- end }} dbus \ isc-dhcp-client \ - iproute2 \ iputils-ping && \ find /boot -type l -exec rm {} \; +{{ if gt .Release.VersionID "14.04" }} +RUN ARCH="$([ "$(uname -m)" = "x86_64" ] && echo amd64 || echo arm64)"; \ + apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ + iproute2 \ +{{ end }} + {{ if gt .Release.VersionID "16.04" }} +RUN ARCH="$([ "$(uname -m)" = "x86_64" ] && echo amd64 || echo arm64)"; \ + apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ + systemd-sysv \ + systemd RUN systemctl preset-all {{ end }} {{ if .Password }}RUN echo "root:{{ .Password }}" | chpasswd {{ end }} {{ if eq .NetworkManager "netplan" }} -RUN apt install -y netplan.io +RUN apt-get install -y netplan.io RUN mkdir -p /etc/netplan && printf '\ network:\n\ version: 2\n\ @@ -47,7 +63,7 @@ network:\n\ - 8.8.4.4\n\ ' > /etc/netplan/00-netcfg.yaml {{ else if eq .NetworkManager "ifupdown"}} -RUN if [ -z "$(apt-cache madison ifupdown-ng 2> /dev/nul)" ]; then apt install -y ifupdown; else apt install -y ifupdown-ng; fi +RUN if [ -z "$(apt-cache madison ifupdown-ng 2> /dev/nul)" ]; then apt-get install -y ifupdown; else apt-get install -y ifupdown-ng; fi RUN mkdir -p /etc/network && printf '\ auto eth0\n\ allow-hotplug eth0\n\ diff --git a/templates/ubuntu12.Dockerfile b/templates/ubuntu12.Dockerfile deleted file mode 100644 index 528fce4..0000000 --- a/templates/ubuntu12.Dockerfile +++ /dev/null @@ -1,73 +0,0 @@ -FROM {{ .Image }} - -USER root - -# restore initctl -RUN rm /sbin/initctl && dpkg-divert --rename --remove /sbin/initctl - -# setup ttyS0 -RUN cp /etc/init/tty1.conf /etc/init/ttyS0.conf && sed -i s/tty1/ttyS0/g /etc/init/ttyS0.conf - -RUN ARCH="$([ "$(uname -m)" = "x86_64" ] && echo amd64 || echo arm64)"; \ - apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ - linux-image-virtual \ - initramfs-tools \ -{{- if .Grub }} - grub-common \ - grub2-common \ -{{- end }} -{{- if .GrubBIOS }} - grub-pc-bin \ -{{- end }} -{{- if .GrubEFI }} - grub-efi-${ARCH}-bin \ -{{- end }} - dbus \ - isc-dhcp-client \ - iputils-ping && \ - find /boot -type l -exec rm {} \; - -{{ if gt .Release.VersionID "16.04" }} -RUN systemctl preset-all -{{ end }} - -{{ if .Password }}RUN echo "root:{{ .Password }}" | chpasswd {{ end }} - -{{ if eq .NetworkManager "netplan" }} -RUN apt install -y netplan.io -RUN mkdir -p /etc/netplan && printf '\ -network:\n\ - version: 2\n\ - renderer: networkd\n\ - ethernets:\n\ - eth0:\n\ - dhcp4: true\n\ - dhcp-identifier: mac\n\ - nameservers:\n\ - addresses:\n\ - - 8.8.8.8\n\ - - 8.8.4.4\n\ -' > /etc/netplan/00-netcfg.yaml -{{ else if eq .NetworkManager "ifupdown"}} -RUN if [ -z "$(apt-cache madison ifupdown-ng 2> /dev/nul)" ]; then apt-get install -y ifupdown; else apt-get install -y ifupdown-ng; fi -RUN mkdir -p /etc/network && printf '\ -auto eth0\n\ -allow-hotplug eth0\n\ -iface eth0 inet dhcp\n\ -' > /etc/network/interfaces -{{ end }} - -{{- if .Luks }} -RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends cryptsetup-initramfs && \ - update-initramfs -u -v -{{- end }} - -# needs to be after update-initramfs -{{- if not .Grub }} -RUN mv $(find /boot -name 'vmlinuz-*') /boot/vmlinuz && \ - mv $(find /boot -name 'initrd.img-*') /boot/initrd.img -{{- end }} - -RUN apt-get clean && \ - rm -rf /var/lib/apt/lists/*