Skip to content

Commit

Permalink
centos-stream-9: fix Dockerfile template
Browse files Browse the repository at this point in the history
Signed-off-by: Adphi <[email protected]>
  • Loading branch information
Adphi committed Jul 9, 2024
1 parent f711f89 commit c0e021e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
- kalilinux
- alpine
- centos
- quay.io/centos/centos:stream9

steps:
- name: Checkout
Expand Down
4 changes: 4 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func TestConfig(t *testing.T) {
image: "centos:latest",
config: configCentOS,
},
{
image: "quay.io/centos/centos:stream9",
config: configCentOS,
},
}
exec.SetDebug(true)

Expand Down
13 changes: 9 additions & 4 deletions dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
_ "embed"
"fmt"
"io"
"strconv"
"text/template"

"github.com/sirupsen/logrus"
Expand All @@ -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
Expand Down Expand Up @@ -117,3 +118,7 @@ func NewDockerfile(release OSRelease, img, password string, networkManager Netwo
}
return d, nil
}

var tplFuncs = template.FuncMap{
"atoi": strconv.Atoi,
}
3 changes: 2 additions & 1 deletion e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var (
{name: "debian:10", luks: "Please unlock disk root:"},
{name: "debian:11", luks: "Please unlock disk root:"},
{name: "centos:8", luks: "Please enter passphrase for disk"},
{name: "quay.io/centos/centos:stream9", luks: "Please enter passphrase for disk"},
}
imgNames = func() []string {
var imgs []string
Expand Down Expand Up @@ -126,7 +127,7 @@ imgs:

require := require2.New(t)

out := filepath.Join(dir, strings.NewReplacer(":", "-", ".", "-").Replace(img.name)+".qcow2")
out := filepath.Join(dir, strings.NewReplacer(":", "-", ".", "-", "/", "-").Replace(img.name)+".qcow2")

if _, err := os.Stat(out); err == nil {
require.NoError(os.Remove(out))
Expand Down
10 changes: 4 additions & 6 deletions pkg/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,10 @@ func (c *config) buildQemuCmdline() ([]string, error) {

// Need to specify the vcpu type when running qemu on arm64 platform, for security reason,
// the vcpu should be "host" instead of other names such as "cortex-a53"...
if c.arch == "aarch64" {
if runtime.GOARCH == "arm64" {
qemuArgs = append(qemuArgs, "-cpu", "host")
} else {
qemuArgs = append(qemuArgs, "-cpu", "cortex-a57")
}
if c.arch == "aarch64" && runtime.GOARCH != "arm64" {
qemuArgs = append(qemuArgs, "-cpu", "cortex-a57")
} else {
qemuArgs = append(qemuArgs, "-cpu", "host")
}

// goArch is the GOARCH equivalent of config.Arch
Expand Down
6 changes: 5 additions & 1 deletion templates/centos.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 }}

Expand Down

0 comments on commit c0e021e

Please sign in to comment.