From 76248921513dc019e328e0ec710492c6a942fc84 Mon Sep 17 00:00:00 2001 From: Prasanth Ullattil Date: Sat, 23 Jun 2018 10:52:42 +0200 Subject: [PATCH] Clone repo to find if the tag was created on master WIP --- helpers/Dockerfile.ubuntu-git | 2 ++ pseudonym-server/cloudbuild.yaml | 20 ++++++------ pseudonym-server/script/check_repo.sh | 45 +++++++++++++++++++++++++++ pseudonym-server/script/deploy.sh | 41 ++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 helpers/Dockerfile.ubuntu-git create mode 100755 pseudonym-server/script/check_repo.sh create mode 100755 pseudonym-server/script/deploy.sh diff --git a/helpers/Dockerfile.ubuntu-git b/helpers/Dockerfile.ubuntu-git new file mode 100644 index 000000000..10b9a1532 --- /dev/null +++ b/helpers/Dockerfile.ubuntu-git @@ -0,0 +1,2 @@ +FROM ubuntu +RUN apt-get -q update && apt-get install -qqy git diff --git a/pseudonym-server/cloudbuild.yaml b/pseudonym-server/cloudbuild.yaml index 5bc209c47..3d2cbcd56 100644 --- a/pseudonym-server/cloudbuild.yaml +++ b/pseudonym-server/cloudbuild.yaml @@ -1,7 +1,7 @@ steps: # Check if branch is master [using same script as prime] - - name: ubuntu - args: ['bash', 'prime/script/check_repo.sh', 'test-$BRANCH_NAME:$TAG_NAME'] + - name: gcr.io/$PROJECT_ID/ubuntu-git + args: ['bash', 'pseudonym-server/script/check_repo.sh', 'pseudonym-server', '$TAG_NAME', '$BRANCH_NAME'] # Gradle clean and build pseudonym-server & its dependencies only - name: gcr.io/cloud-builders/gradle args: ['clean', 'pseudonym-server:build'] @@ -11,14 +11,14 @@ steps: args: ['build', '--tag=gcr.io/$PROJECT_ID/pseudonym-server:$TAG_NAME', 'pseudonym-server'] timeout: 120s # Deploy new docker image to Google Kubernetes Engine (GKE) - - name: ubuntu - args: ['sed', '-i', 's/PSEUDONYM_VERSION/$TAG_NAME/g', 'pseudonym-server/pseudonym-server.yaml'] - - name: gcr.io/cloud-builders/kubectl - args: ['apply', '-f', 'pseudonym-server/pseudonym-server.yaml'] - env: - - 'CLOUDSDK_COMPUTE_ZONE=europe-west1-b' - - 'CLOUDSDK_CONTAINER_CLUSTER=private-cluster' - timeout: 300s +# - name: ubuntu +# args: ['sed', '-i', 's/PSEUDONYM_VERSION/$TAG_NAME/g', 'pseudonym-server/pseudonym-server.yaml'] +# - name: gcr.io/cloud-builders/kubectl +# args: ['apply', '-f', 'pseudonym-server/pseudonym-server.yaml'] +# env: +# - 'CLOUDSDK_COMPUTE_ZONE=europe-west1-b' +# - 'CLOUDSDK_CONTAINER_CLUSTER=private-cluster' +# timeout: 300s # Upload docker image into Google Container Registry (GCR) images: ['gcr.io/$PROJECT_ID/pseudonym-server:$TAG_NAME'] diff --git a/pseudonym-server/script/check_repo.sh b/pseudonym-server/script/check_repo.sh new file mode 100755 index 000000000..e1492a900 --- /dev/null +++ b/pseudonym-server/script/check_repo.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +set -e + +if [ -z "$1" ] || [ -z "$2" ]; then + (>&2 echo "Usage: check_repo.sh ") + exit 1 +fi + +module=$1 +tag=$2 + +echo "Checking if '$tag' exists in master branch" + +if [ ! -f "$module/script/deploy.sh" ]; then + (>&2 echo "Run this script from project root dir (ostelco-core)") + exit 1 +fi + +CHECK_REPO="$module/script/check_repo.sh" + +if [ ! -f ${CHECK_REPO} ]; then + (>&2 echo "Missing file - $CHECK_REPO") + exit 1 +fi + +command -v git >/dev/null 2>&1 || { echo >&2 "Git not available, Aborting."; exit 1; } + +git clone https://github.com/ostelco/ostelco-core.git +cd ostelco-core +git checkout master + +tag_commit=$(git rev-list -n 1 $tag) +echo $tag_commit + +if git rev-list --first-parent master | grep $tag_commit >/dev/null; then + (>&2 echo "$tag points to a commit reachable via first-parent from master") +else + (>&2 echo "$tag does not point to a commit reachable via first-parent from master") +fi + +cd .. +rm -rf ostelco-core + +exit 1 diff --git a/pseudonym-server/script/deploy.sh b/pseudonym-server/script/deploy.sh new file mode 100755 index 000000000..102db3b50 --- /dev/null +++ b/pseudonym-server/script/deploy.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +set -e +module="" +if [ -z "$1" ]; then + echo "module is blank" + exit 1 +else + module=$1 +fi +tag="" +if [ -z "$2" ]; then + echo "tag is blank" + exit 1 +else + tag=$2 +fi + +if [ ! -f pseudonym-server/script/deploy.sh ]; then + (>&2 echo "Run this script from project root dir (ostelco-core)") + exit 1 +fi + +CHECK_REPO="pseudonym-server/script/check_repo.sh" + +if [ ! -f ${CHECK_REPO} ]; then + (>&2 echo "Missing file - $CHECK_REPO") + exit 1 +fi + +PROJECT_ID="$(gcloud config get-value project -q)" +BRANCH_NAME=$(git branch | grep \* | cut -d ' ' -f2) + +echo PROJECT_ID=${PROJECT_ID} +echo BRANCH_NAME=${BRANCH_NAME} + +echo "Deploying pseudonym-server to GKE" + +gcloud container builds submit \ + --config pseudonym-server/cloudbuild.yaml \ + --substitutions TAG_NAME=${tag},BRANCH_NAME=${BRANCH_NAME} .