quinta-feira, 9 de junho de 2016

Docker Hub, save and share your docker images

The Docker Hub is a cloud-based registration service for the construction of container applications or services.

It provides a centralized resource for image container discovery, distribution and change management, user and team collaboration and workflow automation throughout the development pipeline.

Docker hub provides the following features:

     Image Repository -Find, manage and push and pull of community images, official and private image libraries.

     Automated Build - automatically create new images when you make changes to a code that is on GitHub or bit bucket.

     Webhooks - A feature of Automated builds, Webhooks let you trigger actions after a successful push’s too a repository.

     Organization - Create working groups to manage user access to repositories of images.

Public Repository:



Sending image to own repository:



Here I got an existed image.



I logged in my docker hub account.


I put the my tag to send to my account


Now I have two images, the original and my own version.


In the end I did push to repository.


If I check my docker hub account, is possible seeing the image that I sent.


Webhooks

The webhook is an HTTP callback triggered by a specific event.
You can use a webhook to notify people, services and other applications after a new image is sent to your repository.

To start adding webhooks, scroll to the desired repository in Hub and click "Webhooks" under the "Settings" box.

The webhook is called only after a successful push is made.


Calls webhook are HTTP POST requests with a JSON payload similar to the example shown below.

 

After create my webhook I will have this image below:

 


Just for test this webhook I used this site: http://requestb.in



This site will provide one URL to put on WebHook URL and this site provide another URL to check Request received like this:


Automated build

You can build your images automatically from a compilation context stored in a repository.

A building context is a Docker File and any files in the specific location.

For an automated build the building context is a repository where it sends a Docker File.

Use of automated builds requires that you have an account on Docker Hub and hosted repository provider  GitHub or BitBucket.


If you already have on your Github or BitBucket account, you must have chosen the type of public and private connection.



 



After each commit that happen on git repository mapped is possible see this table with status about each image build with code committed. 

  


And is possible combine Automated Build with WebHooks and the result for this could be a deploy in someplace.




These functionalities for Webhooks and Automated Build are limited in private mode, for each user is available 1 Private Repo & Parallel Build, and this pipeline not happen immediately for free account.

My Slides

References:







sexta-feira, 3 de junho de 2016

Reactive Extensions for Java(RxJava) - Overview of some concepts behind the RxJava

RxJava is the Java implementation of ReactiveX and is a library for compose asynchronous and event-based programs using observable sequence for the JVM

RxJava implements of the Reactor pattern, and the observer pattern that could be consider combination between Interator Pattern and Functional Programing, in other words are lot of functions to create, combine and filters streams.

According defined on official documentation: 
"It extends the observer pattern to support sequences of data and/or events and adds operators that allow you to compose sequences together declaratively while abstracting away concerns about things like low-level threading, synchronization, thread-safety, concurrent data structures, and non-blocking I/O." 



The main target of Rx is whole platform JVM not just a language. Until this moment, has supports to Java, Groovy, Scala, JavaScript, Ruby.

One of the ideas of Rx is provide a DSL for creating flows out of asynchronous sources using collections of operators for filtering, selecting transforming and combining that flow in a lazy manner. Encapsulates data sequences in Observable. Provide composable operations on them.

These flows are called Observables, collections of events with push semantics, opposed to pull used in iterator.

Non-blocking is not faster, non blocking could be consider about utilizing threads better, if thread utilization is not a issue, it will perform about the same.
 
About the Observable and Observer we can consider:
  • Observable -> source of data stream (SENDER)
  • Observer -> listener for emitted values (RECEIVER)
  • The Observer Subscribes (listens) to the Observable.
  • Observers react to whatever item or sequence of items the Observable emits.
  • Many observers can subscribe to the same observable.




Observable and Observer Pattern differences:
  • Observer:
    • Allows for concurrent operations
    • The observer does not need to block while waiting for the observable to emit values.
    • Observer waits to receive values when the observable is ready to emit them.
    • Based on push rather than pull.
  • Observable:
    • Composable and easily chained together or combined.
    • Flexible and can be used to emit network results, Sequences, infinite streams.
    • Free from callback hell.
    • Easy to transform one asynchronous stream into another.



Sample Code:


Observable.just("Hello, world!")
    .map(s -> s.hashCode())
    .map(i -> Integer.toString(i))
    .subscribe(s -> System.out.println(s));
Comparison between Iterable and Observable Architecture:
 Iterable Architecture - How it works:
  • Call a method
  • Wait for result
  • Store the return value from that method in a variable.
  • Use that variable and its new value to do something useful.

 Observable Architecture - How it works:
  • Define an Observer that specifics what to do with each emitted value.
  • Call a method that returns an Observable.
  • Subscribe the Observer to the Observable.
  • Tell the Observable that it has a subscriber waiting to receive values when they're available.

The subscribe method connects an Observer to an Observable, the subscribe no need to block the thread and the values will come to your Observer when they are ready.
What should we think about when we use Rx:
  • Treat all data as immutable
  • Since we treat data as a stream, we can return one or more results for each subscription
  • We can transform and combine data on any thread and subscribe to update for related values/collections

My Sandbox with RxJava

Available RX Functions

Reactive Manifesto

Erik Meijer: Rx in 15 Minutes - Rx is Here!!!!!

101 Rx Samples

References: