-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3eb14c4
Showing
48 changed files
with
11,858 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright 2017 Istio Authors | ||
# | ||
# 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. | ||
|
||
set -o errexit | ||
|
||
if [ "$#" -ne 2 ]; then | ||
echo "Incorrect parameters" | ||
echo "Usage: build-services.sh <version> <prefix>" | ||
exit 1 | ||
fi | ||
|
||
VERSION=$1 | ||
PREFIX=$2 | ||
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | ||
|
||
pushd "$SCRIPTDIR/productpage" | ||
docker build --pull -t "${PREFIX}/examples-bookinfo-productpage-v1:${VERSION}" -t "${PREFIX}/examples-bookinfo-productpage-v1:latest" . | ||
#flooding | ||
docker build --pull -t "${PREFIX}/examples-bookinfo-productpage-v-flooding:${VERSION}" -t "${PREFIX}/examples-bookinfo-productpage-v-flooding:latest" --build-arg flood_factor=100 . | ||
popd | ||
|
||
pushd "$SCRIPTDIR/details" | ||
#plain build -- no calling external book service to fetch topics | ||
docker build --pull -t "${PREFIX}/examples-bookinfo-details-v1:${VERSION}" -t "${PREFIX}/examples-bookinfo-details-v1:latest" --build-arg service_version=v1 . | ||
#with calling external book service to fetch topic for the book | ||
docker build --pull -t "${PREFIX}/examples-bookinfo-details-v2:${VERSION}" -t "${PREFIX}/examples-bookinfo-details-v2:latest" --build-arg service_version=v2 \ | ||
--build-arg enable_external_book_service=true . | ||
popd | ||
|
||
pushd "$SCRIPTDIR/reviews" | ||
#java build the app. | ||
docker run --rm -u root -v "$(pwd)":/home/gradle/project -w /home/gradle/project gradle:4.8.1 gradle clean build | ||
pushd reviews-wlpcfg | ||
#plain build -- no ratings | ||
docker build --pull -t "${PREFIX}/examples-bookinfo-reviews-v1:${VERSION}" -t "${PREFIX}/examples-bookinfo-reviews-v1:latest" --build-arg service_version=v1 . | ||
#with ratings black stars | ||
docker build --pull -t "${PREFIX}/examples-bookinfo-reviews-v2:${VERSION}" -t "${PREFIX}/examples-bookinfo-reviews-v2:latest" --build-arg service_version=v2 \ | ||
--build-arg enable_ratings=true . | ||
#with ratings red stars | ||
docker build --pull -t "${PREFIX}/examples-bookinfo-reviews-v3:${VERSION}" -t "${PREFIX}/examples-bookinfo-reviews-v3:latest" --build-arg service_version=v3 \ | ||
--build-arg enable_ratings=true --build-arg star_color=red . | ||
popd | ||
popd | ||
|
||
pushd "$SCRIPTDIR/ratings" | ||
docker build --pull -t "${PREFIX}/examples-bookinfo-ratings-v1:${VERSION}" -t "${PREFIX}/examples-bookinfo-ratings-v1:latest" --build-arg service_version=v1 . | ||
docker build --pull -t "${PREFIX}/examples-bookinfo-ratings-v2:${VERSION}" -t "${PREFIX}/examples-bookinfo-ratings-v2:latest" --build-arg service_version=v2 . | ||
docker build --pull -t "${PREFIX}/examples-bookinfo-ratings-v-faulty:${VERSION}" -t "${PREFIX}/examples-bookinfo-ratings-v-faulty:latest" --build-arg service_version=v-faulty . | ||
docker build --pull -t "${PREFIX}/examples-bookinfo-ratings-v-delayed:${VERSION}" -t "${PREFIX}/examples-bookinfo-ratings-v-delayed:latest" --build-arg service_version=v-delayed . | ||
docker build --pull -t "${PREFIX}/examples-bookinfo-ratings-v-unavailable:${VERSION}" -t "${PREFIX}/examples-bookinfo-ratings-v-unavailable:latest" --build-arg service_version=v-unavailable . | ||
docker build --pull -t "${PREFIX}/examples-bookinfo-ratings-v-unhealthy:${VERSION}" -t "${PREFIX}/examples-bookinfo-ratings-v-unhealthy:latest" --build-arg service_version=v-unhealthy . | ||
popd | ||
|
||
pushd "$SCRIPTDIR/mysql" | ||
docker build --pull -t "${PREFIX}/examples-bookinfo-mysqldb:${VERSION}" -t "${PREFIX}/examples-bookinfo-mysqldb:latest" . | ||
popd | ||
|
||
pushd "$SCRIPTDIR/mongodb" | ||
docker build --pull -t "${PREFIX}/examples-bookinfo-mongodb:${VERSION}" -t "${PREFIX}/examples-bookinfo-mongodb:latest" . | ||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2017 Istio Authors | ||
# | ||
# 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. | ||
|
||
FROM ruby:2.7-rc-slim | ||
|
||
COPY details.rb /opt/microservices/ | ||
|
||
ARG service_version | ||
ENV SERVICE_VERSION ${service_version:-v1} | ||
ARG enable_external_book_service | ||
ENV ENABLE_EXTERNAL_BOOK_SERVICE ${enable_external_book_service:-false} | ||
|
||
EXPOSE 9080 | ||
WORKDIR /opt/microservices | ||
|
||
CMD ["ruby", "details.rb", "9080"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
#!/usr/bin/ruby | ||
# | ||
# Copyright 2017 Istio Authors | ||
# | ||
# 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. | ||
|
||
require 'webrick' | ||
require 'json' | ||
require 'net/http' | ||
|
||
if ARGV.length < 1 then | ||
puts "usage: #{$PROGRAM_NAME} port" | ||
exit(-1) | ||
end | ||
|
||
port = Integer(ARGV[0]) | ||
|
||
server = WEBrick::HTTPServer.new :BindAddress => '*', :Port => port | ||
|
||
trap 'INT' do server.shutdown end | ||
|
||
server.mount_proc '/health' do |req, res| | ||
res.status = 200 | ||
res.body = {'status' => 'Details is healthy'}.to_json | ||
res['Content-Type'] = 'application/json' | ||
end | ||
|
||
server.mount_proc '/details' do |req, res| | ||
pathParts = req.path.split('/') | ||
headers = get_forward_headers(req) | ||
|
||
begin | ||
begin | ||
id = Integer(pathParts[-1]) | ||
rescue | ||
raise 'please provide numeric product id' | ||
end | ||
details = get_book_details(id, headers) | ||
res.body = details.to_json | ||
res['Content-Type'] = 'application/json' | ||
rescue => error | ||
res.body = {'error' => error}.to_json | ||
res['Content-Type'] = 'application/json' | ||
res.status = 400 | ||
end | ||
end | ||
|
||
# TODO: provide details on different books. | ||
def get_book_details(id, headers) | ||
if ENV['ENABLE_EXTERNAL_BOOK_SERVICE'] === 'true' then | ||
# the ISBN of one of Comedy of Errors on the Amazon | ||
# that has Shakespeare as the single author | ||
isbn = '0486424618' | ||
return fetch_details_from_external_service(isbn, id, headers) | ||
end | ||
|
||
return { | ||
'id' => id, | ||
'author': 'William Shakespeare', | ||
'year': 1595, | ||
'type' => 'paperback', | ||
'pages' => 200, | ||
'publisher' => 'PublisherA', | ||
'language' => 'English', | ||
'ISBN-10' => '1234567890', | ||
'ISBN-13' => '123-1234567890' | ||
} | ||
end | ||
|
||
def fetch_details_from_external_service(isbn, id, headers) | ||
uri = URI.parse('https://www.googleapis.com/books/v1/volumes?q=isbn:' + isbn) | ||
http = Net::HTTP.new(uri.host, ENV['DO_NOT_ENCRYPT'] === 'true' ? 80:443) | ||
http.read_timeout = 5 # seconds | ||
|
||
# DO_NOT_ENCRYPT is used to configure the details service to use either | ||
# HTTP (true) or HTTPS (false, default) when calling the external service to | ||
# retrieve the book information. | ||
# | ||
# Unless this environment variable is set to true, the app will use TLS (HTTPS) | ||
# to access external services. | ||
unless ENV['DO_NOT_ENCRYPT'] === 'true' then | ||
http.use_ssl = true | ||
end | ||
|
||
request = Net::HTTP::Get.new(uri.request_uri) | ||
headers.each { |header, value| request[header] = value } | ||
|
||
response = http.request(request) | ||
|
||
json = JSON.parse(response.body) | ||
book = json['items'][0]['volumeInfo'] | ||
|
||
language = book['language'] === 'en'? 'English' : 'unknown' | ||
type = book['printType'] === 'BOOK'? 'paperback' : 'unknown' | ||
isbn10 = get_isbn(book, 'ISBN_10') | ||
isbn13 = get_isbn(book, 'ISBN_13') | ||
|
||
return { | ||
'id' => id, | ||
'author': book['authors'][0], | ||
'year': book['publishedDate'], | ||
'type' => type, | ||
'pages' => book['pageCount'], | ||
'publisher' => book['publisher'], | ||
'language' => language, | ||
'ISBN-10' => isbn10, | ||
'ISBN-13' => isbn13 | ||
} | ||
|
||
end | ||
|
||
def get_isbn(book, isbn_type) | ||
isbn_dentifiers = book['industryIdentifiers'].select do |identifier| | ||
identifier['type'] === isbn_type | ||
end | ||
|
||
return isbn_dentifiers[0]['identifier'] | ||
end | ||
|
||
def get_forward_headers(request) | ||
headers = {} | ||
incoming_headers = [ 'x-request-id', | ||
'x-b3-traceid', | ||
'x-b3-spanid', | ||
'x-b3-parentspanid', | ||
'x-b3-sampled', | ||
'x-b3-flags', | ||
'x-ot-span-context', | ||
'x-datadog-trace-id', | ||
'x-datadog-parent-id', | ||
'x-datadog-sampled' | ||
] | ||
|
||
request.each do |header, value| | ||
if incoming_headers.include? header then | ||
headers[header] = value | ||
end | ||
end | ||
|
||
return headers | ||
end | ||
|
||
server.start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2017 Istio Authors | ||
# | ||
# 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. | ||
|
||
FROM mongo:4.0.12-xenial | ||
WORKDIR /app/data/ | ||
COPY ratings_data.json /app/data/ | ||
COPY script.sh /docker-entrypoint-initdb.d/ | ||
RUN chmod +x /docker-entrypoint-initdb.d/script.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{rating: 5} | ||
{rating: 4} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/sh | ||
|
||
# Copyright Istio Authors | ||
# | ||
# 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. | ||
|
||
set -e | ||
mongoimport --host localhost --db test --collection ratings --drop --file /app/data/ratings_data.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2017 Istio Authors | ||
# | ||
# 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. | ||
|
||
FROM mysql:8.0.17 | ||
# MYSQL_ROOT_PASSWORD must be supplied as an env var | ||
|
||
COPY ./mysqldb-init.sql /docker-entrypoint-initdb.d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Initialize a mysql db with a 'test' db and be able test productpage with it. | ||
# mysql -h 127.0.0.1 -ppassword < mysqldb-init.sql | ||
|
||
CREATE DATABASE test; | ||
USE test; | ||
|
||
CREATE TABLE `ratings` ( | ||
`ReviewID` INT NOT NULL, | ||
`Rating` INT, | ||
PRIMARY KEY (`ReviewID`) | ||
); | ||
INSERT INTO ratings (ReviewID, Rating) VALUES (1, 5); | ||
INSERT INTO ratings (ReviewID, Rating) VALUES (2, 4); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2017 Istio Authors | ||
# | ||
# 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. | ||
|
||
FROM python:3.7.4-slim | ||
|
||
COPY requirements.txt ./ | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
COPY test-requirements.txt ./ | ||
RUN pip install --no-cache-dir -r test-requirements.txt | ||
|
||
COPY productpage.py /opt/microservices/ | ||
COPY tests/unit/* /opt/microservices/ | ||
COPY templates /opt/microservices/templates | ||
COPY static /opt/microservices/static | ||
COPY requirements.txt /opt/microservices/ | ||
|
||
ARG flood_factor | ||
ENV FLOOD_FACTOR ${flood_factor:-0} | ||
|
||
EXPOSE 9080 | ||
WORKDIR /opt/microservices | ||
RUN python -m unittest discover | ||
|
||
USER 1 | ||
|
||
CMD ["python", "productpage.py", "9080"] |
Oops, something went wrong.