Skip to content

Commit

Permalink
Add "new" command for scaffolding projects (#15)
Browse files Browse the repository at this point in the history
Co-authored-by: mg <[email protected]>
  • Loading branch information
mbpolan and tiny-dancer authored May 19, 2021
1 parent 173e9e7 commit 085c266
Show file tree
Hide file tree
Showing 16 changed files with 676 additions and 41 deletions.
21 changes: 15 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: "build containers"
run: ./scripts/build_containers.sh
- name: Publish Unit Test Results
uses: EnricoMi/[email protected]
- uses: actions/setup-go@v2
with:
go-version: "^1.16.4"
- name: Setup gotestsum
uses: autero1/[email protected]
with:
gotestsum_version: 1.6.4
- name: "go test"
run: |
rm -rf ./reports && mkdir ./reports;
gotestsum --format standard-verbose --junitfile ./reports/junit.xml --raw-command -- go test -parallel 5 --json ./...;
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
files: reports/*.xml
name: Unit Test Results
path: reports/*.xml
35 changes: 25 additions & 10 deletions build/package/alpine-builder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@ FROM golang:${GOVERSION} as builder

RUN apt-get update && apt-get upgrade -y ca-certificates && apt-get install -y bash && apt-get install -y unzip

RUN curl -Lo go.zip "https://github.com/golang/go/archive/go1.15.1.zip" && \
unzip go.zip && \
rm -f go.zip && \
cd go-go1.15.1/src/cmd/test2json/ && \
env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" . && \
mv test2json /usr/local/bin/test2json && \
rm -rf /go-go1.15.1

RUN curl -L -o gotestsum.tgz "https://github.com/gotestyourself/gotestsum/releases/download/v0.5.2/gotestsum_0.5.2_linux_amd64.tar.gz" && \
RUN curl -L -o gotestsum.tgz "https://github.com/gotestyourself/gotestsum/releases/download/v1.6.4/gotestsum_1.6.4_linux_amd64.tar.gz" && \
tar -C /usr/local/bin -xzf gotestsum.tgz && \
rm gotestsum.tgz && \
rm /usr/local/bin/LICENSE && \
Expand All @@ -33,8 +25,31 @@ COPY plugins ./plugins

RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
gotestsum --format standard-verbose --junitfile /reports/junit.xml --raw-command -- go test -parallel 5 --json ./... || echo "failed"
gotestsum --format standard-verbose --junitfile ./reports/junit.xml --raw-command -- go test -parallel 5 --json ./... || echo "failed"

RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" -o ./runiac ./cmd/runiac/

FROM hashicorp/terraform:0.14.4

RUN apk update

# Common tools
RUN apk add bash \
&& apk add jq \
&& apk add curl \
&& apk add ca-certificates \
&& rm -rf /var/cache/apk/*

RUN mkdir -p $HOME/.terraform.d/plugins/linux_amd64
RUN mkdir -p $HOME/.terraform.d/plugin-cache

# Grab from builder
COPY --from=builder /app/runiac /usr/local/bin
COPY --from=builder /usr/local/bin/gotestsum /usr/local/bin/gotestsum

ENV TF_IN_AUTOMATION true
ENV GOVERSION ${GOVERSION} # https://github.com/gotestyourself/gotestsum/blob/782abf290e3d93b9c1a48f9aa76b70d65cae66ed/internal/junitxml/report.go#L126

ENTRYPOINT [ "runiac" ]
16 changes: 15 additions & 1 deletion cmd/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,23 @@

# runiac cli

Easily create and run runiac projects!

![](./assets/runiac-new.gif)

## Quick Start

Run the `runiac new` command to initialize a new project directory. Simply answer the prompts as they appear,
and the CLI will automatically create the basic scaffolding for you.

Afterwards, create your infrastructure files according to the deployment tool you wish to use (ARM, Terraform). Once
you are ready, you can have runiac deploy your resources by running: `runiac deploy -a your_account_id -e your_environment`.

Be sure to check out the provided [examples](../../examples) for inspiration!

## Install Locally

```bash
$ go install
$ runiac help
```
```
Binary file added cmd/cli/assets/runiac-new.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions cmd/cli/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,20 @@ var Runner string
var PullRequest string
var StepWhitelist []string

// the base container for runiac
var DefaultBaseContainer = "runiac/deploy:latest-alpine-full"

func init() {
deployCmd.Flags().StringVarP(&AppVersion, "version", "v", "", "Version of the iac code")
deployCmd.Flags().StringVarP(&Environment, "environment", "e", "", "Targeted environment")
deployCmd.Flags().StringVarP(&Account, "account", "a", "", "Targeted Cloud Account (ie. azure subscription, gcp project)")
deployCmd.Flags().StringVarP(&Account, "account", "a", "", "Targeted Cloud Account (ie. azure subscription, gcp project or aws account)")
deployCmd.Flags().StringArrayVarP(&PrimaryRegions, "primary-regions", "p", []string{}, "Primary regions")
deployCmd.Flags().StringArrayVarP(&RegionalRegions, "regional-regions", "r", []string{}, "Regional regions")
deployCmd.Flags().StringArrayVarP(&RegionalRegions, "regional-regions", "r", []string{}, "Runiac will concurrently execute the ./regional directory across these regions setting the runiac_region input variable")
deployCmd.Flags().BoolVar(&DryRun, "dry-run", false, "Dry Run")
deployCmd.Flags().BoolVar(&SelfDestroy, "self-destroy", false, "Teardown after running deploy")
deployCmd.Flags().StringVar(&LogLevel, "log-level", "", "Log level")
deployCmd.Flags().BoolVar(&Interactive, "interactive", false, "Run Docker container in interactive mode")
deployCmd.Flags().StringVarP(&Container, "container", "c", "", "The runiac core container to execute")
deployCmd.Flags().StringVarP(&Container, "container", "c", "", fmt.Sprintf("The runiac deploy container to execute in, defaults to '%s'", DefaultBaseContainer))
deployCmd.Flags().StringVarP(&DeploymentRing, "deployment-ring", "d", "", "The deployment ring to configure")
deployCmd.Flags().BoolVar(&Local, "local", false, "Pre-configure settings to create an isolated configuration specific to the executing machine")
deployCmd.Flags().StringVarP(&Runner, "runner", "", "terraform", "The deployment tool to use for deploying infrastructure")
Expand Down
16 changes: 0 additions & 16 deletions cmd/cli/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,11 @@ import (

"github.com/sirupsen/logrus"
"github.com/spf13/afero"
"github.com/spf13/cobra"
)

var BaseContainer string
var appFS = afero.NewOsFs()

func init() {
initCmd.Flags().StringVar(&BaseContainer, "base-container", "runiac:alpine-azure", "Base Docker image to use containing required tooling")

rootCmd.AddCommand(initCmd)
}

var initCmd = &cobra.Command{
Use: "init",
Short: "Initialize a project",
Long: `Initialize a project`,
Run: func(cmd *cobra.Command, args []string) {

},
}

func InitAction() bool {

logrus.Debug("Creating .runiac directory")
Expand Down
Loading

0 comments on commit 085c266

Please sign in to comment.