1
0
mirror of https://github.com/rancher/os.git synced 2025-08-31 22:32:14 +00:00

Fix installation and trim packages

This commit is contained in:
Darren Shepherd
2021-11-03 22:06:12 -07:00
parent 85e1eb9320
commit f35b3697c3
11 changed files with 167 additions and 43 deletions

View File

@@ -1,11 +1,14 @@
FROM opensuse/leap:15.3 AS build FROM opensuse/leap:15.3 AS build
RUN zypper ref RUN zypper ref
RUN zypper in -y squashfs xorriso go1.16 upx busybox-static curl tar git gzip RUN zypper in -y squashfs xorriso go1.16 upx busybox-static curl tar git gzip
RUN curl -Lo /usr/bin/luet https://github.com/mudler/luet/releases/download/0.20.5/luet-0.20.5-linux-$(go env GOARCH) && \ RUN curl -Lo /usr/bin/luet https://github.com/mudler/luet/releases/download/0.20.6/luet-0.20.6-linux-$(go env GOARCH) && \
chmod +x /usr/bin/luet chmod +x /usr/bin/luet && \
upx /usr/bin/luet
RUN curl -Lo /usr/bin/rancherd https://github.com/rancher/rancherd/releases/download/v0.0.1-alpha11/rancherd-$(go env GOARCH) && \ RUN curl -Lo /usr/bin/rancherd https://github.com/rancher/rancherd/releases/download/v0.0.1-alpha11/rancherd-$(go env GOARCH) && \
chmod +x /usr/bin/rancherd chmod +x /usr/bin/rancherd && \
RUN curl -L https://get.helm.sh/helm-v3.7.1-linux-$(go env GOARCH).tar.gz | tar xzf - -C /usr/bin --strip-components=1 upx /usr/bin/rancherd
RUN curl -L https://get.helm.sh/helm-v3.7.1-linux-$(go env GOARCH).tar.gz | tar xzf - -C /usr/bin --strip-components=1 && \
upx /usr/bin/helm
COPY go.mod go.sum /usr/src/ COPY go.mod go.sum /usr/src/
COPY cmd /usr/src/cmd COPY cmd /usr/src/cmd
COPY pkg /usr/src/pkg COPY pkg /usr/src/pkg
@@ -48,8 +51,10 @@ RUN ["/usr/bin/busybox", "rm", "-rf", "/var", "/etc/ssl", "/usr/bin/busybox"]
# Make OS image # Make OS image
FROM opensuse/leap:15.3 as os FROM opensuse/leap:15.3 as os
RUN sed -i -s 's/^# rpm.install.excludedocs/rpm.install.excludedocs/' /etc/zypp/zypp.conf
RUN zypper ref RUN zypper ref
RUN zypper in -y \ RUN zypper dup -y
RUN zypper in -y -- \
apparmor-parser \ apparmor-parser \
avahi \ avahi \
bash-completion \ bash-completion \
@@ -69,7 +74,6 @@ RUN zypper in -y \
grub2-x86_64-efi \ grub2-x86_64-efi \
haveged \ haveged \
hdparm \ hdparm \
iotop \
iproute2 \ iproute2 \
iptables \ iptables \
iputils \ iputils \
@@ -90,7 +94,7 @@ RUN zypper in -y \
kernel-firmware-qlogic \ kernel-firmware-qlogic \
kernel-firmware-realtek \ kernel-firmware-realtek \
kernel-firmware-usb-network \ kernel-firmware-usb-network \
libtspi1 \ -kubic-locale-archive \
less \ less \
lshw \ lshw \
lsof \ lsof \
@@ -98,43 +102,48 @@ RUN zypper in -y \
lvm2 \ lvm2 \
mdadm \ mdadm \
multipath-tools \ multipath-tools \
nano \
netcat-openbsd \ netcat-openbsd \
nfs-utils \ nfs-utils \
open-iscsi \ open-iscsi \
open-vm-tools \ open-vm-tools \
openssh \
parted \ parted \
-perl \
pciutils \ pciutils \
pigz \ pigz \
policycoreutils \
procps \ procps \
psmisc \ psmisc \
python-azure-agent \
qemu-guest-agent \ qemu-guest-agent \
rng-tools \
rsync \ rsync \
squashfs \ squashfs \
strace \ strace \
SUSEConnect \
sysstat \ sysstat \
systemd \ systemd \
systemd-presets-branding-openSUSE \
-systemd-presets-branding-MicroOS \
systemd-sysvinit \ systemd-sysvinit \
tar \ tar \
tcpdump \
timezone \ timezone \
vim \ vim-small \
which \ which \
zstd zstd
# Copy in some local OS customizations # Copy in some local OS customizations
COPY opensuse/files / COPY opensuse/files /
ARG IMAGE_TAG=latest
RUN cat /etc/os-release.tmpl | env \
"VERSION=${IMAGE_TAG}" \
"VERSION_ID=$(echo ${IMAGE_TAG} | sed s/^v//)" \
"PRETTY_NAME=RancherOS ${IMAGE_TAG}" \
envsubst > /etc/os-release && \
rm /etc/os-release.tmpl
# Starting from here are the lines needed for RancherOS to work # Starting from here are the lines needed for RancherOS to work
# IMPORTANT: Setup rancheros-release used for versioning/upgrade. The # IMPORTANT: Setup rancheros-release used for versioning/upgrade. The
# values here should reflect the tag of the image being built # values here should reflect the tag of the image being built
ARG IMAGE_REPO=norepo ARG IMAGE_REPO=norepo
ARG IMAGE_TAG=latest
RUN echo "IMAGE_REPO=${IMAGE_REPO}" > /usr/lib/rancheros-release && \ RUN echo "IMAGE_REPO=${IMAGE_REPO}" > /usr/lib/rancheros-release && \
echo "IMAGE_TAG=${IMAGE_TAG}" >> /usr/lib/rancheros-release && \ echo "IMAGE_TAG=${IMAGE_TAG}" >> /usr/lib/rancheros-release && \
echo "IMAGE=${IMAGE_REPO}:${IMAGE_TAG}" >> /usr/lib/rancheros-release echo "IMAGE=${IMAGE_REPO}:${IMAGE_TAG}" >> /usr/lib/rancheros-release
@@ -147,3 +156,12 @@ RUN mkinitrd && \
# aarch64 has an uncompressed kernel so we need to link it to vmlinuz # aarch64 has an uncompressed kernel so we need to link it to vmlinuz
kernel=$(ls /boot/Image-* | head -n1) && \ kernel=$(ls /boot/Image-* | head -n1) && \
if [ -e "$kernel" ]; then ln -sf "${kernel#/boot/}" /boot/vmlinuz; fi if [ -e "$kernel" ]; then ln -sf "${kernel#/boot/}" /boot/vmlinuz; fi
# Save some space
RUN zypper clean --all && \
rm -rf /var/log/update* && \
>/var/log/lastlog && \
rm -rf /boot/vmlinux*
FROM scratch as default
COPY --from=os / /

View File

@@ -21,7 +21,7 @@ var (
func main() { func main() {
flag.Parse() flag.Parse()
if *printConfig { if *printConfig {
cfg, err := config.ReadConfig(*configFile) cfg, err := config.ReadConfig(*configFile, *automatic)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }

View File

@@ -5,8 +5,17 @@ general:
debug: false debug: false
spinner_charset: 9 spinner_charset: 9
repositories: repositories:
- name: "cos-toolkit-green" - name: "cos-toolkit-green-amd64"
type: "docker" type: "docker"
enable: true enable: true
arch: amd64
reference: 20211103130314-repository.yaml
urls: urls:
- "quay.io/costoolkit/releases-green" - "quay.io/costoolkit/releases-green"
- name: "cos-toolkit-green-arm64"
type: "docker"
enable: true
arch: arm64
reference: 20211103171213-repository.yaml
urls:
- "quay.io/costoolkit/releases-green-arm64"

View File

@@ -2,15 +2,32 @@
set -x -e set -x -e
HOST_DIR="${HOST_DIR:-/host}" HOST_DIR="${HOST_DIR:-/host}"
RELEASE_FILE="${RELEASE_FILE:-/usr/lib/rancheros-release}" RELEASE_FILE="${RELEASE_FILE:-/usr/lib/rancheros-release}"
CONF_FILE="${CONF_FILE:-/run/data/cloud-config}"
function config()
{
if [ ! -e $CONF_FILE ]; then
return 0
fi
if [ ! -e ${HOST}/oem/90_operator.yaml ] || ! diff $CONF_FILE ${HOST}/oem/90/operator.yaml >/dev/null; then
cp -f $CONF_FILE ${HOST}/oem/90/operator.yaml
$REBOOT
fi
}
if [ "$FORCE" != "true" ]; then if [ "$FORCE" != "true" ]; then
if diff $RELEASE_FILE ${HOST_DIR}${RELEASE_FILE} >/dev/null; then if diff $RELEASE_FILE ${HOST_DIR}${RELEASE_FILE} >/dev/null; then
echo Update to date with echo Update to date with
cat ${RELEASE_FILE} cat ${RELEASE_FILE}
REBOOT="nsenter -i -m -t 1 -- reboot"
config
exit 0 exit 0
fi fi
fi fi
config
mount --rbind $HOST_DIR/dev /dev mount --rbind $HOST_DIR/dev /dev
mount --rbind $HOST_DIR/run /run mount --rbind $HOST_DIR/run /run
bash -x cos-upgrade --directory / bash -x cos-upgrade --directory /

View File

@@ -0,0 +1,9 @@
NAME="RancherOS"
ID="rancheros"
ID_LIKE="suse opensuse"
BUG_REPORT_URL="https://github.com/rancher/os2/issues"
HOME_URL="https://github.com/rancher/os2"
VERSION="${VERSION}"
VERSION_ID="${VERSION_ID}"
PRETTY_NAME="${PRETTY_NAME}"

View File

@@ -19,6 +19,7 @@ type ManagedOSImage struct {
type ManagedOSImageSpec struct { type ManagedOSImageSpec struct {
OSImage string `json:"osImage,omitempty"` OSImage string `json:"osImage,omitempty"`
CloudConfig *fleet.GenericMap `json:"cloudConfig,omitempty"`
NodeSelector *metav1.LabelSelector `json:"nodeSelector,omitempty"` NodeSelector *metav1.LabelSelector `json:"nodeSelector,omitempty"`
Concurrency *int64 `json:"concurrency,omitempty"` Concurrency *int64 `json:"concurrency,omitempty"`

View File

@@ -146,11 +146,24 @@ func merge(readers ...reader) (map[string]interface{}, error) {
return d, nil return d, nil
} }
func readConfigMap(cfg string) (map[string]interface{}, error) { func readConfigMap(cfg string, includeCmdline bool) (map[string]interface{}, error) {
data, err := merge(readCmdline, readFileFunc(cfg)) var (
if err != nil { data map[string]interface{}
return nil, err err error
)
if includeCmdline {
data, err = merge(readCmdline, readFileFunc(cfg))
if err != nil {
return nil, err
}
} else {
data, err = merge(readFileFunc(cfg))
if err != nil {
return nil, err
}
} }
if cfg != "" { if cfg != "" {
values.PutValue(data, cfg, "rancheros", "install", "configUrl") values.PutValue(data, cfg, "rancheros", "install", "configUrl")
} }
@@ -180,7 +193,18 @@ func ToFile(cfg Config, output string) error {
} }
func ToBytes(cfg Config) ([]byte, error) { func ToBytes(cfg Config) ([]byte, error) {
data := values.MergeMaps(nil, cfg.Data) var (
data map[string]interface{}
err error
)
if len(cfg.Data) > 0 {
data = values.MergeMaps(nil, cfg.Data)
} else {
data, err = convert.EncodeToMap(cfg)
if err != nil {
return nil, err
}
}
values.RemoveValue(data, "install") values.RemoveValue(data, "install")
values.RemoveValue(data, "rancheros", "install") values.RemoveValue(data, "rancheros", "install")
bytes, err := yaml.Marshal(data) bytes, err := yaml.Marshal(data)
@@ -191,8 +215,8 @@ func ToBytes(cfg Config) ([]byte, error) {
return append([]byte("#cloud-config\n"), bytes...), nil return append([]byte("#cloud-config\n"), bytes...), nil
} }
func ReadConfig(cfg string) (result Config, err error) { func ReadConfig(cfg string, includeCmdline bool) (result Config, err error) {
data, err := readConfigMap(cfg) data, err := readConfigMap(cfg, includeCmdline)
if err != nil { if err != nil {
return result, err return result, err
} }

View File

@@ -67,7 +67,12 @@ func (h *handler) OnChange(mos *provv1.ManagedOSImage, status provv1.ManagedOSIm
return nil, status, err return nil, status, err
} }
resources, err := ToResources(objects(mos, prefix)) objs, err := objects(mos, prefix)
if err != nil {
return nil, status, err
}
resources, err := ToResources(objs)
if err != nil { if err != nil {
return nil, status, err return nil, status, err
} }

View File

@@ -6,13 +6,30 @@ import (
osv1 "github.com/rancher/os2/pkg/apis/rancheros.cattle.io/v1" osv1 "github.com/rancher/os2/pkg/apis/rancheros.cattle.io/v1"
"github.com/rancher/os2/pkg/clients" "github.com/rancher/os2/pkg/clients"
upgradev1 "github.com/rancher/system-upgrade-controller/pkg/apis/upgrade.cattle.io/v1" upgradev1 "github.com/rancher/system-upgrade-controller/pkg/apis/upgrade.cattle.io/v1"
"gopkg.in/yaml.v3"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1" rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
) )
func objects(mos *osv1.ManagedOSImage, prefix string) []runtime.Object { func cloudConfig(mos *osv1.ManagedOSImage) ([]byte, error) {
if mos.Spec.CloudConfig == nil || len(mos.Spec.CloudConfig.Data) == 0 {
return []byte{}, nil
}
data, err := yaml.Marshal(mos.Spec.CloudConfig.Data)
if err != nil {
return nil, err
}
return append([]byte("#cloud-config\n"), data...), nil
}
func objects(mos *osv1.ManagedOSImage, prefix string) ([]runtime.Object, error) {
cloudConfig, err := cloudConfig(mos)
if err != nil {
return nil, err
}
concurrency := int64(1) concurrency := int64(1)
if mos.Spec.Concurrency != nil { if mos.Spec.Concurrency != nil {
concurrency = *mos.Spec.Concurrency concurrency = *mos.Spec.Concurrency
@@ -66,6 +83,15 @@ func objects(mos *osv1.ManagedOSImage, prefix string) []runtime.Object {
Namespace: clients.SystemNamespace, Namespace: clients.SystemNamespace,
}, },
}, },
&corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "os-upgrader-data",
Namespace: clients.SystemNamespace,
},
Data: map[string][]byte{
"cloud-config": cloudConfig,
},
},
&upgradev1.Plan{ &upgradev1.Plan{
TypeMeta: metav1.TypeMeta{ TypeMeta: metav1.TypeMeta{
Kind: "Plan", Kind: "Plan",
@@ -86,6 +112,10 @@ func objects(mos *osv1.ManagedOSImage, prefix string) []runtime.Object {
Cordon: cordon, Cordon: cordon,
Drain: mos.Spec.Drain, Drain: mos.Spec.Drain,
Prepare: mos.Spec.Prepare, Prepare: mos.Spec.Prepare,
Secrets: []upgradev1.SecretSpec{{
Name: "os-upgrader-data",
Path: "/run/data",
}},
Upgrade: &upgradev1.ContainerSpec{ Upgrade: &upgradev1.ContainerSpec{
Image: PrefixPrivateRegistry(image[0], prefix), Image: PrefixPrivateRegistry(image[0], prefix),
Command: []string{ Command: []string{
@@ -94,7 +124,7 @@ func objects(mos *osv1.ManagedOSImage, prefix string) []runtime.Object {
}, },
}, },
}, },
} }, nil
} }
func PrefixPrivateRegistry(image, prefix string) string { func PrefixPrivateRegistry(image, prefix string) string {

View File

@@ -12,7 +12,7 @@ import (
) )
func Run(automatic bool, configFile string, powerOff bool, silent bool) error { func Run(automatic bool, configFile string, powerOff bool, silent bool) error {
cfg, err := config.ReadConfig(configFile) cfg, err := config.ReadConfig(configFile, automatic)
if err != nil { if err != nil {
return err return err
} }
@@ -58,6 +58,7 @@ func runInstall(cfg config.Config, output string) error {
if err != nil || !val { if err != nil || !val {
return err return err
} }
cfg.Data = nil
} }
if cfg.RancherOS.Install.ConfigURL == "" && !cfg.RancherOS.Install.Automatic { if cfg.RancherOS.Install.ConfigURL == "" && !cfg.RancherOS.Install.Automatic {
@@ -91,13 +92,13 @@ func runInstall(cfg config.Config, output string) error {
return err return err
} }
cfg.RancherOS.Install.ConfigURL = output + ".yip" cfg.RancherOS.Install.ConfigURL = output + ".yip"
} else {
if err := config.ToFile(cfg, output); err != nil {
return err
}
cfg.RancherOS.Install.ConfigURL = output
} }
if err := config.ToFile(cfg, output); err != nil {
return err
}
cfg.RancherOS.Install.ConfigURL = output
ev, err := config.ToEnv(cfg) ev, err := config.ToEnv(cfg)
if err != nil { if err != nil {
return err return err

View File

@@ -27,14 +27,10 @@ RUN cd /usr/sbin && \
rm tmp rm tmp
RUN cd /usr/src && \ RUN cd /usr/src && \
git clone https://github.com/rancher-sandbox/cOS-toolkit git clone https://github.com/rancher-sandbox/cOS-toolkit
RUN curl -Lo /usr/bin/luet https://github.com/mudler/luet/releases/download/0.20.5/luet-0.20.5-linux-$(go env GOARCH) && \ RUN curl -Lo /usr/bin/luet https://github.com/mudler/luet/releases/download/0.20.6/luet-0.20.6-linux-$(go env GOARCH) && \
chmod +x /usr/bin/luet chmod +x /usr/bin/luet
RUN mkdir -p /iso/iso-overlay/boot/grub2 /etc/luet RUN mkdir -p /iso/iso-overlay/boot/grub2 /etc/luet
RUN export SUFFIX; \ RUN echo -e \
if [ "$(uname -m)" == "aarch64" ]; then \
SUFFIX=-arm64 \
;fi && \
echo -e \
'logging:\n'\ 'logging:\n'\
' color: false\n'\ ' color: false\n'\
' enable_emoji: false\n'\ ' enable_emoji: false\n'\
@@ -42,11 +38,18 @@ echo -e \
' debug: false\n'\ ' debug: false\n'\
' spinner_charset: 9\n'\ ' spinner_charset: 9\n'\
'repositories:\n'\ 'repositories:\n'\
'- name: "cos-toolkit-green-amd64"\n'\
' type: "docker"\n'\
' enable: true\n'\
' arch: amd64\n'\
' urls:\n'\
' - "quay.io/costoolkit/releases-green"\n'\
'- name: "cos-toolkit-green"\n'\ '- name: "cos-toolkit-green"\n'\
' type: "docker"\n'\ ' type: "docker"\n'\
' enable: true\n'\ ' enable: true\n'\
' arch: arm64\n'\
' urls:\n'\ ' urls:\n'\
" - \"quay.io/costoolkit/releases-green${SUFFIX}\"\n" > /etc/luet/luet.yaml && \ ' - "quay.io/costoolkit/releases-green-arm64"\n' > /etc/luet/luet.yaml && \
echo -e \ echo -e \
'packages:\n'\ 'packages:\n'\
' uefi:\n'\ ' uefi:\n'\
@@ -71,15 +74,22 @@ echo -e \
'label: "COS_LIVE"\n'\ 'label: "COS_LIVE"\n'\
'\n'\ '\n'\
'squashfs_options:\n'\ 'squashfs_options:\n'\
' compression: gzip\n'\ ' compression: xz\n'\
'\n'\ '\n'\
'luet:\n'\ 'luet:\n'\
' repositories:\n'\ ' repositories:\n'\
' - name: "cos-toolkit-green"\n'\ ' - name: "cos-toolkit-green-amd64"\n'\
' type: "docker"\n'\ ' type: "docker"\n'\
' enable: true\n'\ ' enable: true\n'\
' arch: amd64\n'\
' urls:\n'\ ' urls:\n'\
" - \"quay.io/costoolkit/releases-green${SUFFIX}\"\n" > /iso/iso.yaml ' - "quay.io/costoolkit/releases-green"\n'\
' - name: "cos-toolkit-green-arm64"\n'\
' type: "docker"\n'\
' enable: true\n'\
' arch: arm64\n'\
' urls:\n'\
' - "quay.io/costoolkit/releases-green-arm64"\n' > /iso/iso.yaml
RUN echo -e \ RUN echo -e \
'search --file --set=root /boot/kernel.xz\n'\ 'search --file --set=root /boot/kernel.xz\n'\
'set default=0\n'\ 'set default=0\n'\