Skip to content

Commit

Permalink
update workflow to use github-user and github-token
Browse files Browse the repository at this point in the history
  • Loading branch information
intelliguy committed Mar 21, 2022
1 parent 62cbf52 commit 1302e56
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 31 deletions.
35 changes: 20 additions & 15 deletions github_repo/create-cluster-repo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ spec:
value: "cluster_uuid"
- name: template_name
value: "template-std"
- name: github_id
value: "github_id"
- name: github_usertoken
value: "github_usertoken"

templates:
- name: createClusterRepo
activeDeadlineSeconds: 120
Expand All @@ -24,12 +29,12 @@ spec:
- /bin/bash
- -ecx
- |
echo $TOKEN | gh auth login --with-token
echo $GITHUB_USERTOKEN | gh auth login --with-token
gh repo create tks-management/${CLUSTER_ID} --private --confirm
gh repo create tks-management/${CLUSTER_ID}-manifests --private --confirm
gh repo create ${GITHUB_ID}/${CLUSTER_ID} --private --confirm
gh repo create ${GITHUB_ID}/${CLUSTER_ID}-manifests --private --confirm
git clone https://$(echo -n $TOKEN)@github.com/tks-management/${CONTRACT_ID}.git
git clone https://$(echo -n $GITHUB_USERTOKEN)@github.com/${GITHUB_ID}/${CONTRACT_ID}.git
cp -r ${CONTRACT_ID}/${TEMPLATE_NAME} ${CLUSTER_ID}/${CLUSTER_ID}
cp -r ${CONTRACT_ID}/_github/ ${CLUSTER_ID}/.github
Expand All @@ -47,7 +52,7 @@ spec:
git add *
git commit -m "add new ${CLUSTER_ID} site"
git branch -M main
git remote set-url origin https://$(echo -n $TOKEN)@github.com/tks-management/${CLUSTER_ID}
git remote set-url origin https://$(echo -n $GITHUB_USERTOKEN)@github.com/${GITHUB_ID}/${CLUSTER_ID}
git remote -v
git push -u origin main
cd ..
Expand All @@ -57,7 +62,7 @@ spec:
git add README
git commit -m "add new ${CLUSTER_ID} site"
git branch -M main
git remote set-url origin https://$(echo -n $TOKEN)@github.com/tks-management/${CLUSTER_ID}-manifests
git remote set-url origin https://$(echo -n $GITHUB_USERTOKEN)@github.com/${GITHUB_ID}/${CLUSTER_ID}-manifests
git remote -v
git push -u origin main
cd ..
Expand All @@ -70,17 +75,17 @@ spec:
gh run list --workflow GenerateYaml --limit 1
gh run watch $(gh run list --workflow GenerateYaml --limit 1| grep $CLUSTER_ID | awk -F push '{print $2}' | awk '{print $1}')
envFrom:
- secretRef:
name: "github-tks-mgmt-token"
env:
- name: CONTRACT_ID
value: "{{workflow.parameters.contract_id}}"
- name: CLUSTER_ID
value: "{{workflow.parameters.cluster_id}}"
- name: TEMPLATE_NAME
value: "{{workflow.parameters.template_name}}"

- name: GITHUB_ID
value: "{{workflow.parameters.github_id}}"
- name: GITHUB_USERTOKEN
value: "{{workflow.parameters.github_usertoken}}"
- name: createRepoCredential
activeDeadlineSeconds: 120
container:
Expand All @@ -91,21 +96,21 @@ spec:
- /bin/bash
- -ecx
- |
echo "===== Connect github repo tks-management/${CLUSTER_ID}-manifests with token ====="
echo "===== Connect github repo ${GITHUB_ID}/${CLUSTER_ID}-manifests with token ====="
# log into Argo CD server
./argocd login $ARGO_SERVER --plaintext --insecure --username $ARGO_USERNAME \
--password $ARGO_PASSWORD
./argocd repo add https://github.com/tks-management/${CLUSTER_ID}-manifests --username ${USERNAME} --password ${TOKEN}
./argocd repo add https://github.com/${GITHUB_ID}/${CLUSTER_ID}-manifests --username ${USERNAME} --password ${TOKEN}
envFrom:
- secretRef:
name: "github-tks-mgmt-token"
- secretRef:
name: "decapod-argocd-config"
env:
- name: CLUSTER_ID
value: "{{workflow.parameters.cluster_id}}"

