Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: merge v2-sql branch into main #122

Merged
merged 8 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
156 changes: 156 additions & 0 deletions .github/cloudbuild/pos-check-for-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

###########################################################
# This is a GCP CloudBuild Trigger config file. The trigger
# is for when a PR is open from a branch named release-x.
# x can be major, minor, or patch.
###########################################################

steps:
###########################################################
# Gating step to ensure we run it only once
###########################################################
- id: 'gate-ci'
name: 'python'
entrypoint: bash
args:
- -c
- |
touch /workspace/release.done
COMMIT_MSG=$(git log -1 --oneline --format=%s | sed 's/^.*: //')
if [[ $$COMMIT_MSG == 'update version before release' ]] || [[ $$COMMIT_MSG == 'bump version to next snapshot' ]]; then
echo "Commit message [$$COMMIT_MSG] indicates release version already being updated. Skip steps."
echo "RELEASE_COMPLETE" > /workspace/release.done
fi
# indicates that the step need not wait for any other step
waitFor: [ '-' ]

###########################################################
# Version bump on release PR
###########################################################
- id: 'bump-version'
name: 'python'
entrypoint: bash
args:
- -c
- |
STATUS=$(cat /workspace/release.done)
if [[ $$STATUS == 'RELEASE_COMPLETE' ]]; then
exit 0
fi

pip install -r .github/releases/requirements.txt
echo "PR openned on branch [$_HEAD_BRANCH] for pr-$_PR_NUMBER"
if [[ $_HEAD_BRANCH == 'release-minor' ]]; then
echo "Updating versions for a minor release"
python3 .github/releases/releaser.py -t minor

elif [[ $_HEAD_BRANCH == 'release-patch' ]]; then
echo "Updating versions for a patch release"
python3 .github/releases/releaser.py -t patch

elif [[ $_HEAD_BRANCH == 'release-major' ]]; then
echo "Updating versions for a major release"
python3 .github/releases/releaser.py -t major

else
echo "Nothing to do since it's not a 'release' PR"
echo "RELEASE_COMPLETE" > /workspace/release.done
fi

VERSION=$(python3 .github/releases/releaser.py -p true)
echo "$$VERSION" > release-version.txt
# indicates that the step need not wait for any other step
waitFor: [ 'gate-ci' ]

###########################################################
# Push the version changes to the repo
###########################################################
- id: 'push-changes-to-repo'
name: 'gcr.io/cloud-builders/git'
secretEnv: [ 'GITHUB_TOKEN', 'GITHUB_EMAIL' ]
entrypoint: bash
args:
- -c
- |
STATUS=$(cat /workspace/release.done)
if [[ $$STATUS == 'RELEASE_COMPLETE' ]]; then
exit 0
fi

# we do this so that the deploy triggers can know the PR number
echo "$_PR_NUMBER" > release-pr.number

git config user.email "$$GITHUB_EMAIL"
git config user.name "Anthos DPE"

# as per: https://stackoverflow.com/a/67886960/3396045
git remote set-branches --add origin $_HEAD_BRANCH
git fetch 'origin'
git checkout --track origin/$_HEAD_BRANCH

git add -A
git commit -m "release: update version before release"
git push -u https://$$GITHUB_TOKEN@github.com/GoogleCloudPlatform/point-of-sale.git $_HEAD_BRANCH
waitFor: [ 'bump-version' ]

###########################################################
# Comment about the release status on the release PR
###########################################################
- id: 'comment-release-status-to-github'
name: 'us-docker.pkg.dev/point-of-sale-ci/third-party-images/github-cli:mar-22'
secretEnv: [ 'GITHUB_TOKEN' ]
entrypoint: bash
args:
- -c
- |
STATUS=$(cat /workspace/release.done)
if [[ $$STATUS == 'RELEASE_COMPLETE' ]]; then
exit 0
fi

COMMIT_MSG=$(git log -1 --oneline --format=%s | sed 's/^.*: //')
if [[ $$COMMIT_MSG != 'update version before release' ]]; then
echo "Commit message [$$COMMIT_MSG] is not a release commit. Skipping step."
exit 0
fi

RELEASE_TYPE='patch'
if [[ $_HEAD_BRANCH == 'release-minor' ]]; then
RELEASE_TYPE='minor'
elif [[ $_HEAD_BRANCH == 'release-major' ]]; then
RELEASE_TYPE='major'
fi

