Coder Social home page Coder Social logo

danielbryantuk / oreilly-docker-java-shopping Goto Github PK

View Code? Open in Web Editor NEW
157.0 8.0 315.0 147 KB

Code repository for my O'Reilly "Containerizing Continuous Delivery in Java: Docker Integration for Build Pipelines and Application Architecture" minibook

License: Apache License 2.0

Shell 2.11% Java 77.51% HTML 12.34% Scala 5.06% Gherkin 1.34% Dockerfile 1.65%

oreilly-docker-java-shopping's Introduction

oreilly-docker-java-shopping

Dec 2021: Please note this repo contains frameworks, libraries, and config that are now deprecated (and may have security issues etc). Consider the examples fit for educational use only! Updating all this would require a substantial re-write, and it would probably warrent another version of the book being published

This repo contains code samples from my O'Reilly minibook "Containerizing Continuous Delivery in Java: Docker Integration for Build Pipelines and Application Architecture".

This README is intended to provide high-level guidance of the project, and detailed instructions can be found in the accompanying book.

Project Structure

  • ci-vagrant
  • Installation files that build a Jenkins instance that is ready for experimenting with the examples contained within the book.
  • Currently the installation is undertaken using Vagrant and Oracle's VirtualBox
  • Once Vagrant and VirtualBox are installed locally, the Jenkins box can be built from this directory using the vagrant up command
  • functional-e2e-tests
  • Simple examples of functional end-to-end tests that use JUnit and REST-assured to test the DJShopping application
  • performance-e2e-tests
  • Simple examples of performance/load end-to-end tests that use Gatling with SBT and Scala
  • shopfront
  • The 'shopfront' microservice of the DJShopping example application that provides the primary entry point for the end-user (both Web UI and API-driven)
  • productcatalogue
    • The 'product catalogue' microservice of the DJShopping example application, which provides product details like name and price
  • stockmanager
    • The 'stock manager' microservice of the DJShopping example application, which provides stock information, such as SKU and quantity
  • build_all.sh
    • Convenience shell script for triggering Maven builds of all of the application microservices. This script does not build the associated Docker images, but the minibook contains instructions for doing so, alongside the suggestion that the resulting Docker images are pushed to your own DockerHub account
  • build_all_and_publish_dockerhub.yml
    • Convenience build and publish shell script for triggering Maven builds of all of the application microservices, building an associated Docker image, and (if successful) a push of the image to DockerHub. If you wish to use this script you will have to create a DockerHub account and substitute the existing account details ('danielbryantuk') with your own.
  • docker-compose.yml
  • Docker Compose file that starts all of the DJShopping application microservice containers. Note that if you push your own version of the Docker images to your DockerHub account you will have to change the image names details within this file to run these (i.e. remove the 'danielbryantuk' account name)
  • Run the file via the command docker-compose up
  • docker-compose-build.yml
    • Docker Compose file that contains the build configuration of the DJShopping application microservices.
    • Build the Docker images via the command docker-compose -f docker-compose-build.yml build
    • Build and run the Docker images via the command docker-compose -f docker-compose-build.yml up --build

Example Jenkins Pipelines

Once the Jenkins instance has been built and configured as specified in the accompanying minibook, and the DJShopping build items have been configured and run, it will be possible to create Jenkins Pipeline examples for running end-to-end tests. The examples contained within the book are included here for reference:

Single Service Initialisation Test

node {
    stage ('Successful startup check') {
        docker.image('danielbryantuk/djshopfront').withRun('-p 8010:8010') {
            timeout(time: 30, unit: 'SECONDS') {
                waitUntil {
                    def r = sh script: 'curl -s http://localhost:8010/health | grep "UP"', returnStatus: true
                    return (r == 0);
                }
            }
        }
    }
}

End-to-end Initialisation Test

node {
    stage ('build') {
        git url: 'https://github.com/danielbryantuk/oreilly-docker-java-shopping.git'
        // conduct other build tasks
    }

    stage ('end-to-end tests') {
        timeout(time: 60, unit: 'SECONDS') {
            try {
                sh 'docker-compose up -d'
                waitUntil { // application is up
                    def r = sh script: 'curl -s http://localhost:8010/health | grep "UP"', returnStatus: true
                    return (r == 0);
                }

                // conduct main test here
                sh 'curl http://localhost:8010 | grep "Docker Java"'

            } finally {
                sh 'docker-compose stop'
            }
        }
    }

    stage ('deploy') {
        // deploy the containers/application here
    }
}

End-to-end Functional Tests

