You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Fabian Christ <ch...@googlemail.com> on 2013/03/06 15:12:07 UTC

How to start with a Sling-based app

Hi,

I am evaluating the use of Sling for a new project. I have been
studying the documentation of Sling and Jackrabbit for a while now. I
really like the design and the idea behind Sling ;)

But one thing is still unclear to me: In a normal webapp project,
let's say using PHP, I would organize my source a tree similar to any
other software project and deploy that to a production system. Now,
with Sling and having all the content in a JCR repo things seem to be
a bit different.

My question is: How does a typical Sling workflow and project layout
look like for a professional application on top of Sling?

I see the following options:
- Use REST API and develop directly on the content repo
- Configure somehow a file resource provider and organize the sources
and scripts in a local file system
- Implement own OSGI servlets and integrate them with Sling

What is the way to go? I would assume that the REST API is more for
testing and a quick entry for prototyping but I am more looking for
the development of a real application.

When everything is inside the content repo, how is the process of
deploying local developments to a remote production environment? What
about version control for the sources?

Some experience and best practice insights on how to start would be helpful.

Thanks,
 - Fabian

Re: How to start with a Sling-based app

Posted by Sam Lee <sk...@gmail.com>.
An example OSGi bundle project: https://github.com/saml/rosling

I don't use scriptlets much (jsp, ecma  under /apps).
I use repository to store data only, not code.

If you want to use scriptlets, you can use scripts like this to upload the
scriptlets when modified:
https://gist.github.com/saml/5100383






On Wed, Mar 6, 2013 at 10:23 AM, Fabian Christ <christ.fabian@googlemail.com
> wrote:

> 2013/3/6 Bertrand Delacretaz <bd...@apache.org>:
> > The correct link is
> >
> http://sling.apache.org/documentation/bundles/accessing-filesystem-resources-extensions-fsresource.html
> > I'll fix that on the website.
>
> Thanks.
>
> > If you can keep notes while you're doing that
>
> I will try to write down my steps in a reusable way.
>
> --
> Fabian
> http://twitter.com/fctwitt
>

Re: How to start with a Sling-based app

Posted by Fabian Christ <ch...@googlemail.com>.
2013/3/6 Bertrand Delacretaz <bd...@apache.org>:
> The correct link is
> http://sling.apache.org/documentation/bundles/accessing-filesystem-resources-extensions-fsresource.html
> I'll fix that on the website.

Thanks.

> If you can keep notes while you're doing that

I will try to write down my steps in a reusable way.

-- 
Fabian
http://twitter.com/fctwitt

Re: How to start with a Sling-based app

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Wed, Mar 6, 2013 at 3:55 PM, Fabian Christ
<ch...@googlemail.com> wrote:
> 2013/3/6 Bertrand Delacretaz <bd...@apache.org>:
> ...Could you point me to the doc that describes how to configure a file
> system resource provider? The link at [1] points to nowhere.
>
> [1] http://sling.apache.org/documentation/the-sling-engine/resources.html#file-system-resources

The correct link is
http://sling.apache.org/documentation/bundles/accessing-filesystem-resources-extensions-fsresource.html
I'll fix that on the website.

If you can keep notes while you're doing that, I'm interested in
having your final setup documented on the Sling website when you get
to a working stage, that would be a welcome contribution for the
masses who are looking to jump on the Sling bandwagon ;-)

-Bertrand

Re: How to start with a Sling-based app

Posted by Fabian Christ <ch...@googlemail.com>.
Hi Bertrand,

first thanks for your prompt and extensive reply!

2013/3/6 Bertrand Delacretaz <bd...@apache.org>:
>> ...- Configure somehow a file resource provider and organize the sources
>> and scripts in a local file system...
>
> That's a good setup for server-side scripts development - your Sling
> dev instance can tap directly into this...

Could you point me to the doc that describes how to configure a file
system resource provider? The link at [1] points to nowhere.

[1] http://sling.apache.org/documentation/the-sling-engine/resources.html#file-system-resources

> Then, you can package those scripts into bundles at build time, as
> initial content that Sling will deploy when the bundle is installed on
> a production system, reproducing what you had on disk during
> development.

Yes, that was also my initial idea. More tooling for this step would
for sure be helpful. I understand that you have at $work a more
complete tool chain for this ;)

Thanks,
 - Fabian


--
Fabian
http://twitter.com/fctwitt

Re: How to start with a Sling-based app

Posted by Fabian Christ <ch...@googlemail.com>.
2013/3/20 Sarwar Bhuiyan <sa...@gmail.com>:
> Short answer is there isn't a package manager in sling or jackrabbit at the
> moment.  Crx has one but that's commercial. You could probably write an
> exporter/importer which exports a given path and its children using the
> document formats as a zip file.

Too bad. But good to see that I understood this problem correctly.
Sounds like an opportunity for a new open source project ;)

Thanks for the answer!


--
Fabian
http://twitter.com/fctwitt

