mirror of
https://github.com/linka-cloud/d2vm.git
synced 2026-01-24 02:25:04 +00:00
templates: improve docker build layers caching
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
7
.github/workflows/ci.yaml
vendored
7
.github/workflows/ci.yaml
vendored
@@ -61,6 +61,10 @@ jobs:
|
|||||||
- quay.io/centos/centos:stream
|
- quay.io/centos/centos:stream
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: Free Disk Space (Ubuntu)
|
||||||
|
uses: linka-cloud/free-disk-space@main
|
||||||
|
if: matrix.image == 'quay.io/centos/centos:stream'
|
||||||
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
@@ -109,6 +113,9 @@ jobs:
|
|||||||
- centos:8
|
- centos:8
|
||||||
- quay.io/centos/centos:stream10
|
- quay.io/centos/centos:stream10
|
||||||
steps:
|
steps:
|
||||||
|
- name: Free Disk Space (Ubuntu)
|
||||||
|
uses: linka-cloud/free-disk-space@main
|
||||||
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -24,12 +24,13 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"go.uber.org/multierr"
|
||||||
|
|
||||||
"go.linka.cloud/d2vm/pkg/docker"
|
"go.linka.cloud/d2vm/pkg/docker"
|
||||||
"go.linka.cloud/d2vm/pkg/exec"
|
"go.linka.cloud/d2vm/pkg/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testConfig(t *testing.T, ctx context.Context, name, img string, config Config, luks, grubBIOS, grubEFI bool) {
|
func testConfig(t *testing.T, ctx context.Context, name, img string, config Config, luks, grubBIOS, grubEFI bool) func() error {
|
||||||
require.NoError(t, docker.Pull(ctx, Arch, img))
|
require.NoError(t, docker.Pull(ctx, Arch, img))
|
||||||
tmpPath := filepath.Join(os.TempDir(), "d2vm-tests", strings.NewReplacer(":", "-", ".", "-").Replace(name))
|
tmpPath := filepath.Join(os.TempDir(), "d2vm-tests", strings.NewReplacer(":", "-", ".", "-").Replace(name))
|
||||||
require.NoError(t, os.MkdirAll(tmpPath, 0755))
|
require.NoError(t, os.MkdirAll(tmpPath, 0755))
|
||||||
@@ -37,7 +38,16 @@ func testConfig(t *testing.T, ctx context.Context, name, img string, config Conf
|
|||||||
logrus.Infof("inspecting image %s", img)
|
logrus.Infof("inspecting image %s", img)
|
||||||
r, err := FetchDockerImageOSRelease(ctx, img)
|
r, err := FetchDockerImageOSRelease(ctx, img)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer docker.Remove(ctx, img)
|
var fns []func() error
|
||||||
|
clean := func() (err error) {
|
||||||
|
for _, v := range fns {
|
||||||
|
err = multierr.Append(err, v())
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fns = append(fns, func() error {
|
||||||
|
return docker.Remove(ctx, img)
|
||||||
|
})
|
||||||
if !r.SupportsLUKS() && luks {
|
if !r.SupportsLUKS() && luks {
|
||||||
t.Skipf("LUKS not supported for %s", r.Version)
|
t.Skipf("LUKS not supported for %s", r.Version)
|
||||||
}
|
}
|
||||||
@@ -53,13 +63,16 @@ func testConfig(t *testing.T, ctx context.Context, name, img string, config Conf
|
|||||||
imgUUID := uuid.New().String()
|
imgUUID := uuid.New().String()
|
||||||
logrus.Infof("building kernel enabled image")
|
logrus.Infof("building kernel enabled image")
|
||||||
require.NoError(t, docker.Build(ctx, false, imgUUID, p, dir, Arch))
|
require.NoError(t, docker.Build(ctx, false, imgUUID, p, dir, Arch))
|
||||||
defer docker.Remove(ctx, imgUUID)
|
fns = append(fns, func() error {
|
||||||
|
return docker.Remove(ctx, imgUUID)
|
||||||
|
})
|
||||||
// we don't need to test the kernel location if grub is enabled
|
// we don't need to test the kernel location if grub is enabled
|
||||||
if grubBIOS || grubEFI {
|
if grubBIOS || grubEFI {
|
||||||
return
|
return clean
|
||||||
}
|
}
|
||||||
require.NoError(t, docker.RunAndRemove(ctx, imgUUID, "test", "-f", config.Kernel))
|
require.NoError(t, docker.RunAndRemove(ctx, imgUUID, "test", "-f", config.Kernel))
|
||||||
require.NoError(t, docker.RunAndRemove(ctx, imgUUID, "test", "-f", config.Initrd))
|
require.NoError(t, docker.RunAndRemove(ctx, imgUUID, "test", "-f", config.Initrd))
|
||||||
|
return clean
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConfig(t *testing.T) {
|
func TestConfig(t *testing.T) {
|
||||||
@@ -147,12 +160,17 @@ func TestConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
name := strings.Join(n, "-")
|
name := strings.Join(n, "-")
|
||||||
|
var clean func() error
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
t.Parallel()
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
testConfig(t, ctx, name, test.image, test.config, luks, grubBIOS, grubEFI)
|
clean = testConfig(t, ctx, name, test.image, test.config, luks, grubBIOS, grubEFI)
|
||||||
})
|
})
|
||||||
|
defer func() {
|
||||||
|
if clean != nil {
|
||||||
|
_ = clean()
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,12 +16,6 @@ RUN yum install -y \
|
|||||||
kernel \
|
kernel \
|
||||||
systemd \
|
systemd \
|
||||||
NetworkManager \
|
NetworkManager \
|
||||||
{{- if .GrubBIOS }}
|
|
||||||
grub2 \
|
|
||||||
{{- end }}
|
|
||||||
{{- if .GrubEFI }}
|
|
||||||
grub2 grub2-efi-x64 grub2-efi-x64-modules \
|
|
||||||
{{- end }}
|
|
||||||
e2fsprogs \
|
e2fsprogs \
|
||||||
sudo && \
|
sudo && \
|
||||||
systemctl enable NetworkManager && \
|
systemctl enable NetworkManager && \
|
||||||
@@ -29,6 +23,13 @@ RUN yum install -y \
|
|||||||
systemctl unmask getty.target && \
|
systemctl unmask getty.target && \
|
||||||
find /boot -type l -exec rm {} \;
|
find /boot -type l -exec rm {} \;
|
||||||
|
|
||||||
|
{{- if .GrubBIOS }}
|
||||||
|
RUN yum install -y grub2
|
||||||
|
{{- end }}
|
||||||
|
{{- if .GrubEFI }}
|
||||||
|
RUN yum install -y grub2 grub2-efi-x64 grub2-efi-x64-modules
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
{{ if .Luks }}
|
{{ if .Luks }}
|
||||||
RUN yum install -y cryptsetup && \
|
RUN yum install -y cryptsetup && \
|
||||||
dracut --no-hostonly --regenerate-all --force --install="/usr/sbin/cryptsetup"
|
dracut --no-hostonly --regenerate-all --force --install="/usr/sbin/cryptsetup"
|
||||||
|
|||||||
@@ -19,21 +19,22 @@ RUN ARCH="$([ "$(uname -m)" = "x86_64" ] && echo amd64 || echo arm64)"; \
|
|||||||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
||||||
systemd-sysv \
|
systemd-sysv \
|
||||||
systemd \
|
systemd \
|
||||||
{{- if .Grub }}
|
|
||||||
grub-common \
|
|
||||||
grub2-common \
|
|
||||||
{{- end }}
|
|
||||||
{{- if .GrubBIOS }}
|
|
||||||
grub-pc-bin \
|
|
||||||
{{- end }}
|
|
||||||
{{- if .GrubEFI }}
|
|
||||||
grub-efi-${ARCH}-bin \
|
|
||||||
{{- end }}
|
|
||||||
dbus \
|
dbus \
|
||||||
iproute2 \
|
iproute2 \
|
||||||
isc-dhcp-client \
|
isc-dhcp-client \
|
||||||
iputils-ping
|
iputils-ping
|
||||||
|
|
||||||
|
{{- if .Grub }}
|
||||||
|
RUN DEBIAN_FRONTEND=noninteractive apt install -y grub-common grub2-common
|
||||||
|
{{- end }}
|
||||||
|
{{- if .GrubBIOS }}
|
||||||
|
RUN DEBIAN_FRONTEND=noninteractive apt install -y grub-pc-bin
|
||||||
|
{{- end }}
|
||||||
|
{{- if .GrubEFI }}
|
||||||
|
RUN ARCH="$([ "$(uname -m)" = "x86_64" ] && echo amd64 || echo arm64)"; \
|
||||||
|
DEBIAN_FRONTEND=noninteractive apt install -y grub-efi-${ARCH}-bin
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
RUN systemctl preset-all
|
RUN systemctl preset-all
|
||||||
|
|
||||||
{{ if .Password }}RUN echo "root:{{ .Password }}" | chpasswd {{ end }}
|
{{ if .Password }}RUN echo "root:{{ .Password }}" | chpasswd {{ end }}
|
||||||
|
|||||||
Reference in New Issue
Block a user