Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
*~
#*
*#
.#*
.classpath
.project
.settings/
.springBeans
target/
_site/
.idea
*.iml
*.swp
.factorypath
*.logtjmeter
.checkstyle
*.log
.DS_Store
/spring-cloud-sleuth-core/nb-configuration.xml
/spring-cloud-sleuth-core/nbactions.xml
build/
.gradle

### Node template
# Logs
logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
/package-lock.json

out/
*.log
nohup.out
Empty file added .gitmodules
Empty file.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
Forked from https://github.com/bradtraversy/bookstore

## Bookstore ##

**Bookstore** is a simple web application which includes and Express RESTful API server and a front end in AngularJS

The video tutorial that goes with this project can be found here
[https://www.youtube.com/watch?v=eB9Fq9I5ocs](http://https://www.youtube.com/watch?v=eB9Fq9I5ocs "https://www.youtube.com/watch?v=eB9Fq9I5ocs")
[https://www.youtube.com/watch?v=eB9Fq9I5ocs](https://www.youtube.com/watch?v=eB9Fq9I5ocs "https://www.youtube.com/watch?v=eB9Fq9I5ocs")

## Usage ##
Just clone or download and run **npm install** and then **node app** to start

##Notes##
The Genres Angular controller is blank on purpose. This is for you to try and come up with after watching the video. It may be added in the future

# SPRING CLOUD CONTRACT #

Just run `npm test` to execute contract tests and publish the jars to artifactory.
Requires Docker and Docker Compose!

Click [here](spring-cloud-contract.adoc) to read an article contains a short reminder of what Contract Testing is, how Spring Cloud Contract implements it, and how Spring Cloud Contract can be used in a polyglot world.
19 changes: 19 additions & 0 deletions contracts/1_shouldAddABook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
description: |
Should add a book
request:
method: POST
url: /api/books
headers:
Content-Type: application/json
body: '{
"title" : "Title",
"genre" : "Genre",
"description" : "Description",
"author" : "Author",
"publisher" : "Publisher",
"pages" : 100,
"image_url" : "https://d213dhlpdb53mu.cloudfront.net/assets/pivotal-square-logo-41418bd391196c3022f3cd9f3959b3f6d7764c47873d858583384e759c7db435.svg",
"buy_url" : "https://pivotal.io"
}'
response:
status: 200
23 changes: 23 additions & 0 deletions contracts/2_shouldReturnListOfBooks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
description: |
Should return info about other endpoints to query
request:
method: GET
url: /api/books
response:
status: 200
headers:
Content-Type: application/json
body: '{
"title" : "Title",
"genre" : "Genre",
"description" : "Description",
"author" : "Author",
"publisher" : "Publisher",
"pages" : 100,
"image_url" : "https://d213dhlpdb53mu.cloudfront.net/assets/pivotal-square-logo-41418bd391196c3022f3cd9f3959b3f6d7764c47873d858583384e759c7db435.svg",
"buy_url" : "https://pivotal.io"
}'
matchers:
headers:
- key: Content-Type
regex: application/json.*
7 changes: 7 additions & 0 deletions docker/Dockerfile-artifactory
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM docker.bintray.io/jfrog/artifactory-oss:5.5.1

MAINTAINER Marcin Grzejszczak <[email protected]>

COPY artifactory.config.import.yml /var/opt/jfrog/artifactory/etc/artifactory.config.import.yml

ENTRYPOINT ["/bin/sh", "-c", "/entrypoint-artifactory.sh"]
72 changes: 72 additions & 0 deletions docker/artifactory.config.import.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
version: 1
## This file is complementary to the JFrog Artifactory startup wizard, and may be used to specify the initial basic
## settings for a new Artifactory installation, namely:
## * License Key(s)
## * Base URL
## * Proxy
## * Default repositories
##
##
## HOW TO USE THIS FILE:
##
## To import these settings when bootstrapping Artifactory, save this file as artifactory.config.import.yml under Artifactory’s /etc folder
## Artifactory will load this file if all of the following conditions are met:
## - no repositories have been created
## - a proxy has not been set up, or you did set up a proxy externally, but did not configure proxy setup through this file
## - the base URL has not been set up, or you did set up the base URL externally, but did not configure the base URL setup through this file
## - Artifactory has not been activated with a license, or Artifactory has been activated with a license, and you did not specify a license in this file
##
## To have any of these parameters automatically configured when you bootstrap an Artifactory instance using this file,
## simply uncomment the relevant sections below, and where required, provide values.

##################################################################################
# General Configurations #
##################################################################################
#GeneralConfiguration:
## License key to import in onboarding
# licenseKey : "Enter your license key"

## Setup the Artifactory base URL
## For more information about the Artifactory base URL, please refer to
## https://www.jfrog.com/confluence/display/RTF/Configuring+Artifactory#ConfiguringArtifactory-GeneralSettings
## Uncomment the line below to set the Artifactory base URL
# baseUrl : "https://mycomp.arti.co"

