Skip to content

Commit 4831482

Browse files
Merge pull request #27 from coreydaley/jira_ship_0004_build_env_vars
SHIP-0004: Build Environment Variables
2 parents 44c0a85 + 0fef193 commit 4831482

File tree

308 files changed

+18206
-17770
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

308 files changed

+18206
-17770
lines changed

.github/workflows/e2e.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,12 @@ jobs:
2424

2525
- name: Check out code into the Go module directory
2626
uses: actions/checkout@v2
27+
with:
28+
submodules: recursive
2729

2830
- name: Install Tools
2931
run: sudo apt-get update && sudo apt-get install -y make gcc
3032

31-
- name: Setup BATS
32-
uses: mig4/setup-bats@v1
33-
with:
34-
bats-version: 1.2.1
35-
3633
- name: Install kubectl
3734
uses: azure/setup-kubectl@v1
3835
with:

.gitmodules

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[submodule "test/e2e/bats/core"]
2+
path = test/e2e/bats/core
3+
url = https://github.com/bats-core/bats-core
4+
[submodule "test/e2e/bats/support"]
5+
path = test/e2e/bats/support
6+
url = https://github.com/bats-core/bats-support
7+
[submodule "test/e2e/bats/assert"]
8+
path = test/e2e/bats/assert
9+
url = https://github.com/bats-core/bats-assert
10+
[submodule "test/e2e/bats/file"]
11+
path = test/e2e/bats/file
12+
url = https://github.com/bats-core/bats-file

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ test: test-unit test-e2e
4949
test-unit:
5050
go test $(GO_FLAGS) $(GO_TEST_FLAGS) $(CMD) $(PKG) $(ARGS)
5151