- name: GITHUB_ID
value: "{{workflow.parameters.github_id}}"

- name: main
steps:
- - name: createClusterRepo
Expand Down
25 changes: 15 additions & 10 deletions github_repo/create-contract-repo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ spec:
parameters:
- name: contract_id
value: "contract_uuid"
- name: github_id
value: "github_id"
- name: github_usertoken
value: "github_usertoken"
templates:
- name: createContractRepo
activeDeadlineSeconds: 120
Expand All @@ -20,19 +24,19 @@ spec:
- /bin/bash
- -ecx
- |
echo $TOKEN | gh auth login --with-token
echo $GITHUB_USERTOKEN | gh auth login --with-token
echo "===== Current repo list ====="
gh repo list openinfradev | grep tks-user-site
gh repo list tks-management
gh repo list ${GITHUB_ID}
echo "===== Create and initialize tks-management/${CONTRACT_ID} site and manifests repositories ====="
gh repo create tks-management/${CONTRACT_ID} --private --confirm
echo "===== Create and initialize ${GITHUB_ID}/${CONTRACT_ID} site and manifests repositories ====="
gh repo create ${GITHUB_ID}/${CONTRACT_ID} --private --confirm
cd ${CONTRACT_ID}
echo -n ${TOKEN} | gh secret set API_TOKEN_GITHUB
# Clone user-site-template which only has tks-cluster-aws app_group, currently
git clone https://$(echo -n $TOKEN)@github.com/openinfradev/tks-user-site-template
git clone https://$(echo -n $GITHUB_USERTOKEN)@github.com/openinfradev/tks-user-site-template
# Use hanu-reference template as default 'template-std'
git clone https://github.com/openinfradev/decapod-site
Expand All @@ -50,17 +54,18 @@ spec:
git add .
git commit -m "new contract: ${CONTRACT_ID}"
git remote add new_contract https://$(echo -n $TOKEN)@github.com/tks-management/${CONTRACT_ID}
git remote add new_contract https://$(echo -n $GITHUB_USERTOKEN)@github.com/${GITHUB_ID}/${CONTRACT_ID}
git push new_contract main:main
cd ..
envFrom:
- secretRef:
name: "github-tks-mgmt-token"
env:
- name: CONTRACT_ID
value: "{{workflow.parameters.contract_id}}"

- name: GITHUB_ID
value: "{{workflow.parameters.github_id}}"
- name: GITHUB_USERTOKEN
value: "{{workflow.parameters.github_usertoken}}"

- name: main
steps:
- - name: createContractRepository
Expand Down
13 changes: 7 additions & 6 deletions github_repo/delete-cluster-repo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ spec:
- /bin/bash
- -ecx
- |
echo $TOKEN | gh auth login --with-token
echo $GITHUB_USERTOKEN | gh auth login --with-token
gh repo delete tks-management/${CLUSTER_ID} --confirm
gh repo delete tks-management/${CLUSTER_ID}-manifests --confirm
envFrom:
- secretRef:
name: "github-tks-mgmt-token"
gh repo delete ${GITHUB_ID}/${CLUSTER_ID} --confirm
gh repo delete ${GITHUB_ID}/${CLUSTER_ID}-manifests --confirm
env:
- name: CLUSTER_ID
value: "{{workflow.parameters.cluster_id}}"
- name: GITHUB_ID
value: "{{workflow.parameters.github_id}}"
- name: GITHUB_USERTOKEN
value: "{{workflow.parameters.github_usertoken}}"

0 comments on commit 1302e56

Please sign in to comment.