Skip to content

Commit

Permalink
Upgrade to Jolie modules
Browse files Browse the repository at this point in the history
  • Loading branch information
fmontesi committed Oct 14, 2020
1 parent bc206d2 commit 4daa0a8
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 115 deletions.
Empty file removed LeonardoAdminIface.iol
Empty file.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ If you simply want to use Leonardo to host some static content, you can run it a

You just have to tell Leonardo where the static content is located. You can do it in two ways:

- Pass the content directory as an argument. For example, if your content is in `/var/www`, then you should run the command `jolie main.ol /var/www` in directory `cmd/leonardo`.
- Pass the content directory by using the environment variable `LEONARDO_WWW`. In this case, you just need to invoke `jolie main.ol` in directory `cmd/leonardo`.
- Pass the content directory as an argument. For example, if your content is in `/var/www`, then you should run the command `jolie launcher.ol /var/www`.
- Pass the content directory by using the environment variable `LEONARDO_WWW`. In this case, you just need to invoke `jolie launcher.ol`.

# Make a Docker image with your own website

Expand Down
19 changes: 0 additions & 19 deletions config.iol

This file was deleted.

15 changes: 4 additions & 11 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
FROM alpine/git as Build

RUN mkdir -p /app/leonardo
RUN git clone --depth=1 https://github.com/jolie/leonardo.git /app/leonardo
RUN rm -rf /app/leonardo/docker
RUN rm -rf /app/leonardo/.git

# Start from scratch, copy leonardo
FROM jolielang/jolie
WORKDIR /
COPY --from=Build /app /app

WORKDIR /app/leonardo/cmd/leonardo
COPY . /leonardo
RUN rm -rf /leonardo/docker
RUN rm -rf /leonardo/.git

WORKDIR /leonardo
CMD ["jolie","main.ol"]
15 changes: 4 additions & 11 deletions docker/Dockerfile.jre
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
FROM alpine/git as Build

RUN mkdir -p /app/leonardo
RUN git clone --depth=1 https://github.com/jolie/leonardo.git /app/leonardo
RUN rm -rf /app/leonardo/docker
RUN rm -rf /app/leonardo/.git

# Start from scratch, copy leonardo
FROM jolielang/jolie:jre
WORKDIR /
COPY --from=Build /app /app

WORKDIR /app/leonardo/cmd/leonardo
COPY . /leonardo
RUN rm -rf /leonardo/docker
RUN rm -rf /leonardo/.git

WORKDIR /leonardo
CMD ["jolie","main.ol"]
26 changes: 20 additions & 6 deletions hooks.ol
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
type LeonardoConfig {
wwwDir:string
}
/*
Copyright 2018-2020 Fabrizio Montesi <famontesi@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

type DecoratedResponse {
config:LeonardoConfig
config {
wwwDir:string
}
request {
path:string
}
Expand All @@ -18,9 +32,9 @@ type PreResponseFaultType {
type MaybeString: void | string

interface PreResponseHookIface {
RequestResponse: run(DecoratedResponse)(MaybeString) throws PreResponseFault(PreResponseFaultType)
RequestResponse: run( DecoratedResponse )( MaybeString ) throws PreResponseFault( PreResponseFaultType )
}

interface PostResponseHookIface {
RequestResponse: run(DecoratedResponse)(void)
RequestResponse: run( DecoratedResponse )( void )
}
34 changes: 26 additions & 8 deletions internal/hooks/post_response.ol
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
include "../../types/PostResponseHookIface.iol"
/*
Copyright 2018-2020 Fabrizio Montesi <famontesi@gmail.com>
execution { concurrent }
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
inputPort Input {
Location: "local"
Interfaces: PostResponseHookIface
}
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

from ...hooks import PostResponseHookIface

service DefaultPostResponseHook {
execution: concurrent

inputPort Input {
location: "local"
interfaces: PostResponseHookIface
}

main {
run(mesg)()
main {
run( mesg )()
}
}
35 changes: 26 additions & 9 deletions internal/hooks/pre_response.ol
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
include "../../types/PreResponseHookIface.iol"
/*
Copyright 2018-2020 Fabrizio Montesi <famontesi@gmail.com>
execution { concurrent }
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
inputPort Input {
Location: "local"
Interfaces: PreResponseHookIface
}
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

from ...hooks import PreResponseHookIface

service DefaultPreResponseHook {
execution: concurrent

inputPort Input {
location: "local"
interfaces: PreResponseHookIface
}

main
{
run(mesg)(mesg.content)
main {
run( mesg )( mesg.content )
}
}
43 changes: 43 additions & 0 deletions launcher.ol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright 2020 Fabrizio Montesi <famontesi@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

from runtime import Runtime

service Launcher {
embed Runtime as Runtime
main {
if ( is_defined( args[0] ) ) {
dir = args[0]
} else {
getenv@Runtime( "LEONARDO_WWW" )( dir )
}

if( !(dir instanceof void) ) {
config.wwwDir = dir
}

config.location = "socket://localhost:8080"
config.defaultPage = "index.html"

loadEmbeddedService@Runtime( {
filepath = "main.ol"
service = "Leonardo"
params -> config
} )()

linkIn( Shutdown )
}
}
Loading

0 comments on commit 4daa0a8

Please sign in to comment.