node {
    stage ('build') {
        git url: 'https://github.com/danielbryantuk/oreilly-docker-java-shopping.git'
        // conduct other build tasks
    }

    stage ('end-to-end tests') {
        timeout(time: 60, unit: 'SECONDS') {
            try {
                sh 'docker-compose up -d'
                waitUntil { // application is up
                    def r = sh script: 'curl -s http://localhost:8010/health | grep "UP"', returnStatus: true
                    return (r == 0);
                }

                // conduct main test here
                sh 'cd functional-e2e-tests && mvn clean verify'

            } finally {
                sh 'docker-compose stop'
            }
        }
    }

    stage ('deploy') {
        // deploy the containers/application here
    }
}

oreilly-docker-java-shopping's People

Contributors

codep0tato avatar danielbryantuk avatar demotascha avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oreilly-docker-java-shopping's Issues

Fix pom.xml for stock manager

Error recieved : Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
at org.hibernate.boot.spi.XmlMappingBinderAccess.(XmlMappingBinderAccess.java:43)
at org.hibernate.boot.MetadataSources.(MetadataSources.java:87)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.(EntityManagerFactoryBuilderImpl.java:179)

I am running Java 10. Essentially if you are running java 9 and above you must add the javax.xml.bind.api (spring boot is nice that you only have to add the api) as a dependency in your pom.xml I have fixed this and have this in a branch ready for a pull request.

Unable to reach shopfront application - character encoding

After working through this post (and the book) I am unable to access the shopfront application at http://localhost/shopfront. I get the following error in the browser console:

The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature.

Any idea what might be causing this?

Fatal error when building shopfront

I'm trying to build the shopfront microservice using the mvn clean install as explained on the minibook (p.13) and I have a fatal error

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building shopfront
[INFO]    task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting /home/daniel/work/CM_Arkea/oreilly-docker-java-shopping/shopfront/target
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An invalid artifact was detected.

This artifact might be in your project's POM, or it might have been included transitively during the resolution process. Here is the information we do have for this artifact:

    o GroupID:     org.springframework
    o ArtifactID:  spring-core
    o Version:     <<< MISSING >>>
    o Type:        jar

[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.artifact.InvalidArtifactRTException: For artifact {org.springframework:spring-core:null:jar}: The version cannot be empty.
        at org.apache.maven.artifact.DefaultArtifact.validateIdentity(DefaultArtifact.java:147)
        at org.apache.maven.artifact.DefaultArtifact.<init>(DefaultArtifact.java:122)
        at org.apache.maven.artifact.factory.DefaultArtifactFactory.createArtifact(DefaultArtifactFactory.java:158)
        at org.apache.maven.artifact.factory.DefaultArtifactFactory.createDependencyArtifact(DefaultArtifactFactory.java:58)
        at org.apache.maven.project.DefaultMavenProjectBuilder.createManagedVersionMap(DefaultMavenProjectBuilder.java:454)
        at org.apache.maven.project.DefaultMavenProjectBuilder.buildInternal(DefaultMavenProjectBuilder.java:910)
        at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromRepository(DefaultMavenProjectBuilder.java:255)
        at org.apache.maven.project.artifact.MavenMetadataSource.retrieveRelocatedProject(MavenMetadataSource.java:163)
        at org.apache.maven.project.artifact.MavenMetadataSource.retrieveRelocatedArtifact(MavenMetadataSource.java:94)
        at org.apache.maven.artifact.resolver.DefaultArtifactCollector.recurse(DefaultArtifactCollector.java:387)
        at org.apache.maven.artifact.resolver.DefaultArtifactCollector.collect(DefaultArtifactCollector.java:74)
        at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveTransitively(DefaultArtifactResolver.java:316)
        at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveTransitively(DefaultArtifactResolver.java:304)
        at org.apache.maven.plugin.DefaultPluginManager.resolveTransitiveDependencies(DefaultPluginManager.java:1499)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:442)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Thu Feb 09 14:37:15 CET 2017
[INFO] Final Memory: 22M/303M
[INFO] ------------------------------------------------------------------------

For information:

java -version
java version "1.7.0_121"
OpenJDK Runtime Environment (IcedTea 2.6.8) (7u121-2.6.8-2~deb8u1)
OpenJDK 64-Bit Server VM (build 24.121-b00, mixed mode)
mvn -version
Apache Maven 2.2.1 (rdebian-17)
Java version: 1.7.0_121
Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre
Default locale: fr_FR, platform encoding: UTF-8
OS name: "linux" version: "3.16.0-4-amd64" arch: "amd64" Family: "unix"

