-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from jakefhyde/81-mage
- Loading branch information
Showing
13 changed files
with
321 additions
and
62 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
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,34 @@ | ||
ARG OS=linux | ||
ARG ARCH=amd64 | ||
ARG VERSION=dev | ||
|
||
FROM golang:1.18-alpine as mage | ||
ARG OS | ||
ARG ARCH | ||
ARG VERSION | ||
WORKDIR /app | ||
|
||
COPY . . | ||
|
||
ARG TARGET=build | ||
|
||
RUN apk update && \ | ||
apk upgrade && \ | ||
apk add curl git | ||
|
||
RUN curl -sLf https://github.com/magefile/mage/releases/download/v1.13.0/mage_1.13.0_Linux-64bit.tar.gz | tar xvzf - -C /usr/bin && chmod +x /usr/bin/mage | ||
|
||
ENV GOOS=${OS} | ||
ENV GOARCH=${ARCH} | ||
ENV VERSION=${VERSION} | ||
|
||
RUN mage -v ${TARGET} ${VERSION} | ||
|
||
FROM scratch | ||
ARG OS | ||
ARG ARCH | ||
WORKDIR /app | ||
|
||
COPY --from=mage /app/dist/corral-${OS}-${ARCH} /usr/bin/corral | ||
|
||
ENTRYPOINT ["corral"] |
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
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,102 @@ | ||
//go:build mage | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
"runtime" | ||
|
||
"github.com/magefile/mage/mg" | ||
"github.com/rancherlabs/corral/magetools" | ||
) | ||
|
||
var Default = Build | ||
var g *magetools.Go | ||
var version string | ||
var commit string | ||
|
||
func Setup() error { | ||
var err error | ||
version, err = magetools.GetVersion() | ||
if err != nil { | ||
return err | ||
} | ||
commit, err = magetools.GetCommit() | ||
if err != nil { | ||
return err | ||
} | ||
g = magetools.NewGo(goarch(), goos(), version, commit, false, true) | ||
return nil | ||
} | ||
|
||
func Dependencies() error { | ||
mg.Deps(Setup) | ||
return g.Mod().Download() | ||
} | ||
|
||
func Build(ctx context.Context) error { | ||
mg.Deps(Dependencies) | ||
return g.Build("main.go", fmt.Sprintf("dist/corral-%s-%s", g.OS, g.Arch)) | ||
} | ||
|
||
func Validate() error { | ||
mg.Deps(Setup) | ||
log.Println("[Validate] Running: golangci-lint") | ||
if err := g.Lint(); err != nil { | ||
return err | ||
} | ||
|
||
log.Println("[Validate] Running: go fmt") | ||
if err := g.Fmt("./..."); err != nil { | ||
return err | ||
} | ||
|
||
log.Println("[Validate] Running: go mod tidy") | ||
if err := g.Mod().Tidy(); err != nil { | ||
return err | ||
} | ||
|
||
log.Println("[Validate] Running: go mod verify") | ||
if err := g.Mod().Verify(); err != nil { | ||
return err | ||
} | ||
|
||
log.Println("[Validate] Checking for dirty repo") | ||
if err := magetools.IsGitClean(); err != nil { | ||
return err | ||
} | ||
|
||
log.Println("[Validate] corral has been successfully validated") | ||
return nil | ||
} | ||
|
||
func Test() error { | ||
mg.Deps(Setup) | ||
log.Println("[Test] Running unit tests") | ||
if err := g.Test("", "./cmd/...", "./pkg/..."); err != nil { | ||
return err | ||
} | ||
log.Println("[Test] Running integration tests") | ||
if err := g.Test("./...", "./tests/..."); err != nil { | ||
return err | ||
} | ||
log.Println("[Test] corral has been successfully tested") | ||
return nil | ||
} | ||
|
||
func goos() string { | ||
if goos := os.Getenv("GOOS"); goos != "" { | ||
return goos | ||
} | ||
return runtime.GOOS | ||
} | ||
|
||
func goarch() string { | ||
if goarch := os.Getenv("GOARCH"); goarch != "" { | ||
return goarch | ||
} | ||
return runtime.GOARCH | ||
} |
Oops, something went wrong.