Skip to content

Commit 308deef

Browse files
authored
Merge pull request #86 from jakefhyde/81-mage
2 parents 947b90b + 6108a91 commit 308deef

File tree

13 files changed

+321
-62
lines changed

13 files changed

+321
-62
lines changed

.github/workflows/release.yaml

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,51 @@ jobs:
1313
- uses: actions/checkout@v2
1414
- uses: actions/setup-go@v2
1515
with:
16-
go-version: "1.18.5"
17-
- run: scripts/build
16+
go-version: "1.18.6"
17+
- name: Run Mage build linux amd64
18+
uses: magefile/mage-action@v2
19+
env:
20+
GOOS: linux
21+
GOARCH: amd64
22+
with:
23+
version: latest
24+
args: build
25+
- name: Run Mage build linux arm64
26+
uses: magefile/mage-action@v2
27+
env:
28+
GOOS: linux
29+
GOARCH: arm64
30+
with:
31+
version: latest
32+
args: build
33+
- name: Run Mage build darwin amd64
34+
uses: magefile/mage-action@v2
35+
env:
36+
GOOS: darwin
37+
GOARCH: amd64
38+
with:
39+
version: latest
40+
args: build
41+
- name: Run Mage build darwin arm64
42+
uses: magefile/mage-action@v2
43+
env:
44+
GOOS: darwin
45+
GOARCH: arm64
46+
with:
47+
version: latest
48+
args: build
49+
- name: Run Mage build windows amd64
50+
uses: magefile/mage-action@v2
51+
env:
52+
GOOS: windows
53+
GOARCH: amd64
54+
with:
55+
version: latest
56+
args: build
1857
- uses: softprops/action-gh-release@v1
1958
env:
2059
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2160
with:
2261
files: dist/*
23-
prerelease: ${{ env.IS_PRERELEASE }}
62+
prerelease: contains(github.ref, 'rc')
2463
generate_release_notes: true

.github/workflows/validate.yaml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,29 @@ on: pull_request
44

55
jobs:
66
lint:
7-
name: lint
7+
name: validate
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@v2
1111
- uses: actions/setup-go@v2
1212
with:
13-
go-version: "1.18.5"
14-
- run: go mod tidy
15-
- run: go fmt ./...
16-
- run: if [ -n "$(git status --porcelain --untracked-files=no)" ]; then git --no-pager diff; exit 1; fi
13+
go-version: "1.18.6"
14+
- run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
15+
- name: mage validate
16+
uses: magefile/mage-action@v2
17+
with:
18+
version: latest
19+
args: validate
1720
test:
1821
name: test
1922
runs-on: ubuntu-latest
2023
steps:
2124
- uses: actions/checkout@v2
2225
- uses: actions/setup-go@v2
2326
with:
24-
go-version: "1.18.5"
25-
- run: go test ./...
27+
go-version: "1.18.6"
28+
- name: mage test
29+
uses: magefile/mage-action@v2
30+
with:
31+
version: latest
32+
args: test

Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
ARG OS=linux
2+
ARG ARCH=amd64
3+
ARG VERSION=dev
4+
5+
FROM golang:1.18-alpine as mage
6+
ARG OS
7+
ARG ARCH
8+
ARG VERSION
9+
WORKDIR /app
10+
11+
COPY . .
12+
13+
ARG TARGET=build
14+
15+
RUN apk update && \
16+
apk upgrade && \
17+
apk add curl git
18+
19+
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
20+
21+
ENV GOOS=${OS}
22+
ENV GOARCH=${ARCH}
23+
ENV VERSION=${VERSION}
24+
25+
RUN mage -v ${TARGET} ${VERSION}
26+
27+
FROM scratch
28+
ARG OS
29+
ARG ARCH
30+
WORKDIR /app
31+
32+
COPY --from=mage /app/dist/corral-${OS}-${ARCH} /usr/bin/corral
33+
34+
ENTRYPOINT ["corral"]

Makefile

Whitespace-only changes.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
# Corral
2+
13
[![Go Report Card](https://goreportcard.com/badge/github.com/rancherlabs/corral)](https://goreportcard.com/badge/github.com/rancherlabs/corral)
24

3-
# Corral
45
Corral is a CLI tool for creating and packaging reproducible development environments. Corral allows developers to manage multiple environments, called corrals, and provision them consistently using shared packages.
56

67
# Installation
8+
79
To install corral download the latest binary from the [releases](https://github.com/rancherlabs/corral/releases).
810

911
## First Time Setup

cmd/root.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package cmd
22

33
import (
44
"github.com/rancherlabs/corral/cmd/config"
5+
56
cmdpackage "github.com/rancherlabs/corral/cmd/package"
67
pkgcmd "github.com/rancherlabs/corral/pkg/cmd"
8+
"github.com/rancherlabs/corral/pkg/version"
79
"github.com/sirupsen/logrus"
810
"github.com/spf13/cobra"
911
)
@@ -15,9 +17,10 @@ func Execute() {
1517
var trace bool
1618

1719
rootCmd := &cobra.Command{
18-
Use: "corral",
19-
Short: "Corral is a CLI tool for creating and packaging reproducible development environments.",
20-
Long: "Corral is a CLI tool for creating and packaging reproducible development environments.",
20+
Use: "corral",
21+
Short: "Corral is a CLI tool for creating and packaging reproducible development environments.",
22+
Long: "Corral is a CLI tool for creating and packaging reproducible development environments.",
23+
Version: version.Version,
2124
PersistentPreRun: func(cmd *cobra.Command, args []string) {
2225
if trace {
2326
logrus.SetLevel(logrus.TraceLevel)
@@ -34,8 +37,6 @@ func Execute() {
3437
SilenceErrors: true,
3538
}
3639

37-
//rootCmd.SetErr(logrus.StandardLogger().Out)
38-
3940
rootCmd.AddCommand(
4041
config.NewCommandConfig(),
4142
NewCommandDelete(),

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/hashicorp/hc-install v0.3.2
1010
github.com/hashicorp/terraform-exec v0.16.1
1111
github.com/jedib0t/go-pretty/v6 v6.3.0
12+
github.com/magefile/mage v1.13.0
1213
github.com/onsi/ginkgo/v2 v2.1.6
1314
github.com/onsi/gomega v1.20.2
1415
github.com/opencontainers/image-spec v1.0.2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
305305
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
306306
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
307307
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
308+
github.com/magefile/mage v1.13.0 h1:XtLJl8bcCM7EFoO8FyH8XK3t7G5hQAeK+i4tq+veT9M=
309+
github.com/magefile/mage v1.13.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
308310
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
309311
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
310312
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=

magefiles/magefile.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//go:build mage
2+
3+
package main
4+
5+
import (
6+
"context"
7+
"fmt"
8+
"log"
9+
"os"
10+
"runtime"
11+
12+
"github.com/magefile/mage/mg"
13+
"github.com/rancherlabs/corral/magetools"
14+
)
15+
16+
var Default = Build
17+
var g *magetools.Go
18+
var version string
19+
var commit string
20+
21+
func Setup() error {
22+
var err error
23+
version, err = magetools.GetVersion()
24+
if err != nil {
25+
return err
26+
}
27+
commit, err = magetools.GetCommit()
28+
if err != nil {
29+
return err
30+
}
31+
g = magetools.NewGo(goarch(), goos(), version, commit, false, true)
32+
return nil
33+
}
34+
35+
func Dependencies() error {
36+
mg.Deps(Setup)
37+
return g.Mod().Download()
38+
}
39+
40+
func Build(ctx context.Context) error {
41+
mg.Deps(Dependencies)
42+
return g.Build("main.go", fmt.Sprintf("dist/corral-%s-%s", g.OS, g.Arch))
43+
}
44+
45+
func Validate() error {
46+
mg.Deps(Setup)
47+
log.Println("[Validate] Running: golangci-lint")
48+
if err := g.Lint(); err != nil {
49+
return err
50+
}
51+
52+
log.Println("[Validate] Running: go fmt")
53+
if err := g.Fmt("./..."); err != nil {
54+
return err
55+
}
56+
57+
log.Println("[Validate] Running: go mod tidy")
58+
if err := g.Mod().Tidy(); err != nil {
59+
return err
60+
}
61+
62+
log.Println("[Validate] Running: go mod verify")
63+
if err := g.Mod().Verify(); err != nil {
64+
return err
65+
}
66+
67+
log.Println("[Validate] Checking for dirty repo")
68+
if err := magetools.IsGitClean(); err != nil {
69+
return err
70+
}
71+
72+
log.Println("[Validate] corral has been successfully validated")
73+
return nil
74+
}
75+
76+
func Test() error {
77+
mg.Deps(Setup)
78+
log.Println("[Test] Running unit tests")
79+
if err := g.Test("", "./cmd/...", "./pkg/..."); err != nil {
80+
return err
81+
}
82+
log.Println("[Test] Running integration tests")
83+
if err := g.Test("./...", "./tests/..."); err != nil {
84+
return err
85+
}
86+
log.Println("[Test] corral has been successfully tested")
87+
return nil
88+
}
89+
90+
func goos() string {
91+
if goos := os.Getenv("GOOS"); goos != "" {
92+
return goos
93+
}
94+
return runtime.GOOS
95+
}
96+
97+
func goarch() string {
98+
if goarch := os.Getenv("GOARCH"); goarch != "" {
99+
return goarch
100+
}
101+
return runtime.GOARCH
102+
}

0 commit comments

Comments
 (0)