Skip to content

Commit

Permalink
Clone repo to find if the tag was created on master
Browse files Browse the repository at this point in the history
WIP
  • Loading branch information
prasanthu committed Jun 23, 2018
1 parent 3e6d0f3 commit 7624892
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 10 deletions.
2 changes: 2 additions & 0 deletions helpers/Dockerfile.ubuntu-git
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM ubuntu
RUN apt-get -q update && apt-get install -qqy git
20 changes: 10 additions & 10 deletions pseudonym-server/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -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']
Expand All @@ -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']
45 changes: 45 additions & 0 deletions pseudonym-server/script/check_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

set -e

if [ -z "$1" ] || [ -z "$2" ]; then
(>&2 echo "Usage: check_repo.sh <module name> <git tag>")
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
41 changes: 41 additions & 0 deletions pseudonym-server/script/deploy.sh
Original file line number Diff line number Diff line change
@@ -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} .

0 comments on commit 7624892

Please sign in to comment.