Re: How to start with a Sling-based app

Posted by Sarwar Bhuiyan <sa...@gmail.com>.
Short answer is there isn't a package manager in sling or jackrabbit at the
moment.  Crx has one but that's commercial. You could probably write an
exporter/importer which exports a given path and its children using the
document formats as a zip file.

Also, please note that even though you have versioning in the osgi bundle,
the content you package up in there in SLING-INF will be overwritten in
JCR. So a reverting from 0.2 to 0.1 means you need to remove 0.2 bundle and
reinstall 0.1 bundle (I think).

Sarwar

On Wednesday, March 20, 2013, Fabian Christ wrote:

> 2013/3/6 Bertrand Delacretaz <bdelacretaz@apache.org <javascript:;>>:
> > [...] and if you see gaps feel free to
> > discuss!
>
> I am catching up on my evaluation of Sling (and I am taking notes).
>
> I see one gap where I am not sure how to proceed. Let's say I have
> created my server side scripts and templates under '/apps'. Now the
> Sling way IIUC is to model the RESTful interface of my web app using
> the JCR, i.e. create nodes in '/content' with proper resourceType
> annotation etc.
>
> The stuff in /apps can be packaged as an OSGi bundle and by this
> versioned like any other software component. It can also be easily
> deployed.
>
> The stuff in the JCR (which is the RESTful interface) is different.
> How should I handle this on deployment to another machine? How is
> versioning supported here? Jackrabbit itself provides some way of
> backup - is this the way to go? I have a feeling that this is the kind
> of tooling that people may have @work but that creates a gap in the
> usability of Sling for others.
>
> --
> Fabian
> http://twitter.com/fctwitt
>

Re: How to start with a Sling-based app

Posted by Bill Puschmann <pu...@gmail.com>.
We recently ran into a similar situation with automatic content loading and
explored putting it into the bundle as well.  We had hoped to use felix as
a "package/content manager" of sorts.  From what I was able to understand,
though, is that stopping a bundle or removing it did not remove the content
as well.  The bundle could be used to inject data into the JCR, but after
that, the bundle lost all claim on it.  Was there a configuration item that
we overlooked?

- B

On Thu, Mar 21, 2013 at 8:01 AM, Bertrand Delacretaz <bdelacretaz@apache.org
> wrote:

> On Thu, Mar 21, 2013 at 11:28 AM, Fabian Christ
> <ch...@googlemail.com> wrote:
> > ...I see some TODOs for the Content Definition File Specification [2]....
>
> oh - it looks like we have two confusing variants of those docs:
>
> http://sling.apache.org/site/content-loading.html looks out of date and
> http://sling.apache.org/site/content-loading-jcrcontentloader.html looks
> better
>
> Could you check if what's described in the latter works for you?
>
> I'll follow up on the dev list about the confusing pages.
>
> -Bertrand
>



-- 
One of the most ordinary weaknesses of the human intellect is to seek to
reconcile contrary principles and to purchase peace at the expense of logic.
                                                        - Alexis de
Tocqueville

Re: How to start with a Sling-based app

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Thu, Mar 21, 2013 at 11:28 AM, Fabian Christ
<ch...@googlemail.com> wrote:
> ...I see some TODOs for the Content Definition File Specification [2]....

oh - it looks like we have two confusing variants of those docs:

http://sling.apache.org/site/content-loading.html looks out of date and
http://sling.apache.org/site/content-loading-jcrcontentloader.html looks better

Could you check if what's described in the latter works for you?

I'll follow up on the dev list about the confusing pages.

-Bertrand

Re: How to start with a Sling-based app

Posted by Fabian Christ <ch...@googlemail.com>.
2013/3/20 Bertrand Delacretaz <bd...@apache.org>:
> Sling provides a way to embed initial content in bundles [2], that is
> installed in the repository when the bundle is activated.

I see some TODOs for the Content Definition File Specification [2]. I
think this is what I am looking for. Is there some more information
available anywhere?

I did not have closer look at the slingbucks example, yet. Maybe there is more.

[2] http://sling.apache.org/site/content-loading.html
--
Fabian
http://twitter.com/fctwitt

Re: How to start with a Sling-based app

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Wed, Mar 20, 2013 at 1:31 PM, Fabian Christ
<ch...@googlemail.com> wrote:
> ...The stuff in /apps can be packaged as an OSGi bundle and by this
> versioned like any other software component. It can also be easily
> deployed...

You mean versioned in your source code tree, right?

> ...The stuff in the JCR (which is the RESTful interface) is different.
> How should I handle this on deployment to another machine? How is
> versioning supported here?...

Sling provides a way to embed initial content in bundles [2], that is
installed in the repository when the bundle is activated. The
Slingbucks sample [1]  does have such content under
src/main/resources/SLING-CONTENT for example. This means your initial
content can live in your source code repository alongside whatever
goes under /apps.

