Skip to content
This repository was archived by the owner on May 18, 2026. It is now read-only.

Commit 10322a2

Browse files
authored
feat: support env var values as flags values (#269)
* feat: support env var values as flags values * docs: added env var support documentation * test: fixed integration test for env var Signed-off-by: Diego Alfonso <dalfonso@vmware.com>
1 parent a0b57e3 commit 10322a2

731 files changed

Lines changed: 20963 additions & 286669 deletions

File tree

Some content is hidden

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

.github/workflows/ci.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ jobs:
7979
- 1.23.5
8080
env:
8181
REGISTRY_NAME: registry.local
82+
REGISTRY_USERNAME: ruser
83+
REGISTRY_PASSWORD: rpass
8284
BUNDLE: registry.local/integration-test/hellojar:source
8385
TANZU_CLI_NO_INIT: true
8486
TANZU_HOME: $HOME/tanzu
@@ -119,7 +121,7 @@ jobs:
119121
echo "##[group]Install CA"
120122
# https://ubuntu.com/server/docs/security-trust-store
121123
sudo apt-get install -y ca-certificates
122-
sudo cp ${CERT_DIR}/ca.pem /usr/local/share/ca-certificates/ca.crt
124+
# sudo cp ${CERT_DIR}/ca.pem /usr/local/share/ca-certificates/ca.crt
123125
sudo update-ca-certificates
124126
echo "##[endgroup]"
125127
echo "##[group]Generate cert"
@@ -135,11 +137,21 @@ jobs:
135137
set -o errexit
136138
set -o nounset
137139
set -o pipefail
140+
# Create password file
141+
REGISTRY_HTPWD=$(mktemp -d -t htpwd.XXXX)
142+
docker run \
143+
--entrypoint htpasswd \
144+
httpd:2 -Bbn ${REGISTRY_USERNAME} ${REGISTRY_PASSWORD} > ${REGISTRY_HTPWD}/htpasswd
145+
138146
# Run a registry.
139147
docker run -d \
140148
--restart=always \
141149
--name local-registry \
142150
-v ${CERT_DIR}:/certs \
151+
-v ${REGISTRY_HTPWD}:/auth \
152+
-e "REGISTRY_AUTH=htpasswd" \
153+
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
154+
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
143155
-e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
144156
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/server.pem \
145157
-e REGISTRY_HTTP_TLS_KEY=/certs/server-key.pem \

docs/command-reference/tanzu_apps_workload_apply.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ tanzu apps workload apply --file workload.yaml
8080
### SEE ALSO
8181

8282
* [tanzu apps workload](tanzu_apps_workload.md) - Workload lifecycle management
83+
* [environment variable](../working-with-workloads.md#env-vars) support
8384

docs/command-reference/tanzu_apps_workload_create.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,5 @@ tanzu apps workload create --file workload.yaml
8282
### SEE ALSO
8383

8484
* [tanzu apps workload](tanzu_apps_workload.md) - Workload lifecycle management
85+
* [environment variable](../working-with-workloads.md#env-vars) support
8586

docs/commands-details/workload_create_update_apply.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,8 @@ The `.tanzuignore` file should contain a list of filepaths to exclude from the i
631631
### `--source-image`, `-s`
632632
Registry path where the local source code will be uploaded as an image.
633633

634+
[environment variable](../working-with-workloads.md#env-vars) supported
635+
634636
<details><summary>Example</summary>
635637

636638
```bash
@@ -1118,6 +1120,8 @@ spring-pet-clinic-build-1-build-pod[prepare] 2022-06-15T11:28:01.365372427-05:00
11181120
### `--type`
11191121
Sets the type of the workload by adding the label `apps.tanzu.vmware.com/workload-type`, which is very common to be used as a matcher by supply chains.
11201122
1123+
[environment variable](../working-with-workloads.md#env-vars) supported
1124+
11211125
<details><summary>Example</summary>
11221126
11231127
```bash

docs/working-with-workloads.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Tanzu Application Platform supports creating a workload from an existing local p
4343

4444
- `pet-clinic` is the name of the workload.
4545
- `--local-path` points to the directory where the source code is located.
46-
- `--source-image` is the registry path where the local source code will be uploaded as an image.
46+
- `--source-image` is the registry path where the local source code will be uploaded as an image. It can be set by an [environment variable](#env-vars)
4747

4848
**Exclude Files**
4949
When working with local source code, you can exclude files from the source code to be uploaded within the image by creating a file `.tanzuignore` at the root of the source code. You can find the options available to specify the workload in the command reference for [`workload create`](command-reference/tanzu_apps_workload_create.md), or you can run `tanzu apps workload create --help`.
@@ -118,6 +118,22 @@ tanzu apps workload create petclinic-image --param-yaml maven=$"artifactId:hello
118118
tanzu apps workload create petclinic-image --param-yaml maven="{"artifactId":"hello-world", "type": "jar", "version": "0.0.1", "groupId": "carto.run"}"
119119
```
120120
121+
### <a id="env-vars"></a> Create and Apply environment variables
122+
123+
Developers will provide the same flags/values repeatedly when iterating on their application code.
124+
Typing or *copy*/*pasting* the flag values for every workload `create`/`apply` adds friction to the developer workflow.
125+
126+
For this reason the apps plugin support the use some environment variables to set those values for the following flags:
127+
128+
- `--type`: `TANZU_APPS_TYPE`
129+
- `--registry-ca-cert`: `TANZU_APPS_REGISTRY_CA_CERT`
130+
- `--registry-password`: `TANZU_APPS_REGISTRY_PASSWORD`
131+
- `--registry-username`: `TANZU_APPS_REGISTRY_USERNAME`
132+
- `--registry-token`: `TANZU_APPS_REGISTRY_TOKEN`
133+
- `--source-image`: `TANZU_APPS_SOURCE_IMAGE`
134+
135+
**Note:** Be aware that when set a supported environment value, each apps plugin command will set the flag with the value on the environment variable value
136+
121137
## <a id='service-binding'></a> Bind a Service to a Workload
122138
123139
Multiple services can be configured for each workload. The cluster supply chain is in charge of provisioning those services.

go.mod

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/google/go-cmp v0.5.8
1313
github.com/google/go-containerregistry v0.11.0
1414
github.com/spf13/cobra v1.5.0
15+
github.com/spf13/viper v1.12.0
1516
github.com/stern/stern v1.21.0
1617
github.com/stretchr/testify v1.8.0
1718
github.com/vmware-labs/reconciler-runtime v0.7.1
@@ -30,8 +31,10 @@ require (
3031
)
3132

3233
require (
33-
cloud.google.com/go v0.99.0 // indirect
34-
cloud.google.com/go/storage v1.18.2 // indirect
34+
cloud.google.com/go v0.102.0 // indirect
35+
cloud.google.com/go/compute v1.7.0 // indirect
36+
cloud.google.com/go/iam v0.3.0 // indirect
37+
cloud.google.com/go/storage v1.22.1 // indirect
3538
github.com/Azure/azure-sdk-for-go v66.0.0+incompatible // indirect
3639
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
3740
github.com/Azure/go-autorest/autorest v0.11.23 // indirect
@@ -62,12 +65,9 @@ require (
6265
github.com/beorn7/perks v1.0.1 // indirect
6366
github.com/blang/semver v3.5.1+incompatible // indirect
6467
github.com/briandowns/spinner v1.18.0 // indirect
65-
github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
6668
github.com/cespare/xxhash/v2 v2.1.2 // indirect
6769
github.com/cheggaaa/pb v1.0.29 // indirect
6870
github.com/cheggaaa/pb/v3 v3.1.0 // indirect
69-
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4 // indirect
70-
github.com/cncf/xds/go v0.0.0-20211130200136-a8f946100490 // indirect
7171
github.com/containerd/stargz-snapshotter/estargz v0.12.0 // indirect
7272
github.com/coredns/caddy v1.1.1 // indirect
7373
github.com/coredns/corefile-migration v1.0.17 // indirect
@@ -84,11 +84,9 @@ require (
8484
github.com/docker/go-units v0.4.0 // indirect
8585
github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46 // indirect
8686
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
87-
github.com/envoyproxy/go-control-plane v0.10.1 // indirect
88-
github.com/envoyproxy/protoc-gen-validate v0.6.2 // indirect
8987
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
9088
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
91-
github.com/fsnotify/fsnotify v1.5.1 // indirect
89+
github.com/fsnotify/fsnotify v1.5.4 // indirect
9290
github.com/ghodss/yaml v1.0.0 // indirect
9391
github.com/go-openapi/analysis v0.19.5 // indirect
9492
github.com/go-openapi/errors v0.19.2 // indirect
@@ -112,7 +110,9 @@ require (
112110
github.com/google/go-querystring v1.1.0 // indirect
113111
github.com/google/gofuzz v1.2.0 // indirect
114112
github.com/google/uuid v1.3.0 // indirect
115-
github.com/googleapis/gax-go/v2 v2.1.1 // indirect
113+
github.com/googleapis/enterprise-certificate-proxy v0.0.0-20220520183353-fd19c99a87aa // indirect
114+
github.com/googleapis/gax-go/v2 v2.4.0 // indirect
115+
github.com/googleapis/go-type-adapters v1.0.0 // indirect
116116
github.com/hashicorp/go-version v1.4.0 // indirect
117117
github.com/hashicorp/hcl v1.0.0 // indirect
118118
github.com/huandu/xstrings v1.3.2 // indirect
@@ -130,7 +130,7 @@ require (
130130
github.com/klauspost/compress v1.15.8 // indirect
131131
github.com/lithammer/dedent v1.1.0 // indirect
132132
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
133-
github.com/magiconair/properties v1.8.5 // indirect
133+
github.com/magiconair/properties v1.8.6 // indirect
134134
github.com/mailru/easyjson v0.7.7 // indirect
135135
github.com/mattn/go-colorable v0.1.12 // indirect
136136
github.com/mattn/go-isatty v0.0.14 // indirect
@@ -139,7 +139,7 @@ require (
139139
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
140140
github.com/mitchellh/copystructure v1.2.0 // indirect
141141
github.com/mitchellh/go-homedir v1.1.0 // indirect
142-
github.com/mitchellh/mapstructure v1.4.3 // indirect
142+
github.com/mitchellh/mapstructure v1.5.0 // indirect
143143
github.com/mitchellh/reflectwalk v1.0.2 // indirect
144144
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
145145
github.com/modern-go/reflect2 v1.0.2 // indirect
@@ -148,7 +148,8 @@ require (
148148
github.com/onsi/gomega v1.19.0 // indirect
149149
github.com/opencontainers/go-digest v1.0.0 // indirect
150150
github.com/opencontainers/image-spec v1.0.3-0.20220114050600-8b9d41f48198 // indirect
151-
github.com/pelletier/go-toml v1.9.4 // indirect
151+
github.com/pelletier/go-toml v1.9.5 // indirect
152+
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
152153
github.com/pkg/errors v0.9.1 // indirect
153154
github.com/pmezard/go-difflib v1.0.0 // indirect
154155
github.com/prometheus/client_golang v1.12.1 // indirect
@@ -159,14 +160,13 @@ require (
159160
github.com/russross/blackfriday/v2 v2.1.0 // indirect
160161
github.com/shopspring/decimal v1.2.0 // indirect
161162
github.com/sirupsen/logrus v1.9.0 // indirect
162-
github.com/spf13/afero v1.6.0 // indirect
163-
github.com/spf13/cast v1.4.1 // indirect
163+
github.com/spf13/afero v1.8.2 // indirect
164+
github.com/spf13/cast v1.5.0 // indirect
164165
github.com/spf13/jwalterweatherman v1.1.0 // indirect
165166
github.com/spf13/pflag v1.0.5 // indirect
166-
github.com/spf13/viper v1.10.1 // indirect
167167
github.com/stoewer/go-strcase v1.2.0 // indirect
168168
github.com/stretchr/objx v0.4.0 // indirect
169-
github.com/subosito/gotenv v1.2.0 // indirect
169+
github.com/subosito/gotenv v1.3.0 // indirect
170170
github.com/valyala/fastjson v1.6.3 // indirect
171171
github.com/vbatts/tar-split v0.11.2 // indirect
172172
github.com/vdemeester/k8s-pkg-credentialprovider v1.22.4 // indirect
@@ -188,17 +188,17 @@ require (
188188
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 // indirect
189189
golang.org/x/text v0.3.7 // indirect
190190
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect
191-
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
191+
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
192192
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
193193
gomodules.xyz/jsonpatch/v3 v3.0.1 // indirect
194194
gomodules.xyz/orderedmap v0.1.0 // indirect
195-
google.golang.org/api v0.63.0 // indirect
195+
google.golang.org/api v0.84.0 // indirect
196196
google.golang.org/appengine v1.6.7 // indirect
197-
google.golang.org/genproto v0.0.0-20220308174144-ae0e22291548 // indirect
198-
google.golang.org/grpc v1.44.0 // indirect
197+
google.golang.org/genproto v0.0.0-20220616135557-88e70c0c3a90 // indirect
198+
google.golang.org/grpc v1.47.0 // indirect
199199
google.golang.org/protobuf v1.28.0 // indirect
200200
gopkg.in/inf.v0 v0.9.1 // indirect
201-
gopkg.in/ini.v1 v1.66.2 // indirect
201+
gopkg.in/ini.v1 v1.66.4 // indirect
202202
gopkg.in/yaml.v2 v2.4.0 // indirect
203203
gopkg.in/yaml.v3 v3.0.1 // indirect
204204
k8s.io/apiserver v0.24.0 // indirect

0 commit comments

Comments
 (0)