IK.AM

@making's tech note


Tanzu Application PlatformでPrivate Git Repository上のソースコードをデプロイする

🗃 {Dev/CaaS/Kubernetes/TAP}
🏷 Kubernetes 🏷 Cartographer 🏷 Tanzu 🏷 TAP 
🗓 Updated at 2022-09-12T08:46:47Z  🗓 Created at 2022-09-12T04:50:35Z   🌎 English Page

⚠️ 本記事の内容はVMwareによってサポートされていません。 記事の内容で生じた問題については自己責任で対応し、 VMwareサポート窓口には問い合わせないでください

Tanzu Application Platform (TAP) で、Private Git Repository上のソースコードからアプリをデプロイする際のメモ。

⚠️ ootb_supply_chain_basic.gitops.commit_strategypull_request の場合、この通りではありません。

ドキュメントは次を参照。

ここではsshではなく、basic認証を使用します。

目次

GitHubの場合

次の図の様にrepoに対するアクセストークンを作成します。

image

次の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

image

次のように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.ymlootb_supply_chain_basic.gitops.ssh_secretgitops_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に対するアクセストークンを作成します。

image

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

image

次のように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.ymlootb_supply_chain_basic.gitops.ssh_secretgitops_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"

✒️️ Edit  ⏰ History  🗑 Delete