What did I missed?

Kubernetes config needs updating

I've just updated the Kubernetes YAML config in the kubernetes directory to run on any modern K8s cluster, but the other directories contain YAML that needs updating, too.

Where is the minibook?

This seems like a very silly question... but where can I get a copy of the aforementioned minibook?

A few google searches yielded no results.
screen shot 2016-12-27 at 7 24 09 am

If it's available somewhere on the internet, it would be great to include a link to that from this project. Thanks! :)

stockmanager pod always restart

[root@centos ~]# kubectl get pods
NAME                     READY   STATUS             RESTARTS   AGE
productcatalogue-m6j8l   1/1     Running            0          131m
shopfront-lczpd          1/1     Running            0          141m
stockmanager-b2c6s       0/1     CrashLoopBackOff   39         131m

The container log:


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.3.RELEASE)

2020-09-21 12:41:33.643  INFO 1 --- [           main] u.c.d.d.s.StockManagerApplication        : Starting StockManagerApplication v0.0.1-SNAPSHOT on stockmanager-7w6b4 with PID 1 (/app.jar started by root in /)
2020-09-21 12:41:33.645  INFO 1 --- [           main] u.c.d.d.s.StockManagerApplication        : No active profile set, falling back to default profiles: default
2020-09-21 12:41:34.384  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2020-09-21 12:41:34.429  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 39ms. Found 1 repository interfaces.
2020-09-21 12:41:34.761  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$b70ad3c] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-09-21 12:41:35.075  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8030 (http)
2020-09-21 12:41:35.116  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-09-21 12:41:35.116  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.16]
2020-09-21 12:41:35.125  INFO 1 --- [           main] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
2020-09-21 12:41:35.227  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-09-21 12:41:35.227  INFO 1 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1552 ms
2020-09-21 12:41:35.590  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2020-09-21 12:41:35.711  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2020-09-21 12:41:35.756  INFO 1 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
	name: default
	...]
2020-09-21 12:41:35.819  INFO 1 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.3.7.Final}
2020-09-21 12:41:35.820  INFO 1 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2020-09-21 12:41:35.966  INFO 1 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2020-09-21 12:41:36.171  INFO 1 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2020-09-21 12:41:36.675  INFO 1 --- [           main] o.h.t.schema.internal.SchemaCreatorImpl  : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@492691d7'
2020-09-21 12:41:36.677  INFO 1 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-09-21 12:41:36.853  INFO 1 --- [           main] u.c.d.d.s.config.DataGenerator           : Generating synthetic data for demonstration purposes...
2020-09-21 12:41:36.919  INFO 1 --- [           main] u.c.d.d.s.config.DataGenerator           : ... data generation complete
2020-09-21 12:41:37.155  INFO 1 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-09-21 12:41:37.267  WARN 1 --- [           main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-09-21 12:41:37.469  INFO 1 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'
2020-09-21 12:41:37.516  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8030 (http) with context path ''
2020-09-21 12:41:37.517  INFO 1 --- [           main] u.c.d.d.s.StockManagerApplication        : Started StockManagerApplication in 4.164 seconds (JVM running for 4.499)
2020-09-21 12:42:12.676  INFO 1 --- [nio-8030-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-09-21 12:42:12.676  INFO 1 --- [nio-8030-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2020-09-21 12:42:12.683  INFO 1 --- [nio-8030-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 7 ms

2020-09-21 12:42:32.650  INFO 1 --- [       Thread-5] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2020-09-21 12:42:32.651  INFO 1 --- [       Thread-5] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2020-09-21 12:42:32.651  INFO 1 --- [       Thread-5] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'
2020-09-21 12:42:32.656  INFO 1 --- [       Thread-5] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2020-09-21 12:42:32.658  INFO 1 --- [       Thread-5] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.

No exception. I don't know why this spring app shutdown.

Azure Kubernetes cluster

I could see all the services running up on the Azure Kubernetes cluster and deployment was successful. But the shopfront website not loading on public IP address.

image

UnknownHostException

Hi,
First of all, thanks for cool tutorial - but I've some problems setting it all up:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Mon Oct 30 17:41:23 UTC 2017
There was an unexpected error (type=Internal Server Error, status=500).
I/O error on GET request for "http://productcatalogue:8020/products": productcatalogue; nested exception is java.net.UnknownHostException: productcatalogue

I'm getting it after executing:
minikube service shopfront

What's the problem? All containers run correctly. Am I missing something?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.