LAST_COMMIT=$(cat .git/refs/heads/$_HEAD_BRANCH)
cat <<EOF > /workspace/gh-comment.txt -
:zap: Release Status :zap: </br>
- **Version updated**: Version in the `pom.xml/package.json` has been updated to the next **$$RELEASE_TYPE** release version.
- **Publish Artifacts:** Check the most recent commit ($$LAST_COMMIT) for correctness and run the ["pos-publish-release-artifacts"](https://console.cloud.google.com/cloud-build/triggers;region=global?project=point-of-sale-ci) trigger against this branch **[$BRANCH_NAME]** to upload the artifacts _(Jars and Images)_ to Artifact registry.
EOF
gh pr comment $_PR_NUMBER --repo $_HEAD_REPO_URL --body-file /workspace/gh-comment.txt
# waitFor: commented out, so this step waits for all previous steps

availableSecrets:
inline:
- kmsKeyName: 'projects/$PROJECT_ID/locations/global/keyRings/$_GHTOKEN_KEYRING_NAME/cryptoKeys/$_GHTOKEN_KEY_NAME'
envMap:
GITHUB_TOKEN: 'CiQAuVI6Z93rj1B1R4yer3G1VzEmW7aHtjATP2jOtyJjkW5qOR8SUQBHWet7zXRDJQTBSvFZuXXsOBIxtvf0VDM610Tjgb5XJY8hbIuBxhsMfDy3+/p2ojVnYmE+Mg9NDg5FGZhlJlB/+PBMCumkbMovTXD582u17A=='
- kmsKeyName: 'projects/$PROJECT_ID/locations/global/keyRings/$_GHEMAIL_KEYRING_NAME/cryptoKeys/$_GHEMAIL_KEY_NAME'
envMap:
GITHUB_EMAIL: 'CiQA/ThyQ4p/sDUR2fsc4Q2GgF/PntA048keplEhVQTrmgESLfcSOACXDXFpPP/ASB9nwBao91OK4677dEaGsJQjVKkStDpHtY1ZtF7qefjxq1qK93BSezLllJX/rHbY'
logsBucket: 'gs://pos-cloudbuild-logs'
options:
logging: GCS_ONLY
45 changes: 45 additions & 0 deletions .github/cloudbuild/pos-deploy-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

###########################################################
# This is a GCP CloudBuild Trigger config file. The trigger
# is to be used to build and publish the latest release
# artifacts to repostiories (container-image and maven).
# The trigger associated to this cloudbuild confiuration
# needs to be manually RUN pointing to the release-branch
###########################################################

steps:
###########################################################
# Deploy the latest release manifests to the main cluster
###########################################################
- id: 'deploy-to-k8s-main'
name: 'gcr.io/k8s-skaffold/skaffold:v1.36.0'
entrypoint: bash
args:
- -c
- |
gcloud container clusters get-credentials --zone $_MAIN_CLUSTER_ZONE $_MAIN_CLUSTER
kubectl create namespace $_MAIN_NS-db
kubectl create namespace $_MAIN_NS-inmemory
kubectl apply -f /workspace/namespace.yaml

skaffold run -p release -f=skaffold.yaml --namespace=$_MAIN_NS-db
skaffold run -p release,inmemory -f=skaffold.yaml --namespace=$_MAIN_NS-inmemory
# waitFor: commented out, so this step waits for all previous steps

timeout: 1800s
logsBucket: 'gs://pos-cloudbuild-logs'
options:
logging: GCS_ONLY
30 changes: 22 additions & 8 deletions .github/cloudbuild/pos-pr-open-to-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ steps:
###########################################################
- id: 'npm-install'
name: 'node:16.14.0'
dir: 'point-of-sale-app/ui'
dir: 'src/ui'
entrypoint: 'npm'
args: [ 'install' ]
# indicates that the step need not wait for any other step
Expand All @@ -39,10 +39,17 @@ steps:
- -c
- |
cat <<EOF > /workspace/namespace.yaml -
# namespace to deploy the mysql db based deployment
apiVersion: v1
kind: Namespace
metadata:
name: pr-$_PR_NUMBER
name: pr-$_PR_NUMBER-db
---
# namespace to deploy the inmemory h2 db based deployment
apiVersion: v1
kind: Namespace
metadata:
name: pr-$_PR_NUMBER-inmemory
EOF
# indicates that the step need not wait for any other step
waitFor: [ '-' ]
Expand Down Expand Up @@ -79,7 +86,8 @@ steps:
gcloud container clusters get-credentials --zone $_DEV_CLUSTER_ZONE $_DEV_CLUSTER

./mvnw install
skaffold run -p dev -f=skaffold.yaml --default-repo=us-docker.pkg.dev/$PROJECT_ID/$_POS_IMAGE_REPO --namespace=pr-$_PR_NUMBER --tag=pr-$_PR_NUMBER
skaffold run -p dev -f=skaffold.yaml --default-repo=us-docker.pkg.dev/$PROJECT_ID/$_POS_IMAGE_REPO --namespace=pr-$_PR_NUMBER-db --tag=pr-$_PR_NUMBER-db
skaffold run -p dev,inmemory -f=skaffold.yaml --default-repo=us-docker.pkg.dev/$PROJECT_ID/$_POS_IMAGE_REPO --namespace=pr-$_PR_NUMBER-inmemory --tag=pr-$_PR_NUMBER-inmemory

EOF
# indicates that the step need not wait for any other step
Expand All @@ -90,7 +98,6 @@ steps:
###########################################################
- id: 'deploy-to-k8s'
name: 'gcr.io/k8s-skaffold/skaffold:v1.36.0'
dir: 'point-of-sale-app'
args: [
'bash',
'/workspace/deploy.sh',
Expand All @@ -107,8 +114,10 @@ steps:
- -c
- |
gcloud container clusters get-credentials --zone $_DEV_CLUSTER_ZONE $_DEV_CLUSTER
kubectl -n pr-$_PR_NUMBER get service/$_LB_SERVICE -o jsonpath='{.status.loadBalancer.ingress[0].ip}' > /workspace/pr-$_PR_NUMBER.ip
echo "External IP [$(cat /workspace/pr-$_PR_NUMBER.ip)] saved to file /workspace/pr-$_PR_NUMBER.ip"
kubectl -n pr-$_PR_NUMBER-db get service/$_LB_SERVICE -o jsonpath='{.status.loadBalancer.ingress[0].ip}' > /workspace/pr-$_PR_NUMBER-db.ip
kubectl -n pr-$_PR_NUMBER-inmemory get service/$_LB_SERVICE -o jsonpath='{.status.loadBalancer.ingress[0].ip}' > /workspace/pr-$_PR_NUMBER-inmemory.ip
echo "External IP [$(cat /workspace/pr-$_PR_NUMBER-db.ip)] saved to file /workspace/pr-$_PR_NUMBER-db.ip"
echo "External IP [$(cat /workspace/pr-$_PR_NUMBER-inmemory.ip)] saved to file /workspace/pr-$_PR_NUMBER-inmemory.ip"

waitFor: [ 'deploy-to-k8s' ]

Expand All @@ -122,15 +131,20 @@ steps:
args:
- -c
- |
gh pr comment $_PR_NUMBER --repo $_HEAD_REPO_URL --body "Access the Point-of-Sale at: [$(cat /workspace/pr-$_PR_NUMBER.ip)](http://$(cat /workspace/pr-$_PR_NUMBER.ip))"
cat <<EOF > /workspace/gh-comment.txt -
:zap: Two deployments have been created for the Point-of-Sale application. You may access and test them at: :zap: </br>
- **MySQL DB** backed deployment: [**$(cat /workspace/pr-$_PR_NUMBER-db.ip)**](http://$(cat /workspace/pr-$_PR_NUMBER-db.ip))
- **Embedded H2** DB backed deployment: [**$(cat /workspace/pr-$_PR_NUMBER-inmemory.ip)**](http://$(cat /workspace/pr-$_PR_NUMBER-inmemory.ip))
EOF
gh pr comment $_PR_NUMBER --repo $_HEAD_REPO_URL --body-file /workspace/gh-comment.txt
waitFor: [ 'get-external-loadbalancer-ip' ]

availableSecrets:
inline:
- kmsKeyName: 'projects/$PROJECT_ID/locations/global/keyRings/$_GHTOKEN_KEYRING_NAME/cryptoKeys/$_GHTOKEN_KEY_NAME'
envMap:
GITHUB_TOKEN: 'CiQAuVI6Z93rj1B1R4yer3G1VzEmW7aHtjATP2jOtyJjkW5qOR8SUQBHWet7zXRDJQTBSvFZuXXsOBIxtvf0VDM610Tjgb5XJY8hbIuBxhsMfDy3+/p2ojVnYmE+Mg9NDg5FGZhlJlB/+PBMCumkbMovTXD582u17A=='
timeout: 900s
timeout: 1800s
logsBucket: 'gs://pos-cloudbuild-logs'
options:
logging: GCS_ONLY
3 changes: 2 additions & 1 deletion .github/cloudbuild/pos-pr-webhook-event.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ steps:
echo "Event [$_PULL_REQUEST_EVENT_TYPE] for pr-$_PULL_REQUEST_ID"
if [ $_PULL_REQUEST_EVENT_TYPE == 'closed' ]; then
gcloud container clusters get-credentials --zone $_DEV_CLUSTER_ZONE $_DEV_CLUSTER
kubectl delete namespace pr-$_PULL_REQUEST_ID || true
kubectl delete namespace pr-$_PULL_REQUEST_ID-db
kubectl delete namespace pr-$_PULL_REQUEST_ID-db || true
else
echo "Nothing to do since it's not a 'closed' event"
fi
Expand Down