Skip to content

XLPI/test-book

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Using

If you can create fully your own

Terminology

Instruction of prepare/customization

--OS - debian:jessie --install docker in your linux --add repo in /etc/apt/source.list deb [arch=amd64] https://download.docker.com/linux/debian/ wheezy stable --create account in hub.docker.com (my is "xlpi") -- create account in aws.amazon.com

-- git clone

cd projectPath/ //you can see build.sbt and etc

docker login // enter your login, password

Let's go -- Create your own name of your project,as a example "unicorn-books" (my is "test-book")

nano projectPath/build.sbt // set name to unicorn-books it is relation with sbt assembly generated name of *.jar name:= "unicorn-books"

-- (Check working your app in local machine

sbt run)

--

sbt assembly // for zip your project in single *.jar //name relation with build.sbt/ name:= "unicorn-books" // it command will generate *.jar with your project name - projectPath/target/scala-2.10/unicorn-books-assembly-1.0.jar

-- use Dockerfile or create your own. It is step by step as a bash command to create your image with your project -- change name of assembly *.jar file for your own (generated by sbt assembly command) ...

Service

ADD target/scala-2.10/unicorn-books-assembly-1.0.jar /bs.jar ...

CMD ["/run.sh"] // command to start your prj in Docker container

EXPOSE 8080 // PORT in which your app working

--create Docker container of your entire project with command from Docker file. Name of container must be in format [YourDockerLogin]/[NameOfYourApp] as a example you have hub.docker.com user login: user2017

docker build -t user2017/unicorn-books

.... Successfully built xxxxxxx // xxxxxx - second name of your Docker image

--check that Docker container work in local //-p 8888:8080 [NAME_IMAGE]// HOST_MACHINE_PORT:YOUR_DOCKER_APP_PORT

docker run -p 8888:8080 user2017/unicorn-books

--check working your app in REST browser plugin, or using curl --first do PUT to add data in your app, port is - 8888

curl -H 'Content-Type: application/json' -X PUT -d '{"_id": 1, "title": "My First Book", "author": "John Doe", "description": "Not a very good book"}' http://localhost:8888/api/v1/books

--answer { "_id": 1, "title": "My First Book", "author": "John Doe", "description": "Not a very good book" }

curl -H 'Content-Type: application/json' -X PUT -d '{"_id": 2, "title": "My Second Book", "author": "John Doe", "description": "Not a bad as the first book"}' http://localhost:8888/api/v1/books

--answer { "_id": 2, "title": "My Second Book", "author": "John Doe", "description": "Not a bad as the first book" }

curl -H 'Content-Type: application/json' -X PUT -d '{"_id": 3, "title": "My Third Book", "author": "John Doe", "description": "Failed writers club"}' http://localhost:8888/api/v1/books

--answer { "_id": 3, "title": "My Third Book", "author": "John Doe", "description": "Failed writers club" }

--check that service will return valid data

curl -H 'Content-Type: application/json' http://localhost:8888/api/v1/books

--answer (realized without filed description) [{ "_id": 1, "title": "My First Book", "author": "John Doe" }, { "_id": 2, "title": "My Second Book", "author": "John Doe" }, { "_id": 3, "title": "My Third Book", "author": "John Doe" }]

--we can delete some book by _id

curl -H 'Content-Type: application/json' -X DELETE http://localhost:8888/api/v1/books/_id/2

--chek it

curl -H 'Content-Type: application/json' http://localhost:8888/api/v1/books

--answer [{ "_id": 1, "title": "My First Book", "author": "John Doe" }, { "_id": 3, "title": "My Third Book", "author": "John Doe" }]

-- get book by _id

curl -H 'Content-Type: application/json' http://localhost:8888/api/v1/books/_id/1

--answer { "_id": 3, "title": "My Third Book", "author": "John Doe", "description": "Failed writers club" }

-- all working

docker ps -a // see running container CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4153672bd404 xlpi/test-book "/run.sh" 40 seconds ago Up 38 seconds 8080/tcp relaxed_torvalds

-- stop container by it uniq NAMES

docker stop relaxed_torvalds

docker ps -a // for ckeck that containers stoped

docker ps // to se all container with you was worked

-- let's push our Docker to hub.docker.com

docker push user2017/unicorn-books

-- 151f9c908a36: Pushed 071c50af3343: Pushing [==================================================>] 39.2 MB c4bf8f28961d: Pushed c7a21476b025: Pushing [=======> ] 91.62 MB/622.2 MB 8d4d1ab5ff74: Mounted from user2017/unicorn-books

