Skip to content

Fix building Leeway with Leeway #219

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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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
24 changes: 14 additions & 10 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"name": "leeway",
"build": {
"context": "..",
"dockerfile": "../.gitpod.Dockerfile"
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/devcontainers/features/node:1": {
"version": "lts"
},
"ghcr.io/devcontainers/features/go:1": {
"version": "1.24.0"
},
"ghcr.io/devcontainers/features/common-utils:2": {},
"ghcr.io/devcontainers-contrib/features/shfmt:1": {
"version": "3.10.0"
}
},
"runArgs": [
"--privileged",
"--security-opt=seccomp=unconfined",
"--network=host"
],
"containerUser": "root"
}
"postStartCommand": "./.devcontainer/install-leeway.sh"
}
27 changes: 27 additions & 0 deletions .devcontainer/install-leeway.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
# This script downloads and installs the latest version of leeway

set -euo pipefail

# Get the latest leeway version from GitHub API
LATEST_LEEWAY_VERSION=$(curl -s https://api.github.com/repos/gitpod-io/leeway/releases/latest | jq -r '.tag_name' | sed 's/^v//')

# Ensure we got a valid version
if [ -z "$LATEST_LEEWAY_VERSION" ]; then
echo "Error: Could not determine latest leeway version" >&2
exit 1
fi

echo "Installing leeway version: $LATEST_LEEWAY_VERSION"

# Download the latest leeway release
curl -L -o /tmp/leeway.tar.gz "https://github.com/gitpod-io/leeway/releases/download/v${LATEST_LEEWAY_VERSION}/leeway_Linux_x86_64.tar.gz"

# Extract the tarball
tar -xzf /tmp/leeway.tar.gz -C /tmp

# Install leeway to /usr/local/bin
sudo install -m 755 /tmp/leeway /usr/local/bin/

# Clean up temporary files
rm /tmp/leeway.tar.gz /tmp/leeway
52 changes: 0 additions & 52 deletions .gitpod.Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions .gitpod.yml

This file was deleted.

18 changes: 14 additions & 4 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,19 @@ func saveBuildResult(ctx context.Context, loc string, localCache cache.LocalCach
}
fin, err := os.OpenFile(br, os.O_RDONLY, 0644)
if err != nil {
fout.Close()
if closeErr := fout.Close(); closeErr != nil {
log.WithError(closeErr).Warn("failed to close output file")
}
log.WithError(err).Fatal("cannot copy build result")
}

_, err = io.Copy(fout, fin)
fout.Close()
fin.Close()
if err := fout.Close(); err != nil {
log.WithError(err).Warn("failed to close output file")
}
if err := fin.Close(); err != nil {
log.WithError(err).Warn("failed to close input file")
}
if err != nil {
log.WithError(err).Fatal("cannot copy build result")
}
Expand Down Expand Up @@ -246,7 +252,11 @@ func getBuildOpts(cmd *cobra.Command) ([]leeway.BuildOption, cache.LocalCache) {
if err != nil {
log.Fatal(err)
}
defer f.Close()
defer func() {
if err := f.Close(); err != nil {
log.WithError(err).Warn("failed to close plan file")
}
}()

planOutlet = f
}
Expand Down
10 changes: 8 additions & 2 deletions cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,11 @@ func executeCommandInLocations(rawExecCmd []string, locs []commandExecLocation,
return fmt.Errorf("execution failed in %s (%s): %w", loc.Name, loc.Dir, err)
}
_ = pty.InheritSize(ptmx, os.Stdin)
defer ptmx.Close()
defer func() {
if err := ptmx.Close(); err != nil {
log.WithError(err).Warn("failed to close pty")
}
}()

//nolint:errcheck
go io.Copy(textio.NewPrefixWriter(os.Stdout, prefix), ptmx)
Expand Down Expand Up @@ -358,7 +362,9 @@ func (c filesystemExecCache) MarkExecuted(ctx context.Context, loc commandExecLo
if err != nil {
return err
}
f.Close()
if err := f.Close(); err != nil {
log.WithError(err).Warn("failed to close file")
}
log.WithField("name", fn).Debug("marked executed")
return nil
}
Expand Down
12 changes: 10 additions & 2 deletions cmd/experiemental-unmount.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,21 @@ var unmountCmd = &cobra.Command{
if err != nil {
return err
}
defer src.Close()
defer func() {
if err := src.Close(); err != nil {
logrus.WithError(err).Warn("failed to close source file")
}
}()

f, err := os.OpenFile(dst, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, info.Mode())
if err != nil {
return err
}
defer f.Close()
defer func() {
if err := f.Close(); err != nil {
logrus.WithError(err).Warn("failed to close destination file")
}
}()

logrus.WithField("dest", dst).Debug("applying change: copying content")
_, err = io.Copy(f, src)
Expand Down
6 changes: 5 additions & 1 deletion cmd/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ func formatBuildYaml(fn string, inPlace, fix bool) error {
if err != nil {
return err
}
defer f.Close()
defer func() {
if err := f.Close(); err != nil {
fmt.Fprintf(os.Stderr, "warning: failed to close file: %v\n", err)
}
}()

var out io.Writer = os.Stdout
if inPlace {
Expand Down
10 changes: 7 additions & 3 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ var initCmd = &cobra.Command{
err = yaml.Unmarshal(tpl, &pkg)
if err != nil {
log.WithField("template", string(tpl)).Warn("broken package template")
return fmt.Errorf("This is a leeway bug. Cannot parse package template: %w", err)
return fmt.Errorf("this is a leeway bug, cannot parse package template: %w", err)
}

f, err := os.OpenFile("BUILD.yaml", os.O_CREATE|os.O_RDWR, 0644)
if err != nil {
return err
}
defer f.Close()
defer func() {
if err := f.Close(); err != nil {
fmt.Fprintf(os.Stderr, "warning: failed to close BUILD.yaml file: %v\n", err)
}
}()

var cmp yaml.Node
err = yaml.NewDecoder(f).Decode(&cmp)
Expand All @@ -75,7 +79,7 @@ var initCmd = &cobra.Command{

cmps := cmp.Content[0].Content
for i, nde := range cmps {
if !(nde.Value == "packages" && i < len(cmps)-1 && cmps[i+1].Kind == yaml.SequenceNode) {
if nde.Value != "packages" || i >= len(cmps)-1 || cmps[i+1].Kind != yaml.SequenceNode {
continue
}

Expand Down
6 changes: 5 additions & 1 deletion cmd/provenance-assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ var provenanceAssertCmd = &cobra.Command{
if err != nil {
log.WithError(err).Fatalf("cannot open attestation bundle %s", bundleFN)
}
defer f.Close()
defer func() {
if err := f.Close(); err != nil {
log.WithError(err).Warn("failed to close attestation bundle file")
}
}()

err = provutil.DecodeBundle(f, assert)
} else {
Expand Down
6 changes: 5 additions & 1 deletion cmd/provenance-export.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ var provenanceExportCmd = &cobra.Command{
if err != nil {
log.WithError(err).Fatal("cannot open attestation bundle")
}
defer f.Close()
defer func() {
if err := f.Close(); err != nil {
log.WithError(err).Warn("failed to close attestation bundle file")
}
}()
err = provutil.DecodeBundle(f, export)
if err != nil {
log.WithError(err).Fatal("cannot extract attestation bundle")
Expand Down
6 changes: 5 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ func Execute() {
log.WithError(err).Fatal("cannot start trace but LEEWAY_TRACE is set")
return
}
defer f.Close()
defer func() {
if err := f.Close(); err != nil {
log.WithError(err).Warn("failed to close trace file")
}
}()
err = trace.Start(f)
if err != nil {
log.WithError(err).Fatal("cannot start trace but LEEWAY_TRACE is set")
Expand Down
Loading