Tanzu Application Platform (TAP) で、Private Git Repository上のソースコードからアプリをデプロイする際のメモ。
⚠️
ootb_supply_chain_basic.gitops.commit_strategy
がpull_request
の場合、この通りではありません。
ドキュメントは次を参照。
- https://docs.vmware.com/en/VMware-Tanzu-Application-Platform/1.2/tap/GUID-scc-building-from-source.html#private-gitrepository-1
- https://docs.vmware.com/en/VMware-Tanzu-Application-Platform/1.2/tap/GUID-scc-git-auth.html
ここではsshではなく、basic認証を使用します。
目次
GitHubの場合
次の図の様にrepoに対するアクセストークンを作成します。

次のSecretを対象のnamespaceに作成します。
GIT_SERVER=github.com
GIT_USERNAME=making
GIT_PASSWORD=ghp_Nnh*******
cat <<EOF > git-basic.yaml
apiVersion: v1
kind: Secret
metadata:
name: git-basic
annotations:
tekton.dev/git-0: https://${GIT_SERVER}
type: kubernetes.io/basic-auth
stringData:
username: ${GIT_USERNAME}
password: ${GIT_PASSWORD}
EOF
kubectl apply -f git-basic.yaml -n demo
Workloadが使用するService AccountにもこのSecretを設定します。
kubectl patch serviceaccount default -p "{\"secrets\":[{\"name\":\"git-basic\"}]}" -n demo
Private Git Repository上のソースコードを用意します。ここでは次のリポジトリを使用します。
https://github.com/making/helloworld

次のようにWorkload作成時に、gitops_ssh_secret
パラメータにこのSecretを渡します。
tanzu apps workload apply helloworld \
--app helloworld \
--git-repo https://github.com/making/helloworld \
--git-branch main \
--type web \
--param gitops_ssh_secret=git-basic \
--build-env BP_JVM_VERSION=17 \
-n demo \
-y
TAPインストール時の
tap-values.yml
のootb_supply_chain_basic.gitops.ssh_secret
にgitops_ssh_secret
パラメータのデフォルト値を設定できます
gitrepoリソースを見て、READYがTrueになっていればソースコードを取得できています。
$ kubectl get gitrepo -n demo helloworld
NAME URL READY STATUS AGE
helloworld https://github.com/making/helloworld True Fetched revision: main/78e806b95a842748c1f6f3db13212330e120f80d 26s
Workloadが無事デプロイされればOKです。
$ tanzu apps workload get -n demo helloworld
---
# helloworld: Ready
---
Source
type: git
url: https://github.com/making/helloworld
branch: main
Supply Chain
name: source-to-url
last update: 94s
ready: True
RESOURCE READY TIME
source-provider True 10m
deliverable True 10m
image-provider True 2m3s
config-provider True 114s
app-config True 114s
config-writer True 94s
Issues
No issues reported.
Pods
NAME STATUS RESTARTS AGE
helloworld-00001-deployment-58f7fd4764-2m5dx Running 0 49s
helloworld-build-1-build-pod Succeeded 0 10m
helloworld-config-writer-cgv7d-pod Succeeded 0 110s
Knative Services
NAME READY URL
helloworld Ready http://helloworld-demo.vcap.me
To see logs: "tanzu apps workload tail helloworld --namespace demo"
Bitbucketの場合
次の図の様にrepoに対するアクセストークンを作成します。

Git Repositoryからソースコードを取得するだけであれば、Read権限だけでも良いですが、このSecretはGitOpsでmanifestを書き込む場合にも使用されるので、Write権限もあった方が良いです。
次のSecretを対象のnamespaceに作成します。
GIT_SERVER=bitbucket.org
GIT_USERNAME=tmaki_vmware
GIT_PASSWORD=ATBBg************
cat <<EOF > git-basic.yaml
apiVersion: v1
kind: Secret
metadata:
name: git-basic
annotations:
tekton.dev/git-0: https://${GIT_SERVER}
type: kubernetes.io/basic-auth
stringData:
username: ${GIT_USERNAME}
password: ${GIT_PASSWORD}
EOF
kubectl apply -f git-basic.yaml -n demo
Workloadが使用するService AccountにもこのSecretを設定します。
kubectl patch serviceaccount default -p "{\"secrets\":[{\"name\":\"git-basic\"}]}" -n demo
Private Git Repository上のソースコードを用意します。ここでは次のリポジトリを使用します。
https://bitbucket.org/tmaki_vmware/helloworld

次のようにWorkload作成時に、gitops_ssh_secret
パラメータにこのSecretを渡します。
tanzu apps workload apply helloworld \
--app helloworld \
--git-repo https://bitbucket.org/tmaki_vmware/helloworld \
--git-branch main \
--type web \
--param gitops_ssh_secret=git-basic \
--build-env BP_JVM_VERSION=17 \
-n demo \
-y
TAPインストール時の
tap-values.yml
のootb_supply_chain_basic.gitops.ssh_secret
にgitops_ssh_secret
パラメータのデフォルト値を設定できます
gitrepoリソースを見て、READYがTrueになっていればソースコードを取得できています。
$ kubectl get gitrepo -n demo helloworld
NAME URL READY STATUS AGE
helloworld https://bitbucket.org/tmaki_vmware/helloworld True Fetched revision: main/78e806b95a842748c1f6f3db13212330e120f80d 26s
Workloadが無事デプロイされればOKです。
$ tanzu apps workload get -n demo helloworld
---
# helloworld: Ready
---
Source
type: git
url: https://bitbucket.org/tmaki_vmware/helloworld
branch: main
Supply Chain
name: source-to-url
last update: 94s
ready: True
RESOURCE READY TIME
source-provider True 10m
deliverable True 10m
image-provider True 2m3s
config-provider True 114s
app-config True 114s
config-writer True 94s
Issues
No issues reported.
Pods
NAME STATUS RESTARTS AGE
helloworld-00001-deployment-58f7fd4764-2m5dx Running 0 49s
helloworld-build-1-build-pod Succeeded 0 10m
helloworld-config-writer-cgv7d-pod Succeeded 0 110s
Knative Services
NAME READY URL
helloworld Ready http://helloworld-demo.vcap.me
To see logs: "tanzu apps workload tail helloworld --namespace demo"