Skip to content

Commit

Permalink
Fixed release issues(#272)
Browse files Browse the repository at this point in the history
Updated package.json with the version to 9.3.0
Updated circle ci config.yml
  • Loading branch information
lazolalucas authored Mar 10, 2020
1 parent 85614de commit e49387c
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 214 deletions.
205 changes: 59 additions & 146 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# CircleCI v2.1 Config
version: 2.1

##
# orbs
#
# Orbs used in this pipeline
##
orbs:
anchore: anchore/[email protected]
deploy-kube: mojaloop/[email protected]

##
# defaults
Expand All @@ -27,107 +34,12 @@ defaults_awsCliDependencies: &defaults_awsCliDependencies |
pip install --upgrade awscli==1.14.5 s3cmd==2.0.1 python-magic
apk -v --purge del py-pip

defaults_build_docker_build: &defaults_build_docker_build
name: Build Docker $CIRCLE_TAG image
command: |
echo "Building Docker image: $CIRCLE_TAG"
docker build -t $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG .
defaults_build_docker_login: &defaults_build_docker_login
name: Login to Docker Hub
command: |
docker login -u $DOCKER_USER -p $DOCKER_PASS
defaults_build_docker_publish: &defaults_build_docker_publish
name: Publish Docker image $CIRCLE_TAG & Latest tag to Docker Hub
command: |
echo "Publishing $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG"
docker push $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG
echo "Publishing $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$RELEASE_TAG"
docker push $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$RELEASE_TAG
defaults_deploy_config_kubernetes_cluster: &defaults_deploy_config_kubernetes_cluster
name: Configure Kubernetes cluster
command: |
echo "Configure Kubernetes cluster ${K8_CLUSTER_NAME}"
kubectl config set-cluster $K8_CLUSTER_NAME --server=$K8_CLUSTER_SERVER --insecure-skip-tls-verify=true
defaults_deploy_config_kubernetes_context: &defaults_deploy_config_kubernetes_context
name: Confi gure Kubernetes context
command: |
echo "Configure Kubernetes context ${K8_CLUSTER_NAME}"
kubectl config set-context $K8_CLUSTER_NAME --cluster=$K8_CLUSTER_NAME --user=$K8_USER_NAME --namespace=$K8_NAMESPACE
defaults_deploy_config_kubernetes_credentials: &defaults_deploy_config_kubernetes_credentials
name: Configure Kubernetes credentails
command: |
echo "Configure Kubernetes credentials ${K8_USER_NAME}"
if [ ! -z "$K8_USER_TOKEN" ];
then
echo "Configure Kubernetes credentials ${K8_USER_NAME} using Token"
kubectl config set-credentials $K8_USER_NAME --token=$K8_USER_TOKEN
else
echo "Configure Kubernetes credentials ${K8_USER_NAME} using Certs"
kubectl config set-credentials $K8_USER_NAME --client-certificate=$CIRCLE_WORKING_DIRECTORY/$AWS_S3_DIR_DEVOPS_DEPLOYMENT_CONFIG_KEYS/$K8_USER_PEM_CERT_FILENAME --client-key=$CIRCLE_WORKING_DIRECTORY/$AWS_S3_DIR_DEVOPS_DEPLOYMENT_CONFIG_KEYS/$K8_USER_PEM_KEY_FILENAME
fi
defaults_deploy_configure_helm: &defaults_deploy_configure_helm
name: Configure Helm
command: |
helm init --client-only
defaults_deploy_install_or_upgrade_helm_chart: &defaults_deploy_install_or_upgrade_helm_chart
name: Install or Upgrade Helm Chart
command: |
echo "Install or Upgrade Chart ${K8_RELEASE_NAME} for Docker Image ${DOCKER_ORG}/${CIRCLE_PROJECT_REPONAME}:${CIRCLE_TAG}"
if [ -z "$(helm list -q | grep -E "^${K8_RELEASE_NAME}$")" ] && [ "$(helm list -q | grep -E "^${K8_RELEASE_NAME}$")" != "Error: Unauthorized" ];
then
echo "Installing ${K8_RELEASE_NAME} new release"
helm install --namespace=$K8_NAMESPACE --name=$K8_RELEASE_NAME --repo=$K8_HELM_REPO --version $K8_HELM_CHART_VERSION $HELM_VALUE_SET_VALUES -f $CIRCLE_WORKING_DIRECTORY/$AWS_S3_DIR_DEVOPS_DEPLOYMENT_CONFIG_HELM/$HELM_VALUE_FILENAME $K8_HELM_CHART_NAME
else
echo "Upgrading ${K8_RELEASE_NAME} release"
helm upgrade $K8_RELEASE_NAME --repo=$K8_HELM_REPO --version $K8_HELM_CHART_VERSION --reuse-values $HELM_VALUE_SET_VALUES -f $CIRCLE_WORKING_DIRECTORY/$AWS_S3_DIR_DEVOPS_DEPLOYMENT_CONFIG_HELM/$HELM_VALUE_FILENAME $K8_HELM_CHART_NAME
fi
defaults_deploy_prequisites: &defaults_deploy_prequisites
name: Copy deployment pre-requisites from S3 bucket
command: |
if [ -z "$K8_USER_TOKEN" ];
then
echo "Copying K8 keys into $AWS_S3_DIR_DEVOPS_DEPLOYMENT_CONFIG_KEYS folder"
mkdir $CIRCLE_WORKING_DIRECTORY/$AWS_S3_DIR_DEVOPS_DEPLOYMENT_CONFIG_KEYS
aws s3 cp $AWS_S3_URI_DEVOPS_DEPLOYMENT_CONFIG/$AWS_S3_DIR_DEVOPS_DEPLOYMENT_CONFIG_KEYS/$K8_USER_PEM_KEY_FILENAME $CIRCLE_WORKING_DIRECTORY/$AWS_S3_DIR_DEVOPS_DEPLOYMENT_CONFIG_KEYS/
aws s3 cp $AWS_S3_URI_DEVOPS_DEPLOYMENT_CONFIG/$AWS_S3_DIR_DEVOPS_DEPLOYMENT_CONFIG_KEYS/$K8_USER_PEM_CERT_FILENAME $CIRCLE_WORKING_DIRECTORY/$AWS_S3_DIR_DEVOPS_DEPLOYMENT_CONFIG_KEYS/
else
echo "Skipping K8 keys into $AWS_S3_DIR_DEVOPS_DEPLOYMENT_CONFIG_KEYS folder"
fi
echo "Copying Helm value file into $AWS_S3_DIR_DEVOPS_DEPLOYMENT_CONFIG_HELM folder for $K8_RELEASE_NAME release"
mkdir $CIRCLE_WORKING_DIRECTORY/$AWS_S3_DIR_DEVOPS_DEPLOYMENT_CONFIG_HELM
aws s3 cp $AWS_S3_URI_DEVOPS_DEPLOYMENT_CONFIG/$AWS_S3_DIR_DEVOPS_DEPLOYMENT_CONFIG_HELM/$HELM_VALUE_FILENAME $CIRCLE_WORKING_DIRECTORY/$AWS_S3_DIR_DEVOPS_DEPLOYMENT_CONFIG_HELM/
defaults_deploy_set_kubernetes_context: &defaults_deploy_set_kubernetes_context
name: Set Kubernetes context
command: |
echo "Configure Kubernetes context ${K8_CLUSTER_NAME}"
kubectl config use-context $K8_CLUSTER_NAME
defaults_license_scanner: &defaults_license_scanner
name: Install and set up license-scanner
command: |
git clone https://github.com/mojaloop/license-scanner /tmp/license-scanner
cd /tmp/license-scanner && make build default-files set-up
defaults_slack_announcement: &defaults_slack_announcement
name: Slack announcement for tag releases
command: |
curl -X POST \
$SLACK_WEBHOOK_ANNOUNCEMENT \
-H 'Content-type: application/json' \
-H 'cache-control: no-cache' \
-d "{\"text\": \"*${CIRCLE_PROJECT_REPONAME}* - Release \`${CIRCLE_TAG}\`: https://github.com/mojaloop/${CIRCLE_PROJECT_REPONAME}/releases/tag/${CIRCLE_TAG}\"}"
##
# Executors
#
Expand All @@ -143,11 +55,6 @@ executors:
machine:
image: ubuntu-1604:201903-01

helm-kube:
working_directory: /home/circleci/project
docker:
- image: hypnoglow/kubernetes-helm

##
# Jobs
#
Expand All @@ -164,6 +71,9 @@ jobs:
- run:
name: Access npm folder as root
command: cd $(npm root -g)/npm
- run:
name: Install interledgerjs/five-bells-ledger-api-tests
command: npm install github:interledgerjs/five-bells-ledger-api-tests
- run:
name: Update NPM install
command: npm install
Expand All @@ -185,12 +95,16 @@ jobs:
- restore_cache:
keys:
- dependency-cache-{{ checksum "package.json" }}
- run:
name: Install tape, tapes and tap-xunit
command: npm install -g tape tapes tap-xunit
- dependency-cache-
- run:
name: Create dir for test results
command: mkdir -p ./test/results
- run:
name: Install tape and tap-xunit
command: npm install -g tape tap-xunit
- run:
name: Install tapes
command: npm install -g tapes
- run:
name: Execute unit tests
command: npm -s run test:xunit > ./test/results/tape.xml
Expand All @@ -213,9 +127,10 @@ jobs:
- restore_cache:
keys:
- dependency-cache-{{ checksum "package.json" }}
- dependency-cache-
- run:
name: Execute code coverage check
command: npm -s run test:coverage-check
command: npm -s run test:coverage
- store_artifacts:
path: coverage
prefix: test
Expand All @@ -227,7 +142,7 @@ jobs:
if [ "${CIRCLE_BRANCH}" == "master" ];
then
echo "Sending lcov.info to SonarQube..."
aws s3 cp coverage/lcov.info $AWS_S3_DIR_SONARQUBE/$CIRCLE_PROJECT_REPONAME/lcov.info
aws s3 cp coverage/lcov.info $AWS_S3_DIR_SONARQUBE/central-settlement/lcov.info
else
echo "Not a release (env CIRCLE_BRANCH != 'master'), skipping sending lcov.info to SonarQube."
fi
Expand All @@ -237,14 +152,13 @@ jobs:
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
key: dependency-cache-{{ checksum "CACHE_VERSION.txt" }}-{{ checksum "package.json" }}
- run:
name: Create dir for test results
command: mkdir -p ./test/results
- run:
name: Execute integration tests
command: npm -s run test:integration
no_output_timeout: 25m
- store_artifacts:
path: ./test/results
prefix: test
Expand All @@ -259,7 +173,9 @@ jobs:
name: Install general dependencies
command: *defaults_Dependencies
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
keys:
- dependency-cache-{{ checksum "package.json" }}
- dependency-cache-
- run:
name: Create dir for test results
command: mkdir -p ./audit/results
Expand All @@ -280,7 +196,9 @@ jobs:
- run:
<<: *defaults_license_scanner
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
keys:
- dependency-cache-{{ checksum "package.json" }}
- dependency-cache-
- run:
name: Prune non-production packages before running license-scanner
command: npm prune --production
Expand All @@ -296,7 +214,10 @@ jobs:
steps:
- checkout
- run:
<<: *defaults_build_docker_build
name: Build Docker $CIRCLE_TAG image
command: |
echo "Building Docker image: $CIRCLE_TAG"
docker build -t $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG .
- run:
name: Save docker image to workspace
command: docker save -o /tmp/docker-image.tar $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG
Expand All @@ -307,7 +228,6 @@ jobs:

license-scan:
executor: default-machine
# <<: *defaults_test_env
steps:
- attach_workspace:
at: /tmp
Expand Down Expand Up @@ -383,43 +303,36 @@ jobs:
name: Load the pre-built docker image from workspace
command: docker load -i /tmp/docker-image.tar
- run:
<<: *defaults_build_docker_login
- run:
name: setup environment vars for release/snapshot
command: ./.circleci/_set_up_deploy_envs.sh
name: Login to Docker Hub
command: docker login -u $DOCKER_USER -p $DOCKER_PASS
- run:
name: Re-tag pre built image
command: |
docker tag $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$RELEASE_TAG
- run:
<<: *defaults_build_docker_publish
name: Publish Docker image $CIRCLE_TAG & Latest tag to Docker Hub
command: |
echo "Publishing $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG"
docker push $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG
echo "Publishing $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$RELEASE_TAG"
docker push $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$RELEASE_TAG
- run:
<<: *defaults_slack_announcement
name: Slack announcement for tag releases
command: |
curl -X POST \
$SLACK_WEBHOOK_ANNOUNCEMENT \
-H 'Content-type: application/json' \
-H 'cache-control: no-cache' \
-d "{\"text\": \"*${CIRCLE_PROJECT_REPONAME}* - Release \`${CIRCLE_TAG}\`: https://github.com/mojaloop/${CIRCLE_PROJECT_REPONAME}/releases/tag/${CIRCLE_TAG}\"}"
deploy:
executor: helm-kube
executor: deploy-kube/helm-kube
steps:
- checkout
- run:
name: Install AWS CLI dependencies
command: *defaults_awsCliDependencies
- run:
name: setup environment vars for release/snapshot
command: ./.circleci/_set_up_deploy_envs.sh
- run:
<<: *defaults_deploy_prequisites
- run:
<<: *defaults_deploy_config_kubernetes_cluster
- run:
<<: *defaults_deploy_config_kubernetes_credentials
- run:
<<: *defaults_deploy_config_kubernetes_context
- run:
<<: *defaults_deploy_set_kubernetes_context
- run:
<<: *defaults_deploy_configure_helm
- run:
<<: *defaults_deploy_install_or_upgrade_helm_chart
- deploy-kube/setup_and_run:
helm_set_values: |
--set central.centralsettlement.image.repository=$DOCKER_ORG/$CIRCLE_PROJECT_REPONAME \
--set central.centralsettlement.image.tag=$CIRCLE_TAG
##
# Workflows
Expand Down Expand Up @@ -461,7 +374,7 @@ workflows:
ignore:
- /feature*/
- /bugfix*/
- vulnerability-check:
- test-integration:
context: org-global
requires:
- setup
Expand All @@ -472,7 +385,7 @@ workflows:
ignore:
- /feature*/
- /bugfix*/
- audit-licenses:
- vulnerability-check:
context: org-global
requires:
- setup
Expand All @@ -483,7 +396,7 @@ workflows:
ignore:
- /feature*/
- /bugfix*/
- test-integration:
- audit-licenses:
context: org-global
requires:
- setup
Expand All @@ -505,7 +418,7 @@ workflows:
- audit-licenses
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*(\-snapshot)?(\-hotfix(\.[0-9]+))?/
only: /v[0-9]+(\.[0-9]+)*(\-snapshot)?/
branches:
ignore:
- /.*/
Expand All @@ -515,7 +428,7 @@ workflows:
- build
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*(\-snapshot)?(\-hotfix(\.[0-9]+))?/
only: /v[0-9]+(\.[0-9]+)*(\-snapshot)?/
branches:
ignore:
- /.*/
Expand All @@ -525,7 +438,7 @@ workflows:
- build
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*(\-snapshot)?(\-hotfix(\.[0-9]+))?/
only: /v[0-9]+(\.[0-9]+)*(\-snapshot)?/
branches:
ignore:
- /.*/
Expand All @@ -536,7 +449,7 @@ workflows:
- image-scan
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*(\-snapshot)?(\-hotfix(\.[0-9]+))?/
only: /v[0-9]+(\.[0-9]+)*(\-snapshot)?/
branches:
ignore:
- /.*/
Expand All @@ -549,4 +462,4 @@ workflows:
only: /v[0-9]+(\.[0-9]+)*(\-snapshot)?/
branches:
ignore:
- /.*/
- /.*/
Loading

0 comments on commit e49387c

Please sign in to comment.