Skip to content

Commit

Permalink
Merge pull request #86 from jakefhyde/81-mage
Browse files Browse the repository at this point in the history
  • Loading branch information
jakefhyde authored Sep 17, 2022
2 parents 947b90b + 6108a91 commit 308deef
Show file tree
Hide file tree
Showing 13 changed files with 321 additions and 62 deletions.
45 changes: 42 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,51 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "1.18.5"
- run: scripts/build
go-version: "1.18.6"
- name: Run Mage build linux amd64
uses: magefile/mage-action@v2
env:
GOOS: linux
GOARCH: amd64
with:
version: latest
args: build
- name: Run Mage build linux arm64
uses: magefile/mage-action@v2
env:
GOOS: linux
GOARCH: arm64
with:
version: latest
args: build
- name: Run Mage build darwin amd64
uses: magefile/mage-action@v2
env:
GOOS: darwin
GOARCH: amd64
with:
version: latest
args: build
- name: Run Mage build darwin arm64
uses: magefile/mage-action@v2
env:
GOOS: darwin
GOARCH: arm64
with:
version: latest
args: build
- name: Run Mage build windows amd64
uses: magefile/mage-action@v2
env:
GOOS: windows
GOARCH: amd64
with:
version: latest
args: build
- uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: dist/*
prerelease: ${{ env.IS_PRERELEASE }}
prerelease: contains(github.ref, 'rc')
generate_release_notes: true
21 changes: 14 additions & 7 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,29 @@ on: pull_request

jobs:
lint:
name: lint
name: validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "1.18.5"
- run: go mod tidy
- run: go fmt ./...
- run: if [ -n "$(git status --porcelain --untracked-files=no)" ]; then git --no-pager diff; exit 1; fi
go-version: "1.18.6"
- run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- name: mage validate
uses: magefile/mage-action@v2
with:
version: latest
args: validate
test:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "1.18.5"
- run: go test ./...
go-version: "1.18.6"
- name: mage test
uses: magefile/mage-action@v2
with:
version: latest
args: test
34 changes: 34 additions & 0 deletions Dockerfile
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"]
Empty file added Makefile
Empty file.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Corral

[![Go Report Card](https://goreportcard.com/badge/github.com/rancherlabs/corral)](https://goreportcard.com/badge/github.com/rancherlabs/corral)

# Corral
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.

# Installation

To install corral download the latest binary from the [releases](https://github.com/rancherlabs/corral/releases).

## First Time Setup
Expand Down
11 changes: 6 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package cmd

import (
"github.com/rancherlabs/corral/cmd/config"

cmdpackage "github.com/rancherlabs/corral/cmd/package"
pkgcmd "github.com/rancherlabs/corral/pkg/cmd"
"github.com/rancherlabs/corral/pkg/version"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand All @@ -15,9 +17,10 @@ func Execute() {
var trace bool

rootCmd := &cobra.Command{
Use: "corral",
Short: "Corral is a CLI tool for creating and packaging reproducible development environments.",
Long: "Corral is a CLI tool for creating and packaging reproducible development environments.",
Use: "corral",
Short: "Corral is a CLI tool for creating and packaging reproducible development environments.",
Long: "Corral is a CLI tool for creating and packaging reproducible development environments.",
Version: version.Version,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if trace {
logrus.SetLevel(logrus.TraceLevel)
Expand All @@ -34,8 +37,6 @@ func Execute() {
SilenceErrors: true,
}

//rootCmd.SetErr(logrus.StandardLogger().Out)

rootCmd.AddCommand(
config.NewCommandConfig(),
NewCommandDelete(),
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/hashicorp/hc-install v0.3.2
github.com/hashicorp/terraform-exec v0.16.1
github.com/jedib0t/go-pretty/v6 v6.3.0
github.com/magefile/mage v1.13.0
github.com/onsi/ginkgo/v2 v2.1.6
github.com/onsi/gomega v1.20.2
github.com/opencontainers/image-spec v1.0.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magefile/mage v1.13.0 h1:XtLJl8bcCM7EFoO8FyH8XK3t7G5hQAeK+i4tq+veT9M=
github.com/magefile/mage v1.13.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
Expand Down
102 changes: 102 additions & 0 deletions magefiles/magefile.go
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
}
Loading

0 comments on commit 308deef

Please sign in to comment.