-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package tools | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"dagger.io/dagger" | ||
|
||
"github.com/aweris/gale/internal/version" | ||
) | ||
|
||
// Ghx returns a dagger file for the ghx binary. It'll return an error if the binary is not available. | ||
func Ghx(ctx context.Context, client *dagger.Client) (*dagger.File, error) { | ||
v := version.GetVersion() | ||
|
||
tag := v.GitVersion | ||
|
||
// If the tag is a dev tag, we'll use the main branch. | ||
if tag == "v0.0.0-dev" { | ||
tag = "main" | ||
} | ||
|
||
file := client.Container().From("ghcr.io/aweris/gale/tools/ghx:" + tag).File("/ghx") | ||
|
||
// check, if the file doesn't exist or is empty | ||
if size, err := file.Size(ctx); size == 0 || err != nil { | ||
return nil, fmt.Errorf("ghx@%s binary not available", tag) | ||
} | ||
|
||
return file, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package tools | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"dagger.io/dagger" | ||
|
||
"golang.org/x/mod/semver" | ||
|
||
"github.com/magefile/mage/mg" | ||
|
||
"github.com/aweris/gale/internal/dagger/images" | ||
) | ||
|
||
type Ghx mg.Namespace | ||
|
||
// Publish publishes the artifact service to ghcr.io/aweris/gale/services/artifact with the given version. | ||
func (_ Ghx) Publish(ctx context.Context, version string) error { | ||
if version != "main" { | ||
if ok := semver.IsValid(version); !ok { | ||
return fmt.Errorf("invalid semver tag: %s", version) | ||
} | ||
} | ||
|
||
image := fmt.Sprintf("ghcr.io/aweris/gale/tools/ghx:%s", version) | ||
|
||
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
file := images.GoBase(client). | ||
WithMountedDirectory("/src", client.Host().Directory(".")). | ||
WithWorkdir("/src/tools/ghx"). | ||
WithEnvVariable("CGO_ENABLED", "0"). | ||
WithExec([]string{"go", "build", "-o", "/src/out/ghx", "."}). | ||
File("/src/out/ghx") | ||
|
||
addr, err := client.Container(). | ||
From("gcr.io/distroless/static"). | ||
WithFile("/ghx", file). | ||
WithEntrypoint([]string{"/ghx"}). | ||
Publish(ctx, image) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("Artifact service published to %s\n", addr) | ||
|
||
return nil | ||
} |