Skip to content

Commit 085c266

Browse files
mbpolantiny-dancer
andauthored
Add "new" command for scaffolding projects (#15)
Co-authored-by: mg <grose.matthewf@gmail.com>
1 parent 173e9e7 commit 085c266

File tree

16 files changed

+676
-41
lines changed

16 files changed

+676
-41
lines changed

.github/workflows/build.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,20 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v2
14-
- name: "build containers"
15-
run: ./scripts/build_containers.sh
16-
- name: Publish Unit Test Results
17-
uses: EnricoMi/publish-unit-test-result-action@v1.7
14+
- uses: actions/setup-go@v2
15+
with:
16+
go-version: "^1.16.4"
17+
- name: Setup gotestsum
18+
uses: autero1/action-gotestsum@v1.0.0
19+
with:
20+
gotestsum_version: 1.6.4
21+
- name: "go test"
22+
run: |
23+
rm -rf ./reports && mkdir ./reports;
24+
gotestsum --format standard-verbose --junitfile ./reports/junit.xml --raw-command -- go test -parallel 5 --json ./...;
25+
- name: Upload Test Results
1826
if: always()
27+
uses: actions/upload-artifact@v2
1928
with:
20-
github_token: ${{ secrets.GITHUB_TOKEN }}
21-
files: reports/*.xml
29+
name: Unit Test Results
30+
path: reports/*.xml

build/package/alpine-builder/Dockerfile

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,7 @@ FROM golang:${GOVERSION} as builder
66

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

9-
RUN curl -Lo go.zip "https://github.com/golang/go/archive/go1.15.1.zip" && \
10-
unzip go.zip && \
11-
rm -f go.zip && \
12-
cd go-go1.15.1/src/cmd/test2json/ && \
13-
env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" . && \
14-
mv test2json /usr/local/bin/test2json && \
15-
rm -rf /go-go1.15.1
16-
17-
RUN curl -L -o gotestsum.tgz "https://github.com/gotestyourself/gotestsum/releases/download/v0.5.2/gotestsum_0.5.2_linux_amd64.tar.gz" && \
9+
RUN curl -L -o gotestsum.tgz "https://github.com/gotestyourself/gotestsum/releases/download/v1.6.4/gotestsum_1.6.4_linux_amd64.tar.gz" && \
1810
tar -C /usr/local/bin -xzf gotestsum.tgz && \
1911
rm gotestsum.tgz && \
2012
rm /usr/local/bin/LICENSE && \
@@ -33,8 +25,31 @@ COPY plugins ./plugins
3325

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

3830
RUN --mount=type=cache,target=/go/pkg/mod \
3931
--mount=type=cache,target=/root/.cache/go-build \
4032
env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" -o ./runiac ./cmd/runiac/
33+
34+
FROM hashicorp/terraform:0.14.4
35+
36+
RUN apk update
37+
38+
# Common tools
39+
RUN apk add bash \
40+
&& apk add jq \
41+
&& apk add curl \
42+
&& apk add ca-certificates \
43+
&& rm -rf /var/cache/apk/*
44+
45+
RUN mkdir -p $HOME/.terraform.d/plugins/linux_amd64
46+
RUN mkdir -p $HOME/.terraform.d/plugin-cache
47+
48+
# Grab from builder
49+
COPY --from=builder /app/runiac /usr/local/bin
50+
COPY --from=builder /usr/local/bin/gotestsum /usr/local/bin/gotestsum
51+
52+
ENV TF_IN_AUTOMATION true
53+
ENV GOVERSION ${GOVERSION} # https://github.com/gotestyourself/gotestsum/blob/782abf290e3d93b9c1a48f9aa76b70d65cae66ed/internal/junitxml/report.go#L126
54+
55+
ENTRYPOINT [ "runiac" ]

cmd/cli/README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,23 @@
99

1010
# runiac cli
1111

12+
Easily create and run runiac projects!
13+
14+
![](./assets/runiac-new.gif)
15+
16+
## Quick Start
17+
18+
Run the `runiac new` command to initialize a new project directory. Simply answer the prompts as they appear,
19+
and the CLI will automatically create the basic scaffolding for you.
20+
21+
Afterwards, create your infrastructure files according to the deployment tool you wish to use (ARM, Terraform). Once
22+
you are ready, you can have runiac deploy your resources by running: `runiac deploy -a your_account_id -e your_environment`.
23+
24+
Be sure to check out the provided [examples](../../examples) for inspiration!
25+
1226
## Install Locally
1327

1428
```bash
1529
$ go install
1630
$ runiac help
17-
```
31+
```

cmd/cli/assets/runiac-new.gif

597 KB
Loading

cmd/cli/cmd/deploy.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,20 @@ var Runner string
3636
var PullRequest string
3737
var StepWhitelist []string
3838

39+
// the base container for runiac
40+
var DefaultBaseContainer = "runiac/deploy:latest-alpine-full"
41+
3942
func init() {
4043
deployCmd.Flags().StringVarP(&AppVersion, "version", "v", "", "Version of the iac code")
4144
deployCmd.Flags().StringVarP(&Environment, "environment", "e", "", "Targeted environment")
42-
deployCmd.Flags().StringVarP(&Account, "account", "a", "", "Targeted Cloud Account (ie. azure subscription, gcp project)")
45+
deployCmd.Flags().StringVarP(&Account, "account", "a", "", "Targeted Cloud Account (ie. azure subscription, gcp project or aws account)")
4346
deployCmd.Flags().StringArrayVarP(&PrimaryRegions, "primary-regions", "p", []string{}, "Primary regions")
44-
deployCmd.Flags().StringArrayVarP(&RegionalRegions, "regional-regions", "r", []string{}, "Regional regions")
47+
deployCmd.Flags().StringArrayVarP(&RegionalRegions, "regional-regions", "r", []string{}, "Runiac will concurrently execute the ./regional directory across these regions setting the runiac_region input variable")
4548
deployCmd.Flags().BoolVar(&DryRun, "dry-run", false, "Dry Run")
4649
deployCmd.Flags().BoolVar(&SelfDestroy, "self-destroy", false, "Teardown after running deploy")
4750
deployCmd.Flags().StringVar(&LogLevel, "log-level", "", "Log level")
4851
deployCmd.Flags().BoolVar(&Interactive, "interactive", false, "Run Docker container in interactive mode")
49-
deployCmd.Flags().StringVarP(&Container, "container", "c", "", "The runiac core container to execute")
52+
deployCmd.Flags().StringVarP(&Container, "container", "c", "", fmt.Sprintf("The runiac deploy container to execute in, defaults to '%s'", DefaultBaseContainer))
5053
deployCmd.Flags().StringVarP(&DeploymentRing, "deployment-ring", "d", "", "The deployment ring to configure")
5154
deployCmd.Flags().BoolVar(&Local, "local", false, "Pre-configure settings to create an isolated configuration specific to the executing machine")
5255
deployCmd.Flags().StringVarP(&Runner, "runner", "", "terraform", "The deployment tool to use for deploying infrastructure")

cmd/cli/cmd/init.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,11 @@ import (
55

66
"github.com/sirupsen/logrus"
77
"github.com/spf13/afero"
8-
"github.com/spf13/cobra"
98
)
109

1110
var BaseContainer string
1211
var appFS = afero.NewOsFs()
1312

14-
func init() {
15-
initCmd.Flags().StringVar(&BaseContainer, "base-container", "runiac:alpine-azure", "Base Docker image to use containing required tooling")
16-
17-
rootCmd.AddCommand(initCmd)
18-
}
19-
20-
var initCmd = &cobra.Command{
21-
Use: "init",
22-
Short: "Initialize a project",
23-
Long: `Initialize a project`,
24-
Run: func(cmd *cobra.Command, args []string) {
25-
26-
},
27-
}
28-
2913
func InitAction() bool {
3014

3115
logrus.Debug("Creating .runiac directory")

0 commit comments

Comments
 (0)