This is an example application that utilises the Spurious Clojure AWS SDK Helper.
You'll need to have Spurious running (see project for installation steps).
You'll also need some content put into the Spurious S3 bucket. Here is an example script that utilises Ruby to put content into the Spurious S3 bucket (I used Ruby instead of Clojure as a way to demonstrate how Spurious works with multiple languages). Simply modify the bucket name and object path to suit your needs.
If you're not using Docker, then you'll need Leiningen 1.7.0 or above installed.
To start a web server for the application, run:
lein ring server
If you want to use the application from inside a Docker container you'll need to modify the application code for src/spurious_clojure_example/routes/home.clj to use :docker instead of :app.
To build the Docker image from the provided Dockerfile, execute the following command:
docker build -t spurious-clojure-example .Note: the
Dockerfilehas been set-up in such a way as to cache dependencies and to only download them if they change; but I have noticed issues when testing libraries locally, so you might want to add the--no-cacheflag (but be careful, you'll end up running out of disk space eventually)
Note: the
--envflag is for testing purposes only
also change--publishflag to your own preference
Multi-line version (for readability)...
docker run -it --rm \
--name spurious-app \
--env DEBUG=true \
--publish 4000:8080 \
--link spurious-s3:s3.spurious.localhost \
--link spurious-sqs:sqs.spurious.localhost \
--link spurious-dynamo:dynamodb.spurious.localhost \
spurious-clojure-exampleOne liner...
docker run -it --rm --name spurious-app --env DEBUG=true --publish 4000:8080 --link spurious-s3:s3.spurious.localhost --link spurious-sqs:sqs.spurious.localhost --link spurious-dynamo:dynamodb.spurious.localhost spurious-clojure-exampleI wanted to test the spurious-clojure-aws-sdk-helper before releasing it officially to the public Clojars repository.
To do this I ran lein install from that code repo - which installs it locally to your ~/.m2 cache. Now I'm able to add this cache directory into my Docker container to use instead of the actual Clojars endpoint. To do this follow these steps:
- Add
ADD .m2/repository /root/.m2/repositoryto theDockerfile - Run
rm -rf .m2to remove the directory from this current repo (in case you followed these steps previously) - Run
cp -r ~/.m2 ./(to get a fresh copy of your lein cache into this repo) - Run
docker build -t spurious-clojure-example .to build a new image with the fresh cache - Run the container as before
It can be useful to jump inside a running Clojure based Docker container by using the following command. For example, I needed to verify the location of the lein cache directory within a non-mac environment):
docker run -it -v /path/to/your/app:/app clojure bashThe following notes all refer to the spurious-clojure-example.routes.home namespace...
-
You'll notice that the helper is loaded within the
nsmacros rather than dynamically loaded at runtime. This is because the application (when deployed) is compiled into a Jar file with all dependences included; this means that there is no point doing a dynamicrequireof a library when in dev/debug mode. -
There are two keynames
:bucket-nameand:key(which is an S3 object path). Make sure to set the values to an appropriate location which matches your own (Spurious/Live) S3 objects. -
The
credentialsfunction is only to demonstrate the principle of using a basicifcondition to switch between dev/debug and live credentials. Obviously (well, it probably should be obvious) storing your access keys in your code is a bad idea and they should be referenced via some external mechanism (such as environment variables).
Copyright © 2015 Integralist