refactor: move container generation to distro modules
This commit is contained in:
@ -53,6 +53,11 @@ func (u Ubuntu) Packages() (pkgs []string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
err = c.Build("ubuntu:"+u.release, u.envs(), u.runs())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
cmd := "apt-cache search " +
|
||||
"--names-only '^linux-image-[0-9\\.\\-]*-generic$' " +
|
||||
"| awk '{ print $1 }'"
|
||||
@ -69,17 +74,17 @@ func (u Ubuntu) Packages() (pkgs []string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func Envs(km config.Target) (envs []string) {
|
||||
func (u Ubuntu) envs() (envs []string) {
|
||||
envs = append(envs, "DEBIAN_FRONTEND=noninteractive")
|
||||
return
|
||||
}
|
||||
|
||||
func Runs(km config.Target) (commands []string) {
|
||||
func (u Ubuntu) runs() (commands []string) {
|
||||
cmdf := func(f string, s ...interface{}) {
|
||||
commands = append(commands, fmt.Sprintf(f, s...))
|
||||
}
|
||||
|
||||
if km.Distro.Release < "14.04" {
|
||||
if u.release < "14.04" {
|
||||
cmdf("sed -i 's/archive.ubuntu.com/old-releases.ubuntu.com/' " +
|
||||
"/etc/apt/sources.list")
|
||||
}
|
||||
@ -88,14 +93,14 @@ func Runs(km config.Target) (commands []string) {
|
||||
cmdf("apt-get install -y build-essential libelf-dev")
|
||||
cmdf("apt-get install -y wget git")
|
||||
|
||||
if km.Distro.Release == "12.04" {
|
||||
if u.release == "12.04" {
|
||||
cmdf("apt-get install -y grub")
|
||||
cmdf("cp /bin/true /usr/sbin/grub-probe")
|
||||
cmdf("mkdir -p /boot/grub")
|
||||
cmdf("touch /boot/grub/menu.lst")
|
||||
}
|
||||
|
||||
if km.Distro.Release < "14.04" {
|
||||
if u.release < "14.04" {
|
||||
return
|
||||
}
|
||||
|
||||
|
22
distro/ubuntu/ubuntu_test.go
Normal file
22
distro/ubuntu/ubuntu_test.go
Normal file
@ -0,0 +1,22 @@
|
||||
package ubuntu
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"code.dumpstack.io/tools/out-of-tree/distro"
|
||||
)
|
||||
|
||||
func TestUbuntu(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
u := Ubuntu{release: "22.04", container: "out_of_tree_ubuntu_22__04"}
|
||||
|
||||
assert.Equal(u.ID(), distro.Ubuntu)
|
||||
assert.Equal(u.Release(), "22.04")
|
||||
|
||||
assert.True(u.Equal(distro.Distro{Release: "22.04", ID: distro.Ubuntu}))
|
||||
|
||||
assert.NotEmpty(u.Packages())
|
||||
}
|
Reference in New Issue
Block a user