diff --git a/dockerfile.go b/dockerfile.go index 7657168..cf8f3f3 100644 --- a/dockerfile.go +++ b/dockerfile.go @@ -18,6 +18,7 @@ import ( _ "embed" "fmt" "io" + "strconv" "text/template" "github.com/sirupsen/logrus" @@ -36,10 +37,10 @@ var alpineDockerfile string var centOSDockerfile string var ( - ubuntuDockerfileTemplate = template.Must(template.New("ubuntu.Dockerfile").Parse(ubuntuDockerfile)) - debianDockerfileTemplate = template.Must(template.New("debian.Dockerfile").Parse(debianDockerfile)) - alpineDockerfileTemplate = template.Must(template.New("alpine.Dockerfile").Parse(alpineDockerfile)) - centOSDockerfileTemplate = template.Must(template.New("centos.Dockerfile").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 @@ -117,3 +118,7 @@ func NewDockerfile(release OSRelease, img, password string, networkManager Netwo } return d, nil } + +var tplFuncs = template.FuncMap{ + "atoi": strconv.Atoi, +} diff --git a/templates/centos.Dockerfile b/templates/centos.Dockerfile index 79f9f82..319a46a 100644 --- a/templates/centos.Dockerfile +++ b/templates/centos.Dockerfile @@ -2,8 +2,12 @@ FROM {{ .Image }} USER root +{{ $version := atoi .Release.Version }} + +{{ if le $version 8 }} RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* && \ sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* +{{ end }} RUN yum update -y @@ -36,7 +40,7 @@ RUN dracut --no-hostonly --regenerate-all --force {{- if not .Grub }} RUN cd /boot && \ - mv $(find . -name 'vmlinuz-*') /boot/vmlinuz && \ + mv $(find {{ if le $version 8 }}.{{ else }}/{{ end }} -name 'vmlinuz*') /boot/vmlinuz && \ mv $(find . -name 'initramfs-*.img') /boot/initrd.img {{- end }}