istio.io/istio@v0.0.0-20240520182934-d79c90f27776/samples/bookinfo/README.md (about) 1 # Bookinfo Sample 2 3 See <https://istio.io/docs/examples/bookinfo/>. 4 5 **Note**: We need the owner of the PR to perform the appropriate testing with built/pushed images to their own docker repository before we would build/push images to the official Istio repository. 6 7 ## General Setup 8 9 ```bash 10 # This defines the docker hub to use when running integration tests and building docker images 11 # eg: HUB="docker.io/istio", HUB="gcr.io/istio-testing" 12 export HUB="docker.io/$USER" 13 14 # This defines the docker tag to use when running integration tests and 15 # building docker images to be your user id. You may also set this variable 16 # this to any other legitimate docker tag. 17 export TAG=<version number> 18 ``` 19 20 ## Compile code 21 22 ```bash 23 cd samples/bookinfo 24 BOOKINFO_TAG=$TAG BOOKINFO_HUB=$HUB src/build-services.sh 25 ``` 26 27 For example: 28 29 ```bash 30 $ BOOKINFO_TAG=test1.0 BOOKINFO_HUB=docker.io/user1 src/build-services.sh 31 +++ dirname ./build-services.sh 32 ++ cd . 33 ++ pwd 34 + SCRIPTDIR=/work/samples/bookinfo/src 35 + cd /work/samples/bookinfo/src/../../.. 36 + h=docker.io/user1 37 + t=test1.0 38 + [[ docker.io/user1 == \i\s\t\i\o ]] 39 + [[ docker.io/user1 == \d\o\c\k\e\r\.\i\o\/\i\s\t\i\o ]] 40 + plat=linux/amd64 41 + [[ '' == \t\r\u\e ]] 42 + env TAG=test1.0 HUB=docker.io/user1 docker buildx bake -f samples/bookinfo/src/docker-bake.hcl --set '*.platform=linux/amd64' 43 [+] Building 1.9s (123/133) 44 => [examples-bookinfo-ratings-v-faulty internal] load build definition from Dockerfile 0.0s 45 => => transferring dockerfile: 1.05kB 0.0s 46 ... 47 => CACHED [examples-bookinfo-ratings-v-faulty 4/6] COPY ratings.js /opt/microservices/ 0.0s 48 => CACHED [examples-bookinfo-ratings-v-faulty 5/6] WORKDIR /opt/microservices 0.0s 49 => CACHED [examples-bookinfo-ratings-v-faulty 6/6] RUN npm install 0.0s 50 WARNING: No output specified for examples-bookinfo-mysqldb, examples-bookinfo-ratings-v-faulty, examples-bookinfo-reviews-v2, examples-bookinfo-reviews-v3, examples-bookinfo-productpage-v-flooding, examples-bookinfo-ratings-v-unhealthy, examples-bookinfo-ratings-v-unavailable, examples-bookinfo-ratings-v1, examples-bookinfo-details-v2, examples-bookinfo-reviews-v1, examples-bookinfo-productpage-v1, examples-bookinfo-ratings-v-delayed, examples-bookinfo-details-v1, examples-bookinfo-ratings-v2, examples-bookinfo-mongodb target(s) with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load 51 ``` 52 53 The code for the bookinfo sample is now compiled and built. The bookinfo versions are different from Istio versions since the sample should work with any version of Istio. 54 55 ## Build docker images 56 57 ```bash 58 cd samples/bookinfo 59 BOOKINFO_TAG=$TAG BOOKINFO_HUB=$HUB src/build-services.sh --load 60 ``` 61 62 For example: 63 64 ```bash 65 $ BOOKINFO_TAG=test1.0 BOOKINFO_HUB=docker.io/user1 src/build-services.sh --load 66 +++ dirname ./build-services.sh 67 ++ cd . 68 ++ pwd 69 + SCRIPTDIR=/work/samples/bookinfo/src 70 + cd /work/samples/bookinfo/src/../../.. 71 + h=docker.io/user1 72 + t=test1.0 73 + [[ docker.io/user1 == \i\s\t\i\o ]] 74 + [[ docker.io/user1 == \d\o\c\k\e\r\.\i\o\/\i\s\t\i\o ]] 75 + plat=linux/amd64 76 + [[ '' == \t\r\u\e ]] 77 ... 78 => [examples-bookinfo-productpage-v-flooding] exporting to docker image format 10.4s 79 => => exporting layers 0.0s 80 => => exporting manifest sha256:5046deeca78c67f0977fa627b3c2a98ba380b09f4dabf5620040fbf723785f6a 0.0s 81 => => exporting config sha256:5a632c874e649f6492d5a6592a3da2b9ee3fca8d6f55bfbc0249b865eb8579be 0.0s 82 => => sending tarball 10.4s 83 => importing to docker 0.1s 84 => importing to docker 0.0s 85 => importing to docker 0.0s 86 => importing to docker 0.0s 87 => importing to docker 0.0s 88 => importing to docker 0.0s 89 => importing to docker 0.0s 90 => importing to docker 0.0s 91 => importing to docker 0.0s 92 => importing to docker 0.0s 93 => importing to docker 0.0s 94 => importing to docker 0.1s 95 => importing to docker 0.3s 96 => importing to docker 0.2s 97 => importing to docker 0.1s 98 + [[ true == \t\r\u\e ]] 99 + find ./samples/bookinfo/platform -name '*bookinfo*.yaml' -exec sed -i.bak 's#image:.*\(\/examples-bookinfo-.*\):.*#image: docker.io\/user1\1:test1.0#g' '{}' +/ay 100 ``` 101 102 Docker images are now created. 103 104 ## Push docker images to docker hub 105 106 After the local build is successful, you will need to push the images to Docker hub. You may need to login to Docker before you run the command using `docker login`. 107 108 ```bash 109 cd samples/bookinfo 110 BOOKINFO_LATEST=true BOOKINFO_TAG=$TAG BOOKINFO_HUB=$HUB src/build-services.sh --push 111 ``` 112 113 For example: 114 115 ```bash 116 $ BOOKINFO_TAG=test1.0 BOOKINFO_HUB=docker.io/user1 src/build-services.sh --push 117 +++ dirname ./build-services.sh 118 ++ cd . 119 ++ pwd 120 + SCRIPTDIR=/work/samples/bookinfo/src 121 + cd /work/samples/bookinfo/src/../../.. 122 + h=docker.io/user1 123 + t=test1.0 124 + [[ docker.io/user1 == \i\s\t\i\o ]] 125 + [[ docker.io/user1 == \d\o\c\k\e\r\.\i\o\/\i\s\t\i\o ]] 126 + plat=linux/amd64 127 + [[ '' == \t\r\u\e ]] 128 + env TAG=test1.0 HUB=docker.io/user1 docker buildx bake -f samples/bookinfo/src/docker-bake.hcl --set '*.platform=linux/amd64' --push 129 ... 130 => => pushing layers 11.1s 131 => => pushing manifest for docker.io/user1/examples-bookinfo-reviews-v3:test1.0@sha256:4c9e2dfcabdfc55fba9037967ee412690b23d676481713eb88985926e229c8db 0.7s 132 => [auth] user1/examples-bookinfo-ratings-v2:pull,push token for registry-1.docker.io 0.0s 133 => [auth] user1/examples-bookinfo-ratings-v-delayed:pull,push token for registry-1.docker.io 0.0s 134 => [auth] user1/examples-bookinfo-ratings-v-unavailable:pull,push token for registry-1.docker.io 0.0s 135 => [auth] user1/examples-bookinfo-ratings-v-unhealthy:pull,push token for registry-1.docker.io 0.0s 136 => [auth] user1/examples-bookinfo-ratings-v-faulty:pull,push token for registry-1.docker.io 0.0s 137 => [auth] user1/examples-bookinfo-mongodb:pull,push token for registry-1.docker.io 0.0s 138 => [auth] user1/examples-bookinfo-details-v1:pull,push token for registry-1.docker.io 0.0s 139 => [auth] user1/examples-bookinfo-productpage-v1:pull,push token for registry-1.docker.io 0.0s 140 => [auth] user1/examples-bookinfo-details-v2:pull,push token for registry-1.docker.io 0.0s 141 => [auth] user1/examples-bookinfo-productpage-v-flooding:pull,push token for registry-1.docker.io 0.0s 142 => [auth] user1/examples-bookinfo-reviews-v1:pull,push token for registry-1.docker.io 0.0s 143 => [auth] user1/examples-bookinfo-reviews-v3:pull,push token for registry-1.docker.io 0.0s 144 => [auth] user1/examples-bookinfo-reviews-v2:pull,push token for registry-1.docker.io 0.0s 145 + [[ true == \t\r\u\e ]] 146 + find ./samples/bookinfo/platform -name '*bookinfo*.yaml' -exec sed -i.bak 's#image:.*\(\/examples-bookinfo-.*\):.*#image: docker.io\/user1\1:test1.0#g' '{}' + 147 ``` 148 149 ## Update YAML files to point to the newly created images 150 151 You need to update the YAML file with the latest tag that you used during the build, eg: `$HUB:$TAG`. 152 153 Run the following script to update the YAML files in one step. 154 155 ```bash 156 cd samples/bookinfo 157 export BOOKINFO_UPDATE=true 158 BOOKINFO_TAG=test1.0 BOOKINFO_HUB=user1 src/build-services.sh 159 ``` 160 161 For example: 162 163 ```bash 164 $ export BOOKINFO_UPDATE=true 165 $ BOOKINFO_TAG=test1.0 BOOKINFO_HUB=user1 src/build-services.sh 166 +++ dirname samples/bookinfo/src/build-services.sh 167 ++ cd samples/bookinfo/src 168 ++ pwd 169 + SCRIPTDIR=/work/samples/bookinfo/src 170 + cd /work/samples/bookinfo/src/../../.. 171 + h=user1 172 + t=test1.0 173 + [[ user1 == \i\s\t\i\o ]] 174 + [[ user1 == \d\o\c\k\e\r\.\i\o\/\i\s\t\i\o ]] 175 + plat=linux/amd64 176 + [[ '' == \t\r\u\e ]] 177 + env TAG=test1.0 HUB=docker.io/user1 docker buildx bake -f samples/bookinfo/src/docker-bake.hcl --set '*.platform=linux/amd64' 178 ... 179 => CACHED [examples-bookinfo-ratings-v-faulty 4/6] COPY ratings.js /opt/microservices/ 0.0s 180 => CACHED [examples-bookinfo-ratings-v-faulty 5/6] WORKDIR /opt/microservices 0.0s 181 => CACHED [examples-bookinfo-ratings-v-faulty 6/6] RUN npm install 0.0s 182 WARNING: No output specified for examples-bookinfo-mysqldb, examples-bookinfo-ratings-v-faulty, examples-bookinfo-reviews-v2, examples-bookinfo-reviews-v3, examples-bookinfo-productpage-v-flooding, examples-bookinfo-ratings-v-unhealthy, examples-bookinfo-ratings-v-unavailable, examples-bookinfo-ratings-v1, examples-bookinfo-details-v2, examples-bookinfo-reviews-v1, examples-bookinfo-productpage-v1, examples-bookinfo-ratings-v-delayed, examples-bookinfo-details-v1, examples-bookinfo-ratings-v2, examples-bookinfo-mongodb target(s) with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load 183 + [[ true == \t\r\u\e ]] 184 + find ./samples/bookinfo/platform -name '*bookinfo*.yaml' -exec sed -i.bak 's#image:.*\(\/examples-bookinfo-.*\):.*#image: user1\1:test1.0#g' '{}' + 185 ``` 186 187 Verify that expected image eg: `user1/examples-bookinfo-*:test1.0` is updated in `platform/kube/bookinfo*.yaml` files. 188 189 ## Tests 190 191 Test that the bookinfo samples work with the latest image eg: `user1/examples-bookinfo-*:test1.0` that you pushed. 192 193 ```bash 194 $ cd ../../ 195 $ kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml 196 serviceaccount/bookinfo-details created 197 deployment.apps/details-v1 created 198 serviceaccount/bookinfo-ratings created 199 ... 200 ``` 201 202 Wait for all the pods to be in `Running` start. 203 204 ```bash 205 $ kubectl get pods 206 NAME READY STATUS RESTARTS AGE 207 details-v1-7f556f5c6b-485l2 2/2 Running 0 10m 208 productpage-v1-84c8f95c8d-tlml2 2/2 Running 0 10m 209 ratings-v1-66777f856b-2ls78 2/2 Running 0 10m 210 reviews-v1-64c47f4f44-rx642 2/2 Running 0 10m 211 reviews-v2-66b6b95f44-s5nt6 2/2 Running 0 10m 212 reviews-v3-7f69dd7fd4-zjvc8 2/2 Running 0 10m 213 ``` 214 215 Once all the pods are in the `Running` state. Test if the bookinfo works through cli. 216 217 ```bash 218 $ kubectl exec -it "$(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}')" -c ratings -- curl productpage:9080/productpage | grep -o "<title>.*</title>" 219 <title>Simple Bookstore App</title> 220 ``` 221 222 You can also test it by hitting productpage in the browser. 223 224 ```bash 225 http://192.168.39.116:31395/productpage 226 ``` 227 228 You should see the following in the browser. 229 230  231 232 **Note**: If everything works as mentioned above, request a new official set of images be built and pushed from the reviewer, and add another commit to the original PR with the version changes. 233 234 Bookinfo is tested by istio.io integration tests. You can find them under [tests](https://github.com/istio/istio.io/tree/master/tests) in the [istio/istio.io](https://github.com/istio/istio.io) repository.