52-
# runs all end-to-end tests using bats, it assumes bats is installed
52+
# looks for *.bats files in the test/e2e directory and runs them
5353
test-e2e:
54-
./test/e2e/e2e.bats
54+
./test/e2e/bats/core/bin/bats --recursive test/e2e/*.bats
5555

5656
# wait for KinD cluster to be on ready state, so tests can be performed
5757
verify-kind:

docs/testing.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,22 @@ The install script waits for the Controller instance to be running.
5454
[BATS][batsCore] is a testing framework for Bash. It's structured as a regular script with enhanced
5555
syntax to define test cases, collect results, and more.
5656

57-
To run BATS based tests, make sure you have `bats` installed, and then execute:
57+
The BATS core tool and it's supporting libraries are linked in this project as `git submodules`,
58+
alleviating the need to install BATS yourself.
59+
60+
To run BATS based tests, make sure that you have cloned the project (including all submodules):
61+
62+
```sh
63+
# Option 1: Clone the repository and populate submodules right away
64+
git clone --recurse-submodules --depth 1 https://github.com/shipwright-io/cli.git
65+
66+
# Option 2: Populate submodules after cloning
67+
cd /your/project/directory/cli
68+
git submodule init
69+
git submodule update
70+
```
71+
72+
then run:
5873

5974
```sh
6075
make test-e2e

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ go 1.15
55
require (
66
github.com/mailru/easyjson v0.7.1 // indirect
77
github.com/onsi/gomega v1.10.3
8-
github.com/shipwright-io/build v0.5.2-0.20210715083206-5d8fb411a1eb
9-
github.com/spf13/cobra v1.1.3
8+
github.com/shipwright-io/build v0.6.0
9+
github.com/spf13/cobra v1.2.1
1010
github.com/spf13/pflag v1.0.5
1111
github.com/texttheater/golang-levenshtein/levenshtein v0.0.0-20200805054039-cae8b0eaed6c
12-
k8s.io/api v0.20.2
13-
k8s.io/apimachinery v0.20.2
12+
k8s.io/api v0.20.6
13+
k8s.io/apimachinery v0.20.6
1414
k8s.io/cli-runtime v0.20.2
15-
k8s.io/client-go v0.20.2
15+
k8s.io/client-go v0.20.6
1616
k8s.io/utils v0.0.0-20210629042839-4a2b36d8d73f
1717
)
1818

go.sum

Lines changed: 415 additions & 0 deletions
Large diffs are not rendered by default.

pkg/shp/cmd/build/create.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import (
44
"fmt"
55

66
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
7-
"github.com/shipwright-io/cli/pkg/shp/cmd/runner"
8-
"github.com/shipwright-io/cli/pkg/shp/flags"
9-
"github.com/shipwright-io/cli/pkg/shp/params"
107
"github.com/spf13/cobra"
118

129
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1310
"k8s.io/cli-runtime/pkg/genericclioptions"
11+
12+
"github.com/shipwright-io/cli/pkg/shp/cmd/runner"
13+
"github.com/shipwright-io/cli/pkg/shp/flags"
14+
"github.com/shipwright-io/cli/pkg/shp/params"
15+
"github.com/shipwright-io/cli/pkg/shp/util"
1416
)
1517

1618
// CreateCommand contains data input from user
@@ -59,6 +61,13 @@ func (c *CreateCommand) Run(params *params.Params, io *genericclioptions.IOStrea
5961
},
6062
Spec: *c.buildSpec,
6163
}
64+
65+
envs, err := c.cmd.Flags().GetStringArray("env")
66+
if err != nil {
67+
return err
68+
}
69+
b.Spec.Env = append(b.Spec.Env, util.StringSliceToEnvVarSlice(envs)...)
70+
6271
flags.SanitizeBuildSpec(&b.Spec)
6372

6473
clientset, err := params.ShipwrightClientSet()

pkg/shp/cmd/buildrun/create.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import (
44
"fmt"
55

66
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
7-
"github.com/shipwright-io/cli/pkg/shp/cmd/runner"
8-
"github.com/shipwright-io/cli/pkg/shp/flags"
9-
"github.com/shipwright-io/cli/pkg/shp/params"
107
"github.com/spf13/cobra"
118

129
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1310
"k8s.io/cli-runtime/pkg/genericclioptions"
11+
12+
"github.com/shipwright-io/cli/pkg/shp/cmd/runner"
13+
"github.com/shipwright-io/cli/pkg/shp/flags"
14+
"github.com/shipwright-io/cli/pkg/shp/params"
15+
"github.com/shipwright-io/cli/pkg/shp/util"
1416
)
1517

1618
// CreateCommand reprents the build's create subcommand.
@@ -60,6 +62,13 @@ func (c *CreateCommand) Run(params *params.Params, ioStreams *genericclioptions.
6062
},
6163
Spec: *c.buildRunSpec,
6264
}
65+
66+
envs, err := c.cmd.Flags().GetStringArray("env")
67+
if err != nil {
68+
return err
69+
}
70+
br.Spec.Env = append(br.Spec.Env, util.StringSliceToEnvVarSlice(envs)...)
71+
6372
flags.SanitizeBuildRunSpec(&br.Spec)
6473

6574
clientset, err := params.ShipwrightClientSet()

pkg/shp/flags/build.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package flags
33
import (
44
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
55
"github.com/spf13/pflag"
6+
67
corev1 "k8s.io/api/core/v1"
78
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
89
"k8s.io/utils/pointer"
@@ -37,6 +38,7 @@ func BuildSpecFromFlags(flags *pflag.FlagSet) *buildv1alpha1.BuildSpec {
3738
imageFlags(flags, "builder", spec.Builder)
3839
imageFlags(flags, "output", &spec.Output)
3940
timeoutFlags(flags, spec.Timeout)
41+
envFlags(flags, spec.Env)
4042

4143
return spec
4244
}
@@ -56,6 +58,9 @@ func SanitizeBuildSpec(b *buildv1alpha1.BuildSpec) {
5658
if b.Builder.Image == "" && b.Builder.Credentials == nil {
5759
b.Builder = nil
5860
}
61+
if len(b.Env) == 0 {
62+
b.Env = nil
63+
}
5964
}
6065
if b.Timeout != nil && b.Timeout.Duration == 0 {
6166
b.Timeout = nil

pkg/shp/flags/buildrun.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ func BuildRunSpecFromFlags(flags *pflag.FlagSet) *buildv1alpha1.BuildRunSpec {
2020
Output: &buildv1alpha1.Image{
2121
Credentials: &corev1.LocalObjectReference{},
2222
},
23+
Env: []corev1.EnvVar{},
2324
}
2425

2526
buildRefFlags(flags, spec.BuildRef)
2627
serviceAccountFlags(flags, spec.ServiceAccount)
2728
timeoutFlags(flags, spec.Timeout)
2829
imageFlags(flags, "output", spec.Output)
30+
envFlags(flags, spec.Env)
2931

3032
return spec
3133
}
@@ -52,4 +54,8 @@ func SanitizeBuildRunSpec(br *buildv1alpha1.BuildRunSpec) {
5254
if br.Timeout != nil && br.Timeout.Duration == 0 {
5355
br.Timeout = nil
5456
}
57+
58+
if len(br.Env) == 0 {
59+
br.Env = nil
60+
}
5561
}

0 commit comments

Comments
 (0)