"How to publish Smalltalk Image from Pharo Workspace" by Mike on at tutorial/ephemeric_publish_from_workspace under #ephemericcloud  

How to publish Smalltalk Image from Pharo Workspace

Ephemeric cloud is a cloud platform which is managed by REST API. It is very simple to publish your Pharo Image as ephemeric using just Pharo itself. You may execute the below listed script in any morden Pharo instance to publish it online (ZnClient class is available by default in Pharo).

Please note that one of requirements to the published images is that it must run a web server on 8080 port. Please make sure that the server auto starts a web server on 8080 upon the start of the Image.

Note

For instance, Teapot HTTP server does not start automatically as it is needed to be added to the start up list manually first.

To start the publishing process, save the current state of your image to a disk:

"Snapshot current state to a new file"
Smalltalk saveAsNewVersion.

Warning

Do not execute the saving of the Image with the rest of the script in just one "do it" command as it will lead to unexpected behaviour: Image will try to publish itself automatically upon every start, possibly breaking in headless mode.

After you saved the image will execute the following code in Playground (or Workspace):

|user authToken zipImage entity answerJSON ephemericUrl|

"Ephemeric cloud credentials (available at http://www.pharocloud.com)"
user := ''.
authToken := ''.

"Create a zip archive from the image file"
ZipArchive new addFile: Smalltalk imageFile basename; writeToFileNamed: Smalltalk imageFile basename,'.zip'.
zipImage := (Smalltalk imageFile basename,'.zip') asFileReference.

"Create HTTP multi-part post-query"
entity := ZnMultiPartFormDataEntity new 
	addPart: (ZnMimePart 
		fieldName: 'imageZip'
		fileName: Smalltalk imageFile basename
		entity: (ZnStreamingEntity 
			readBinaryFrom: zipImage binaryReadStream 
			usingType: 'application/zip' asMIMEType 
			andLength: zipImage size)); yourself.

"Send the query, read output"
answerJSON := (ZnClient new
		beOneShot;
		url: ('https://www.pharocloud.com/api/ephemerics/user/{1}?auth={2}' format: { user. authToken }) asUrl;
		entity: entity;
		timeout: 60*1000;
		post;
		response) contents.

"Get and show the URL of your appliance"
ephemericUrl := ('http://', (answerJSON subStrings: '"') first) asUrl.
ephemericUrl inspect.

http://ws.stfx.eu/BTURJDRFU7BO

That's it, you should have an inspector opened on URL of your online application.

Please try the script and share your feedback with me.

Cheers, Mike

blog comments powered by Disqus