## Configure proxies for artifactory
## For more information on configuring a proxy in Artifactory, please refer to
## https://www.jfrog.com/confluence/display/RTF/Managing+Proxies
## Uncomment the lines below to setup a proxy
# proxies :
# - key : "proxy1"
# host : "https://proxy.mycomp.io"
# port : 443
# userName : "admin"
# password : "password"
# defaultProxy : true
# - key : "proxy2"
# ...
##################################################################################
# Onboarding Configurations #
##################################################################################
OnboardingConfiguration:
## Uncomment the package types for which you want to create default repositories
repoTypes :
# - bower
# - cocoapods
# - conan
# - debian
# - docker
# - gems
# - gradle
# - ivy
- maven
# - npm
# - nuget
# - opkg
# - composer
# - pypi
# - sbt
# - vagrant
# - rpm
# - gitlfs
11 changes: 11 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "2"
services:
mongo:
image: mongo:jessie
ports: ["27017:27017"]
artifactory:
build:
context: .
dockerfile: Dockerfile-artifactory
ports:
- "8081:8081"
10 changes: 10 additions & 0 deletions json/1_request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"title" : "Title",
"genre" : "Genre",
"description" : "Description",
"author" : "Author",
"publisher" : "Publisher",
"pages" : 100,
"image_url" : "https://d213dhlpdb53mu.cloudfront.net/assets/pivotal-square-logo-41418bd391196c3022f3cd9f3959b3f6d7764c47873d858583384e759c7db435.svg",
"buy_url" : "https://pivotal.io"
}
5 changes: 5 additions & 0 deletions json/1_request.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -e

curl -H "Content-Type:application/json" -X POST --data @1_request.json http://localhost:9876/api/books
5 changes: 5 additions & 0 deletions json/2_request.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -e

curl -X GET http://localhost:9876/api/books
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"description": "Simple bookstore app",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "./run_tests.sh"
},
"dependencies":{
"express":"*",
"body-parser":"*",
"mongoose":"*"
"dependencies": {
"express": "*",
"body-parser": "*",
"mongoose": "*"
},
"author": "Brad Traversy",
"license": "ISC"
Expand Down
19 changes: 19 additions & 0 deletions run_contract_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

SC_CONTRACT_DOCKER_VERSION="${SC_CONTRACT_DOCKER_VERSION:-1.2.3.BUILD-SNAPSHOT}"
APP_IP="$( ./whats_my_ip.sh )"
APP_PORT="${APP_PORT:-3000}"
ARTIFACTORY_PORT="${ARTIFACTORY_PORT:-8081}"
APPLICATION_BASE_URL="http://${APP_IP}:${APP_PORT}"
ARTIFACTORY_URL="http://${APP_IP}:${ARTIFACTORY_PORT}/artifactory/libs-release-local"
CURRENT_DIR="$( pwd )"
PROJECT_NAME="${PROJECT_NAME:-bookstore}"
PROJECT_GROUP="${PROJECT_GROUP:-com.example}"
PROJECT_VERSION="${PROJECT_VERSION:-0.0.1.RELEASE}"

echo "Sc Contract Version [${SC_CONTRACT_DOCKER_VERSION}]"
echo "Application URL [${APPLICATION_BASE_URL}]"
echo "Artifactory URL [${ARTIFACTORY_URL}]"
echo "Project Version [${PROJECT_VERSION}]"

docker run --rm -e "APPLICATION_BASE_URL=${APPLICATION_BASE_URL}" -e "PUBLISH_ARTIFACTS=true" -e "PROJECT_NAME=${PROJECT_NAME}" -e "PROJECT_GROUP=${PROJECT_GROUP}" -e "REPO_WITH_BINARIES_URL=${ARTIFACTORY_URL}" -e "PROJECT_VERSION=${PROJECT_VERSION}" -v "${CURRENT_DIR}/contracts/:/contracts:ro" -v "${CURRENT_DIR}/node_modules/spring-cloud-contract/output:/spring-cloud-contract-output/" springcloud/spring-cloud-contract:"${SC_CONTRACT_DOCKER_VERSION}"
17 changes: 17 additions & 0 deletions run_stub_runner_boot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

SC_CONTRACT_DOCKER_VERSION="${SC_CONTRACT_DOCKER_VERSION:-1.2.3.BUILD-SNAPSHOT}"
APP_IP="$( ./whats_my_ip.sh )"

# Stub coordinates 'groupId:artifactId:version:classifier'
STUB_GROUP="${STUB_GROUP:-com.example}"
STUB_ARTIFACT="${STUB_ARTIFACT:-bookstore}"
STUB_VERSION="${STUB_VERSION:-0.0.1.RELEASE}"
STUB_PORT="9876"

# Spring Cloud Contract Stub Runner properties
STUBRUNNER_PORT="${STUBRUNNER_PORT:-8083}"
STUBRUNNER_IDS="${STUB_GROUP}:${STUB_ARTIFACT}:${STUB_VERSION}:stubs:${STUB_PORT}"
STUBRUNNER_REPOSITORY_ROOT="http://${APP_IP}:8081/artifactory/libs-release-local"

docker run --rm -e "STUBRUNNER_IDS=${STUBRUNNER_IDS}" -e "SERVER_PORT=${STUBRUNNER_PORT}" -e "STUBRUNNER_REPOSITORY_ROOT=${STUBRUNNER_REPOSITORY_ROOT}" -p "${STUBRUNNER_PORT}:${STUBRUNNER_PORT}" -p "${STUB_PORT}:${STUB_PORT}" springcloud/spring-cloud-contract-stub-runner:"${SC_CONTRACT_DOCKER_VERSION}"
15 changes: 15 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Start docker infra
./stop_infra.sh
./setup_infra.sh

# Kill & Run app
pkill -f "node app"
nohup node app &

# Execute contract tests
./run_contract_tests.sh

# Kill app
pkill -f "node app"
6 changes: 6 additions & 0 deletions setup_infra.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

pushd docker
docker-compose build
docker-compose up -d
popd
Loading