Skip to content

Instantly share code, notes, and snippets.

@shinofara
Last active July 11, 2020 02:51
Show Gist options
  • Save shinofara/6e5c7eee2debdefa15f8482b1188c70a to your computer and use it in GitHub Desktop.
Save shinofara/6e5c7eee2debdefa15f8482b1188c70a to your computer and use it in GitHub Desktop.
Application Repository
steps:
- name: gcr.io/cloud-builders/gcloud
id: 'setup_ssh'
entrypoint: 'bash'
args:
- '-c'
- |
<ここに秘密鍵をSecret Managerなどから取ってくる処理>
git config --global url."git@github.com:".insteadOf "https://github.com/"
volumes:
- name: 'ssh'
path: /root/.ssh
- name: gcr.io/cloud-builders/docker
id: build
entrypoint: 'bash'
args:
- '-c'
- |
docker build -t gcr.io/hoge-dev/hoge:latest \
-t gcr.io/hoge-dev/hoge:${BRANCH_NAME} \
-t gcr.io/hoge-dev/hoge:${COMMIT_SHA} .
docker gcr.io/hoge-dev/hoge
- name: 'gcr.io/cloud-builders/git'
id: checkout_k8s_repo
entrypoint: /bin/sh
args:
- '-c'
- |
git clone git@github.com:hoge-org/k8s.git /work/k8s
cd /work/k8s
set +e
git checkout candidate_hoge > /dev/null 2> /dev/null
if [ $? -eq 1 ]; then
git checkout -b candidate_hoge
fi
set -e
volumes:
- name: 'ssh'
path: /root/.ssh
- name: 'k8s'
path: /work/k8s
- name: 'gcr.io/cloud-builders/git'
id: push_git
entrypoint: /bin/sh
args:
- '-c'
- |
commit_message="$(TZ=TZ=Asia/Tokyo git log --date=format:'%Y/%m/%d %H:%M:%S' --format="%ad %B" -n 1 $COMMIT_SHA | head -1) by hoge"
commit_url="https://github.com/hoge-org/hoge/commit/$COMMIT_SHA"
commit_detail="$(git log --format=%B -n 1)"
cd /work/k8s/manifests/hoge/base
sed "s/COMMIT_SHA/${COMMIT_SHA}/g" kustomization.tpl.yml > kustomization.yml
cd /work/k8s
git config user.email $(gcloud auth list --filter=status:ACTIVE --format='value(account)')
git add -A ./
git commit -m "$commit_message" -m "$commit_url" -m "$commit_detail"
git push origin candidate_hoge
volumes:
- name: 'ssh'
path: /root/.ssh
- name: 'k8s'
path: /work/k8s
- name: 'python'
id: Update Description
entrypoint: bash
env:
- '_GITHUB_TOKEN=$_GITHUB_TOKEN'
args:
- '-c'
- |
pip3 install requests
prid=$(git log --format="%B" $COMMIT_SHA | head -1 | sed 's/.*#\([0-9]*\).*/\1/')
cmd="python3 /work/k8s/bin/update_pr_desc.py hoge $prid"
$cmd
volumes:
- name: 'k8s'
path: /work/k8s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment