% -*- mode: latex; -*- mustache tags:  
\ifx\wholebook\relax\else

	\documentclass[10pt,twoside,english]{root/support/latex/sbabook/sbabook}
  \usepackage{import}
  \subimport{root/support/latex/}{common.tex}

  \hypersetup{pdfinfo = {
    Title = {Deploy TinyBlog},
    Author = {},
    Keywords = {pharo, smalltalk}}}
  \begin{document}
\fi

\chapter{Previous Week Solution}
You can load the full TinyBlog application using the following snippet:

\begin{displaycode}{smalltalk}
Gofer new 
   smalltalkhubUser: 'PharoMooc' project: 'TinyBlog';
   package: 'ConfigurationOfTinyBlog';
   load. 
#ConfigurationOfTinyBlog asClass loadFinalApp
\end{displaycode}

To test it, you should launch the Seaside HTTP server. 
You can now complete or finish \textbf{your} application et commit it in your Smalltalkhub repository. 
\chapter{Deploy in the Cloud}
Now that you have finished to develop your blog web application, we will see how to deploy it on a server in the cloud.

If you want to deploy your application on your own server, we encourage you to read the last chapter of the book  \symbol{34}Enterprise Pharo: a Web Perspective\symbol{34} (\url{http://books.pharo.org}).

In this tutorial, we will describe a simpler solution provided by PharoCloud (\url{http://pharocloud.com}).
\section{PharoCloud Hosting}
PharoCloud is a hosting service dedicated to Pharo web application that offers a free testing plan (ephemeric cloud subscription).

Set-up your PharoCloud account:

\begin{itemize}
\item Create an account on \url{http://pharocloud.com}
\item Activate your account
\item Connect
\item Activate your \symbol{34}Ephemeric Cloud\symbol{34} to obtain an \textbf{API User ID} and an \textbf{API Auth Token}
\item Click on \symbol{34}Open Cloud Client\symbol{34} and log in using the oabove credentials
\item Once connected, you should see a web allowing you to upload an archive file (zip) that should contains two files: a Pharo image and its changes file
\end{itemize}
\section{Preparing Pharo image to Deploy on PharoCloud}
Currently, PharoCloud only supports Pharo 4 images. 

So, download a PharoWeb 4 image.
\url{https://ci.inria.fr/pharo-contribution/job/PharoWeb/PHARO=40,VERSION=stable,VM=vm/lastSuccessfulBuild/artifact/PharoWeb.zip}. 
You should also download a virtual machine for Pharo 4 images \url{http://get.pharo.org/vm40}.
Then, launch this image using this VM and we will configure it.

Let's strat by configuring Seaside by removing all demos applications and all development tools:

\begin{displaycode}{smalltalk}
	"Seaside Deployment configuration"
	WAAdmin clearAll.
	WAAdmin applicationDefaults removeParent: WADevelopmentConfiguration instance.
	WAFileHandler default: WAFileHandler new.
	WAFileHandler default 
		preferenceAt: #fileHandlerListingClass
		put: WAHtmlFileHandlerListing.
	WAAdmin defaultDispatcher 
		register: WAFileHandler default
		at: 'files'.
\end{displaycode}

Now, you can load the TinyBlog application:

\begin{displaycode}{smalltalk}
	"Load TinyBlog"
	Gofer new 
	   smalltalkhubUser: 'PharoMooc' project: 'TinyBlog';
	   package: 'ConfigurationOfTinyBlog';
	   load. 
	#ConfigurationOfTinyBlog asClass loadFinalApp.

	"Create Demo posts if needed"
	#TBBlog asClass createDemoPosts.
\end{displaycode}

or \textbf{your} application directly from your Smalltalkhub code repository:

\begin{displaycode}{smalltalk}
	"Load TinyBlog"
	Gofer new 
	   smalltalkhubUser: 'XXXX' project: 'TinyBlog';
	   package: 'TinyBlog';
	   load. 

	"Create Demo posts if needed"
	#TBBlog asClass createDemoPosts.
\end{displaycode}

We now configure Seaside to use TinyBlog as the default application and we launch the HTTP server.

\begin{displaycode}{smalltalk}
	"Tell Seaside to use TinyBlog as default app"
	WADispatcher default defaultName: 'TinyBlog'.

	"Start HTTP server"
	ZnZincServerAdaptor startOn: 8080.
\end{displaycode}

You can now save the Pharo image (World Menu \textgreater{} save) and test locally with a web browser on the URL: \url{http://localhost:8080}.
\section{Deploy on Ephemeric Cloud of PharoCloud}
You just need to create and archive (zip file) that contains both the \textcode{PharoWeb.image} and \textcode{PharoWeb.changes}.

Then, drag'n drop this archive file on the Ephemeric Cloud web page and activate this Pharo image (play button) as shown in figure \ref{activeEphemerics}.


\begin{figure}

\begin{center}
\includegraphics[width=0.85\textwidth]{figures/ActiveEphemerics.png}\caption{Managing Pharo images on Ephemeric Cloud.\label{activeEphemerics}}\end{center}
\end{figure}


If you clic on the public URL provided Ephemeric Cloud, you should see your web application as displayed on figure \ref{tinyBlogOnPharoCloud}.


\begin{figure}

\begin{center}
\includegraphics[width=0.85\textwidth]{figures/TinyBlogOnPharoCloud.png}\caption{Your TinyBlog Application Hosted on PharoCloud.\label{tinyBlogOnPharoCloud}}\end{center}
\end{figure}



\ifx\wholebook\relax\else
\end{document}
\fi