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

Update grub2disk: #145

Merged
merged 1 commit into from
Sep 5, 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
20 changes: 9 additions & 11 deletions grub2disk/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# syntax=docker/dockerfile:1

FROM golang:1.21-alpine AS base
FROM golang:1.23-alpine AS base

FROM base AS build-amd64
RUN apk add --no-cache grub grub-bios git ca-certificates gcc musl-dev
Expand All @@ -9,12 +7,12 @@ FROM base AS build-arm64
RUN apk add --no-cache grub git ca-certificates gcc musl-dev

FROM build-${TARGETARCH} AS grub2disk
COPY . /src
WORKDIR /src/grub2disk
RUN --mount=type=cache,sharing=locked,id=gomod,target=/go/pkg/mod/cache \
--mount=type=cache,sharing=locked,id=goroot,target=/root/.cache/go-build \
CGO_ENABLED=1 GOOS=linux go build -a -ldflags "-linkmode external -extldflags '-static' -s -w" -o grub2disk
WORKDIR /src
COPY go.mod go.sum /src/
RUN go mod download
COPY . /src/
RUN CGO_ENABLED=1 GOOS=linux go build -a -ldflags "-linkmode external -extldflags '-static' -s -w" -o /src/grub2disk/grub2disk /src/grub2disk/

FROM scratch
COPY --from=grub2disk /src/grub2disk/grub2disk /usr/bin/grub2disk
ENTRYPOINT ["/usr/bin/grub2disk"]
FROM alpine:3.20.2
COPY --from=grub2disk /src/grub2disk/grub2disk /usr/sbin/grub2disk
ENTRYPOINT ["/usr/sbin/grub2disk"]
7 changes: 3 additions & 4 deletions grub2disk/grub/grub.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ package grub

import (
"fmt"
"os"
"os/exec"
"syscall"

log "github.com/sirupsen/logrus"
)

func makeDirAndMount(devicePath string, mountPoint string, filesystemType string) (err error) {
// if err = os.Mkdir(mountPoint, os.ModeDir); err != nil {
if _, err = exec.Command("/bin/sh", "-c", "/bin/mkdir -p "+mountPoint).Output(); err != nil {
log.Error(fmt.Errorf("failed to create the directory %s", mountPoint))
return err
if err := os.MkdirAll(mountPoint, os.ModeDir); err != nil {
return fmt.Errorf("failed to create the directory %s: %w", mountPoint, err)
}

// if err = syscall.Mount(devicePath, mountPoint, filesystemType, flag, ""); err != nil {
Expand Down
4 changes: 0 additions & 4 deletions grub2disk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"os"
"os/exec"

log "github.com/sirupsen/logrus"
"github.com/tinkerbell/actions/grub2disk/grub"
Expand All @@ -15,9 +14,6 @@ func main() {
grubBlockDevice := os.Getenv("GRUB_DISK")
filesystemType := os.Getenv("FS_TYPE")

if _, err := exec.Command("/bin/sh", "-c", "apk add grub grub-bios").Output(); err != nil {
log.Fatal(fmt.Errorf("failed to install grub-install with error %w", err))
}
if err := grub.MountGrub(grubInstallPath, grubBlockDevice, filesystemType); err != nil {
log.Fatal(err)
}
Expand Down