mirror of
https://github.com/rancher/os.git
synced 2025-09-01 14:48:55 +00:00
move auto-formatter drive selection logic to os-autoformat container
and get rid of: - machine-rancheros.iso, - special case in build-images, - some bootstrap.go code
This commit is contained in:
@@ -82,6 +82,9 @@ func imagesFromConfig(cfg *config.Config) []string {
|
|||||||
for _, service := range cfg.BootstrapContainers {
|
for _, service := range cfg.BootstrapContainers {
|
||||||
imagesMap[service.Image] = 1
|
imagesMap[service.Image] = 1
|
||||||
}
|
}
|
||||||
|
for _, service := range cfg.Autoformat {
|
||||||
|
imagesMap[service.Image] = 1
|
||||||
|
}
|
||||||
for _, service := range cfg.SystemContainers {
|
for _, service := range cfg.SystemContainers {
|
||||||
imagesMap[service.Image] = 1
|
imagesMap[service.Image] = 1
|
||||||
}
|
}
|
||||||
|
@@ -52,7 +52,8 @@ type Repositories map[string]Repository
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
Environment map[string]string `yaml:"environment,omitempty"`
|
Environment map[string]string `yaml:"environment,omitempty"`
|
||||||
Services map[string]*project.ServiceConfig `yaml:"services,omitempty"`
|
Services map[string]*project.ServiceConfig `yaml:"services,omitempty"`
|
||||||
BootstrapContainers map[string]*project.ServiceConfig `yaml:"bootstrap_containers,omitempty"`
|
BootstrapContainers map[string]*project.ServiceConfig `yaml:"bootstrap,omitempty"`
|
||||||
|
Autoformat map[string]*project.ServiceConfig `yaml:"autoformat,omitempty"`
|
||||||
BootstrapDocker DockerConfig `yaml:"bootstrap_docker,omitempty"`
|
BootstrapDocker DockerConfig `yaml:"bootstrap_docker,omitempty"`
|
||||||
CloudInit CloudInit `yaml:"cloud_init,omitempty"`
|
CloudInit CloudInit `yaml:"cloud_init,omitempty"`
|
||||||
Console ConsoleConfig `yaml:"console,omitempty"`
|
Console ConsoleConfig `yaml:"console,omitempty"`
|
||||||
@@ -124,6 +125,7 @@ type StateConfig struct {
|
|||||||
Dev string `yaml:"dev,omitempty"`
|
Dev string `yaml:"dev,omitempty"`
|
||||||
Required bool `yaml:"required,omitempty"`
|
Required bool `yaml:"required,omitempty"`
|
||||||
Autoformat []string `yaml:"autoformat,omitempty"`
|
Autoformat []string `yaml:"autoformat,omitempty"`
|
||||||
|
FormatZero bool `yaml:"formatzero,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CloudInit struct {
|
type CloudInit struct {
|
||||||
|
@@ -1,102 +1,28 @@
|
|||||||
// +build linux
|
|
||||||
|
|
||||||
package init
|
package init
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"fmt"
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/rancherio/os/config"
|
"github.com/rancherio/os/config"
|
||||||
"github.com/rancherio/os/docker"
|
"github.com/rancherio/os/docker"
|
||||||
"github.com/rancherio/os/util"
|
"github.com/rancherio/os/util"
|
||||||
"github.com/rancherio/rancher-compose/librcompose/project"
|
"github.com/rancherio/rancher-compose/librcompose/project"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const boot2dockerMagic = "boot2docker, please format-me"
|
|
||||||
|
|
||||||
func autoformat(cfg *config.Config) error {
|
func autoformat(cfg *config.Config) error {
|
||||||
if len(cfg.State.Autoformat) == 0 || util.ResolveDevice(cfg.State.Dev) != "" {
|
if len(cfg.State.Autoformat) == 0 || util.ResolveDevice(cfg.State.Dev) != "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
AUTOFORMAT := "AUTOFORMAT=" + strings.Join(cfg.State.Autoformat, " ")
|
||||||
var format string
|
FORMATZERO := "FORMATZERO=" + fmt.Sprint(cfg.State.FormatZero)
|
||||||
|
cfg.Autoformat["autoformat"].Environment = project.NewMaporEqualSlice([]string{AUTOFORMAT, FORMATZERO})
|
||||||
outer:
|
err := docker.RunServices("autoformat", cfg, cfg.Autoformat)
|
||||||
for _, dev := range cfg.State.Autoformat {
|
return err
|
||||||
log.Infof("Checking %s to auto-format", dev)
|
|
||||||
if _, err := os.Stat(dev); os.IsNotExist(err) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := os.Open(dev)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
buffer := make([]byte, 1048576, 1048576)
|
|
||||||
c, err := f.Read(buffer)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if c != 1048576 {
|
|
||||||
log.Infof("%s not right size", dev)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
boot2docker := false
|
|
||||||
|
|
||||||
if strings.HasPrefix(string(buffer[:len(boot2dockerMagic)]), boot2dockerMagic) {
|
|
||||||
boot2docker = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if boot2docker == false {
|
|
||||||
for _, b := range buffer {
|
|
||||||
if b != 0 {
|
|
||||||
log.Infof("%s not empty", dev)
|
|
||||||
continue outer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
format = dev
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if format != "" {
|
|
||||||
log.Infof("Auto formatting : %s", format)
|
|
||||||
|
|
||||||
// copy
|
|
||||||
udev := *cfg.BootstrapContainers["udev"]
|
|
||||||
udev.Links = project.NewMaporColonSlice(append(udev.Links.Slice(), "autoformat"))
|
|
||||||
udev.LogDriver = "json-file"
|
|
||||||
|
|
||||||
err := docker.RunServices("autoformat", cfg, map[string]*project.ServiceConfig{
|
|
||||||
"autoformat": {
|
|
||||||
Net: "none",
|
|
||||||
Privileged: true,
|
|
||||||
Image: "rancher/os-autoformat:" + config.VERSION,
|
|
||||||
Command: project.NewCommand(format),
|
|
||||||
Labels: project.NewSliceorMap(map[string]string{
|
|
||||||
config.DETACH: "false",
|
|
||||||
config.SCOPE: config.SYSTEM,
|
|
||||||
}),
|
|
||||||
LogDriver: "json-file",
|
|
||||||
Environment: project.NewMaporEqualSlice([]string{
|
|
||||||
"MAGIC=" + boot2dockerMagic,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
"udev": &udev,
|
|
||||||
})
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func runBootstrapContainers(cfg *config.Config) error {
|
func runBootstrapContainers(cfg *config.Config) error {
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
bootstrap_containers:
|
bootstrap:
|
||||||
udev:
|
udev:
|
||||||
image: rancher/os-udev:v0.4.0-dev
|
image: rancher/os-udev:v0.4.0-dev
|
||||||
command: []
|
command: []
|
||||||
@@ -18,6 +18,42 @@ bootstrap_containers:
|
|||||||
- /dev:/host/dev
|
- /dev:/host/dev
|
||||||
- /lib/modules:/lib/modules
|
- /lib/modules:/lib/modules
|
||||||
- /lib/firmware:/lib/firmware
|
- /lib/firmware:/lib/firmware
|
||||||
|
autoformat:
|
||||||
|
autoformat:
|
||||||
|
image: rancher/os-autoformat:v0.4.0-dev
|
||||||
|
command: []
|
||||||
|
dns: []
|
||||||
|
dns_search: []
|
||||||
|
env_file: []
|
||||||
|
environment: []
|
||||||
|
labels:
|
||||||
|
io.rancher.os.detach: false
|
||||||
|
io.rancher.os.scope: system
|
||||||
|
links: []
|
||||||
|
log_driver: json-file
|
||||||
|
net: none
|
||||||
|
privileged: true
|
||||||
|
volumes: []
|
||||||
|
udev:
|
||||||
|
image: rancher/os-udev:v0.4.0-dev
|
||||||
|
command: []
|
||||||
|
dns: []
|
||||||
|
dns_search: []
|
||||||
|
env_file: []
|
||||||
|
environment: []
|
||||||
|
labels:
|
||||||
|
io.rancher.os.detach: false
|
||||||
|
io.rancher.os.scope: system
|
||||||
|
links:
|
||||||
|
- autoformat
|
||||||
|
log_driver: json-file
|
||||||
|
net: host
|
||||||
|
uts: host
|
||||||
|
privileged: true
|
||||||
|
volumes:
|
||||||
|
- /dev:/host/dev
|
||||||
|
- /lib/modules:/lib/modules
|
||||||
|
- /lib/firmware:/lib/firmware
|
||||||
bootstrap_docker:
|
bootstrap_docker:
|
||||||
args: [docker, -d, -s, overlay, -b, none, --restart=false, -g, /var/lib/system-docker,
|
args: [docker, -d, -s, overlay, -b, none, --restart=false, -g, /var/lib/system-docker,
|
||||||
-G, root, -H, 'unix:///var/run/system-docker.sock']
|
-G, root, -H, 'unix:///var/run/system-docker.sock']
|
||||||
|
@@ -40,7 +40,7 @@ chmod +x ${INITRD_DIR}/docker #ini
|
|||||||
|
|
||||||
ln -sf bin/rancheros ./ros
|
ln -sf bin/rancheros ./ros
|
||||||
|
|
||||||
for i in $(./ros c images -i os-config.yml) rancher/os-autoformat:${VERSION}; do
|
for i in $(./ros c images -i os-config.yml); do
|
||||||
docker pull ${i}
|
docker pull ${i}
|
||||||
done
|
done
|
||||||
docker save $(./ros c images -i os-config.yml) rancher/os-autoformat:${VERSION} > ${INITRD_DIR}/images.tar #initrd2-images: /images.tar
|
docker save $(./ros c images -i os-config.yml) > ${INITRD_DIR}/images.tar #initrd2-images: /images.tar
|
||||||
|
@@ -30,7 +30,7 @@ default rancheros
|
|||||||
label rancheros
|
label rancheros
|
||||||
kernel /boot/vmlinuz
|
kernel /boot/vmlinuz
|
||||||
initrd /boot/initrd
|
initrd /boot/initrd
|
||||||
append quiet rancher.password=rancher
|
append quiet rancher.password=rancher rancher.state.autoformat=[/dev/sda,/dev/vda]
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
cd ${CD}
|
cd ${CD}
|
||||||
@@ -44,24 +44,6 @@ xorriso \
|
|||||||
-isohybrid-mbr /usr/lib/syslinux/isohdpfx.bin \
|
-isohybrid-mbr /usr/lib/syslinux/isohdpfx.bin \
|
||||||
-o ${DIST}/artifacts/rancheros.iso $(pwd)
|
-o ${DIST}/artifacts/rancheros.iso $(pwd)
|
||||||
|
|
||||||
cat > ${CD}/boot/isolinux/isolinux.cfg << EOF
|
|
||||||
default rancheros
|
|
||||||
label rancheros
|
|
||||||
kernel /boot/vmlinuz
|
|
||||||
initrd /boot/initrd
|
|
||||||
append quiet rancher.password=rancher rancher.state.autoformat=[/dev/sda,/dev/vda]
|
|
||||||
EOF
|
|
||||||
|
|
||||||
cd ${CD}
|
|
||||||
xorriso \
|
|
||||||
-publisher "Rancher Labs, Inc." \
|
|
||||||
-as mkisofs \
|
|
||||||
-l -J -R -V "RancherOS" \
|
|
||||||
-no-emul-boot -boot-load-size 4 -boot-info-table \
|
|
||||||
-b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat \
|
|
||||||
-isohybrid-mbr /usr/lib/syslinux/isohdpfx.bin \
|
|
||||||
-o ${DIST}/artifacts/machine-rancheros.iso $(pwd)
|
|
||||||
|
|
||||||
|
|
||||||
if [ -e ${DIST}/artficats/iso-checksums.txt ]; then
|
if [ -e ${DIST}/artficats/iso-checksums.txt ]; then
|
||||||
rm ${DIST}/artficats/iso-checksums.txt
|
rm ${DIST}/artficats/iso-checksums.txt
|
||||||
|
Reference in New Issue
Block a user