2
0
mirror of https://github.com/linka-cloud/d2vm.git synced 2024-11-29 11:06:24 +00:00

merge dockerfiles

Signed-off-by: LEI WANG <ssst0n3@gmail.com>
This commit is contained in:
LEI WANG 2024-08-29 17:29:58 +08:00
parent a784b433ca
commit 0f86904ddc
No known key found for this signature in database
4 changed files with 29 additions and 92 deletions

View File

@ -286,6 +286,9 @@ func (b *builder) mountImg(ctx context.Context) error {
if strings.HasPrefix(r.VersionID, "12.") { if strings.HasPrefix(r.VersionID, "12.") {
mkfsExt4Opts = append(mkfsExt4Opts, "-O", "^has_journal,^metadata_csum") 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") logrus.Infof("mounting raw image")
o, _, err := exec.RunOut(ctx, "losetup", "--show", "-f", b.diskRaw) o, _, err := exec.RunOut(ctx, "losetup", "--show", "-f", b.diskRaw)

View File

@ -19,7 +19,6 @@ import (
"fmt" "fmt"
"io" "io"
"strconv" "strconv"
"strings"
"text/template" "text/template"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -28,9 +27,6 @@ import (
//go:embed templates/ubuntu.Dockerfile //go:embed templates/ubuntu.Dockerfile
var ubuntuDockerfile string var ubuntuDockerfile string
//go:embed templates/ubuntu12.Dockerfile
var ubuntu12Dockerfile string
//go:embed templates/debian.Dockerfile //go:embed templates/debian.Dockerfile
var debianDockerfile string var debianDockerfile string
@ -42,7 +38,6 @@ var centOSDockerfile string
var ( var (
ubuntuDockerfileTemplate = template.Must(template.New("ubuntu.Dockerfile").Funcs(tplFuncs).Parse(ubuntuDockerfile)) 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)) debianDockerfileTemplate = template.Must(template.New("debian.Dockerfile").Funcs(tplFuncs).Parse(debianDockerfile))
alpineDockerfileTemplate = template.Must(template.New("alpine.Dockerfile").Funcs(tplFuncs).Parse(alpineDockerfile)) alpineDockerfileTemplate = template.Must(template.New("alpine.Dockerfile").Funcs(tplFuncs).Parse(alpineDockerfile))
centOSDockerfileTemplate = template.Must(template.New("centos.Dockerfile").Funcs(tplFuncs).Parse(centOSDockerfile)) centOSDockerfileTemplate = template.Must(template.New("centos.Dockerfile").Funcs(tplFuncs).Parse(centOSDockerfile))
@ -95,11 +90,7 @@ func NewDockerfile(release OSRelease, img, password string, networkManager Netwo
d.tmpl = debianDockerfileTemplate d.tmpl = debianDockerfileTemplate
net = NetworkManagerIfupdown2 net = NetworkManagerIfupdown2
case ReleaseUbuntu: case ReleaseUbuntu:
if strings.HasPrefix(release.VersionID, "12.") {
d.tmpl = ubuntu12DockerfileTemplate
} else {
d.tmpl = ubuntuDockerfileTemplate d.tmpl = ubuntuDockerfileTemplate
}
if release.VersionID < "18.04" { if release.VersionID < "18.04" {
net = NetworkManagerIfupdown2 net = NetworkManagerIfupdown2
} else { } else {

View File

@ -2,13 +2,18 @@ FROM {{ .Image }}
USER root 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)"; \ RUN ARCH="$([ "$(uname -m)" = "x86_64" ] && echo amd64 || echo arm64)"; \
apt-get update && \ apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \
linux-image-virtual \ linux-image-virtual \
initramfs-tools \ initramfs-tools \
systemd-sysv \
systemd \
{{- if .Grub }} {{- if .Grub }}
grub-common \ grub-common \
grub2-common \ grub2-common \
@ -21,18 +26,29 @@ RUN ARCH="$([ "$(uname -m)" = "x86_64" ] && echo amd64 || echo arm64)"; \
{{- end }} {{- end }}
dbus \ dbus \
isc-dhcp-client \ isc-dhcp-client \
iproute2 \
iputils-ping && \ iputils-ping && \
find /boot -type l -exec rm {} \; 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" }} {{ 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 RUN systemctl preset-all
{{ end }} {{ end }}
{{ if .Password }}RUN echo "root:{{ .Password }}" | chpasswd {{ end }} {{ if .Password }}RUN echo "root:{{ .Password }}" | chpasswd {{ end }}
{{ if eq .NetworkManager "netplan" }} {{ if eq .NetworkManager "netplan" }}
RUN apt install -y netplan.io RUN apt-get install -y netplan.io
RUN mkdir -p /etc/netplan && printf '\ RUN mkdir -p /etc/netplan && printf '\
network:\n\ network:\n\
version: 2\n\ version: 2\n\
@ -47,7 +63,7 @@ network:\n\
- 8.8.4.4\n\ - 8.8.4.4\n\
' > /etc/netplan/00-netcfg.yaml ' > /etc/netplan/00-netcfg.yaml
{{ else if eq .NetworkManager "ifupdown"}} {{ 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 '\ RUN mkdir -p /etc/network && printf '\
auto eth0\n\ auto eth0\n\
allow-hotplug eth0\n\ allow-hotplug eth0\n\

View File

@ -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/*