Skip to content

Commit

Permalink
Merge pull request #145 from jacobweinstock/grub2disk-image
Browse files Browse the repository at this point in the history
Update grub2disk:

## Description

<!--- Please describe what this PR is going to change -->
Use alpine for final container in the Dockerfile as there are quite a few shell commands used.

## Why is this needed

<!--- Link to issue you have raised -->

Fixes: #

## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran to -->
<!--- see how your change affects other areas of the code, etc. -->


## How are existing users impacted? What migration steps/scripts do we need?

<!--- Fixes a bug, unblocks installation, removes a component of the stack etc -->
<!--- Requires a DB migration script, etc. -->


## Checklist:

I have:

- [ ] updated the documentation and/or roadmap (if required)
- [ ] added unit or e2e tests
- [ ] provided instructions on how to upgrade
  • Loading branch information
jacobweinstock authored Sep 5, 2024
2 parents 12cf23f + e2aa15e commit ae59b37
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
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

0 comments on commit ae59b37

Please sign in to comment.