You're right that CQ5 for example adds a content package manager on
top of Sling, which makes distributing JCR content easier - but I
think the Sling initial content mechanisms should work as well, at
least for setting up the base content that your application needs.

Would that initial content mechanism work for you, or what are you missing?

-Bertrand

[1] https://svn.apache.org/repos/asf/sling/trunk/samples/slingbucks
[2] http://sling.apache.org/site/content-loading.html

Re: How to start with a Sling-based app

Posted by Fabian Christ <ch...@googlemail.com>.
2013/3/6 Bertrand Delacretaz <bd...@apache.org>:
> [...] and if you see gaps feel free to
> discuss!

I am catching up on my evaluation of Sling (and I am taking notes).

I see one gap where I am not sure how to proceed. Let's say I have
created my server side scripts and templates under '/apps'. Now the
Sling way IIUC is to model the RESTful interface of my web app using
the JCR, i.e. create nodes in '/content' with proper resourceType
annotation etc.

The stuff in /apps can be packaged as an OSGi bundle and by this
versioned like any other software component. It can also be easily
deployed.

The stuff in the JCR (which is the RESTful interface) is different.
How should I handle this on deployment to another machine? How is
versioning supported here? Jackrabbit itself provides some way of
backup - is this the way to go? I have a feeling that this is the kind
of tooling that people may have @work but that creates a gap in the
usability of Sling for others.

-- 
Fabian
http://twitter.com/fctwitt

Re: How to start with a Sling-based app

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Fabian,

On Wed, Mar 6, 2013 at 3:12 PM, Fabian Christ
<ch...@googlemail.com> wrote:
> ...I
> really like the design and the idea behind Sling ;)...

good, thanks!

> ...I see the following options:
> - Use REST API and develop directly on the content repo...

Using client-side javascript code to read and write content?

That would work - you could use Sling as an intelligent JSON data
store as is, but putting some code in server-side servlets or scripts
(which can also be ecmascript if you like) usually provides more
flexibility and might be easier to test.

That's in addition to client-side code - you basically use server-side
code to supply additional app-specific RESTful endpoints in Sling, and
your client code uses that. In the end you have 3 levels: client code,
server-side scripts and server-side OSGi services.

> ...- Configure somehow a file resource provider and organize the sources
> and scripts in a local file system...

That's a good setup for server-side scripts development - your Sling
dev instance can tap directly into this to avoid having to copy your
scripts to the JCR repository every time you change them (even though
that's quite easy if you mount the JCR repo via webdav).

Then, you can package those scripts into bundles at build time, as
initial content that Sling will deploy when the bundle is installed on
a production system, reproducing what you had on disk during
development.

> ...Implement own OSGI servlets and integrate them with Sling...

I would do that for services that require more stability, robustness
and testability. As scripts and servlets and interchangeable, you
could prototype with scripts and move to java servlets if and when
needed. Note that with "mvn install sling:install" you can update a
bundle quickly on your running dev instance for testing and debugging,
that's how I often work.

At $work we have some additional tools that help synchronize between
the filesystem and the JCR repository, we did discuss contributing
them but I don't know if and when that will happen. In the meantime,
the above setup should be usable, and if you see gaps feel free to
discuss!

-Bertrand

Re: How to start with a Sling-based app

Posted by Fabian Christ <ch...@googlemail.com>.
Hi Sam,

2013/3/6 Sam Lee <sk...@gmail.com>:
> I personally provide  OSGi bundles.

So you implement the complete app as OSGi bundles using bundle based
resource providers? And the content repo is only used to store the
app/user data?

Best,
 - Fabian

Re: How to start with a Sling-based app

Posted by Sam Lee <sk...@gmail.com>.
I personally provide  OSGi bundles.


On Wed, Mar 6, 2013 at 9:12 AM, Fabian Christ
<ch...@googlemail.com>wrote:

> Hi,
>
> I am evaluating the use of Sling for a new project. I have been
> studying the documentation of Sling and Jackrabbit for a while now. I
> really like the design and the idea behind Sling ;)
>
> But one thing is still unclear to me: In a normal webapp project,
> let's say using PHP, I would organize my source a tree similar to any
> other software project and deploy that to a production system. Now,
> with Sling and having all the content in a JCR repo things seem to be
> a bit different.
>
> My question is: How does a typical Sling workflow and project layout
> look like for a professional application on top of Sling?
>
> I see the following options:
> - Use REST API and develop directly on the content repo
> - Configure somehow a file resource provider and organize the sources
> and scripts in a local file system
> - Implement own OSGI servlets and integrate them with Sling
>
> What is the way to go? I would assume that the REST API is more for
> testing and a quick entry for prototyping but I am more looking for
> the development of a real application.
>
> When everything is inside the content repo, how is the process of
> deploying local developments to a remote production environment? What
> about version control for the sources?
>
> Some experience and best practice insights on how to start would be
> helpful.
>
> Thanks,
>  - Fabian
>