-- latest: digest: sha256:441e030b08defc3a169151b11c3f8c6ee8ba498146585d2762410ff4224bfe90 size: 1368 -- check your container is in hub.docker.com by name user2017/unicorn-books

-- AWS Deploy -- create Dockerrun.aws.json file in projectPath/ and set name of your Docker container from hub.docker.com and PORT if you need //Dockerrun.aws.json { "AWSEBDockerrunVersion": "1", "Image": { "Name": "user2017/unicorn-books", "Update": "true" }, "Ports": [ { "ContainerPort": "8080" } ], "Logging": "/var/log/nginx" }

-- login in console.aws.amazon.com --got to services/ElasticBeanstalk --press "Create new Application" --set App name: unicorn-books Description: ........

--in path "Environments" press Create new environments --choose 0 Web environments <===== 0 Worker environment --press "Select" --chose 0 Platform = --select Docker

--Application code 0 Sample 0 Existing 0 Upload your code <=== --choose projectPath/Dockerrun.aws.json --press "Upload" --press "Crate environment --wait few minutes --get generated URL , as example http://sample-env.zxrtxyr8t2.eu-central-1.elasticbeanstalk.com/

--check YOUR SERVICE ONLINE !!! --as local , but diffenrent URL

--first do PUT to add data in your app, port is - 8888

curl -H 'Content-Type: application/json' -X PUT -d '{"_id": 1, "title": "My First Book", "author": "John Doe", "description": "Not a very good book"}' http://sample-env.zxrtxyr8t2.eu-central-1.elasticbeanstalk.com/api/v1/books

--answer { "_id": 1, "title": "My First Book", "author": "John Doe", "description": "Not a very good book" }

curl -H 'Content-Type: application/json' -X PUT -d '{"_id": 2, "title": "My Second Book", "author": "John Doe", "description": "Not a bad as the first book"}' http://sample-env.zxrtxyr8t2.eu-central-1.elasticbeanstalk.com/api/v1/books

--answer { "_id": 2, "title": "My Second Book", "author": "John Doe", "description": "Not a bad as the first book" }

curl -H 'Content-Type: application/json' -X PUT -d '{"_id": 3, "title": "My Third Book", "author": "John Doe", "description": "Failed writers club"}' hhttp://sample-env.zxrtxyr8t2.eu-central-1.elasticbeanstalk.com/api/v1/books

--answer { "_id": 3, "title": "My Third Book", "author": "John Doe", "description": "Failed writers club" }

--check that service will return valid data

curl -H 'Content-Type: application/json' http://sample-env.zxrtxyr8t2.eu-central-1.elasticbeanstalk.com/api/v1/books

--answer (realized without filed description) [{ "_id": 1, "title": "My First Book", "author": "John Doe" }, { "_id": 2, "title": "My Second Book", "author": "John Doe" }, { "_id": 3, "title": "My Third Book", "author": "John Doe" }]

--we can delete some book by _id

curl -H 'Content-Type: application/json' -X DELETE http://sample-env.zxrtxyr8t2.eu-central-1.elasticbeanstalk.com/api/v1/books/_id/2

--chek it

curl -H 'Content-Type: application/json' http://sample-env.zxrtxyr8t2.eu-central-1.elasticbeanstalk.com/api/v1/books

--answer [{ "_id": 1, "title": "My First Book", "author": "John Doe" }, { "_id": 3, "title": "My Third Book", "author": "John Doe" }]

-- get book by _id

curl -H 'Content-Type: application/json' http://sample-env.zxrtxyr8t2.eu-central-1.elasticbeanstalk.com/api/v1/books/_id/1

--answer { "_id": 3, "title": "My Third Book", "author": "John Doe", "description": "Failed writers club" }

Articles

This repository is used for following articles:

** [Полное практическое руководство по Docker: с нуля до кластера на AWS]https://habrahabr.ru/post/310460/#aws) -RUS ** [Разработка микросервисов с использованием Scala, Spray, MongoDB, Docker и Ansible - RUS]https://habrahabr.ru/post/250043/ -RUS
** [Microservices Development with Scala, Spray, MongoDB, Docker and Ansible - ORIGIN]https://technologyconversations.com/2015/01/26/microservices-development-with-scala-spray-mongodb-docker-and-ansible/ - origin

Docker

image: xlpi/book-service

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published