Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

centos-stream-9: fix Dockerfile template #52

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 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 Expand Up @@ -104,6 +105,7 @@ jobs:
- debian:10
- debian:11
- centos:8
- quay.io/centos/centos:stream9
steps:
- name: Checkout
uses: actions/checkout@v3
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
Loading