Launch docker on lein test - clojure

Can I execute a terminal command when lein test is invoked?
I'm trying with
:aliases {"docker-launch" ["run" "-m" "docker" "run" "-it" "--rm" "-p" "27017:27017" "mongo:4.2"]}
:profiles {:default {:prep-tasks ^:test ["docker-launch"] }}
But it only concatenates the docker string with lein run. I need to launch the docker container to execute tests.

Related

How to connect to a gcloud instance and run a command either on startup or consecutively in one line

I'm trying to run a command when I start my gcloud vm server. I added the following command in the console custom metadata
key:
startup-script
value:
#! /bin/bash
parallel 'screen -d -m python3 Documents/myscript.py' ::: arg1 arg2
But when I start the vm instance, it doesn't run because I don't see any screens when I type screen -list. However, when I connect with the gcp tool over SSH using the following command to connect
gcloud beta compute ssh --zone "us-west1-c" "instance-1" --project "unique-kakaw-123456"
and then run
parallel 'screen -d -m python3 Documents/myscript.py' ::: arg1 arg2
consecutively, it runs properly.
How do I either, get my script to run on start up on gcp, or failing which, use the gcloud command to run the command in the same line so then when I hit enter, it will connect to the server and run the command right after. Because if I put both the above commands in the same line and add a ; it won't work obviously.
For some reason, I can add the script to rc.d and update on my ubuntu pc at home and it works fine. I don't know why it doesn't work on gcp.
The startup script should be working. Here's what could be happening:
1. Python script is not being executed because it cannot be found
Compute Engine documentation says:
The instance always executes startup scripts as root after the network is available.
So, if the Python script is in your home directory, provide the full path (replace [USER] with the actual user):
#! /bin/bash
parallel 'screen -d -m python3 /home/[USER]/Documents/myscript.py' ::: arg1 arg2
2. Python script runs and then exits, so screen terminates the window
Screen's User Manual says:
When a program terminates, screen (per default) kills the window that contained it. If this window was in the foreground, the display switches to the previously displayed window; if none are left, screen exits.
Thus if your Python script exits prematurely, add this to your /etc/screenrc:
zombie qr
Here is what this parameter does:
When a string of two keys is specified to the zombie command, ‘dead’ windows will remain in the list.
For the record, I replicated your startup script configuration in my GCP instance (providing the full path) and I can confirm it does work: there were two screens running with my Python script, each with its own argument.

How to configure Jetty settings in project.clj and use Lein Ring in Clojure?

I would like to add some configuration to Jetty Adapter and run it with the lein-ring plugin, but i could not find any information.
I can run this configured from the main function by using lein run.
(jet/run-jetty main-handler {:port 8080 :join? false})
But I want to set those configurations in the project.clj so I can use "lein ring server".
The lein-ring documentation suggests you can put a map of options for your ring adapter in the project.clj file, like this:
:ring {:handler hello-world.core/handler
:adapter {:join? false
:port 8080}}
Though you probably do not want to use :join? false I'd think.

Clojure - Ring uberjar specify port

How can I generate a standalone ring uberjar that listens to a given port ?
When developing I launch my app with the following leiningen/ring command, in which I can specify the port :
lein with-profile dev ring server-headless 9696
Now I want to deploy it, so I ran :
lein with-profile prod ring uberjar 9696
But I got an error :
Error encountered performing task 'ring' with profile(s): 'prod'
clojure.lang.ArityException: Wrong number of args (2) passed to: uberjar/uberjar
So I added a :portin my project.clj :
:ring {:handler img-cli.handler/handler
:init img-cli.handler/init
:destroy img-cli.handler/destroy
:port 9696}
lein with-profile prod ring uberjar
java -jar my-jar.jar
But then I see in the logs : Started server on port 3000
How do I generate an uberjar with the port that I want ?
Note : just in case, I'm using compojure.
It turns out that my use of the profile was problematic.
A closer looks at the profile documentation yields :
To activate a profile in addition to the defaults, prepend it with a
+:
$ lein with-profile +server run
Therefore I had to use lein with-profile +prod ring uberjar 9696 (notice the +).

Issue with lein ring uberjar and profiles

I am having troubles to make lein ring uberjar work with multiple profiles.
The following works:
lein new luminus profile-issue
cd profile-issue
lein ring uberjar
java -jar target\profile-issue-0.1.0-SNAPSHOT-standalone.jar
Now, when working with multiple profiles the following change to project.clj is important.
;add key to project.clj
:target-path "target/%s/"
Next attempt
lein clean
lein ring uberjar
java -jar target\profile-issue-0.1.0-SNAPSHOT-standalone.jar
Error: Could not find or load main class profile_issue.handler.main
The reason why it's important to split the target path into subdirectories when working with multiple profiles is explained here, around line 250. In a nutshell, when using :target-path "target/ you'll end up in troubles because different profiles compile into the same directory and when you start the REPL without a lein clean, you don't really know what you get.
And btw, when using :target-path "target/%s/" the jar and uberjar don't end up in the same directory which is weird.
Any idea?

How can I install Leiningen packages behind a firewall?

I use a local library to do some development, but the firewall prevents alot of internet sites. Is there a way to download artifacts manually?
My project.clj is:
https://github.com/zubairq/coils/blob/master/project.clj?
Update
From the comments given I am understanding that the steps to take are:
1) Install Maven
2) Find out which jars are in my project (How can I do this based on my project.clj?)
Dependency Tree
In order to figure out which jars your project needs you can do:
$ lein deps :tree
Which will show you something that is called a "dependency tree". It will look similar to:
[clj-time "0.5.0"]
[joda-time "2.2"]
[clojure-complete "0.2.3"]
[org.myproject/some-proto "0.0.1-20130523.145830-9"]
[org.flatland/protobuf "0.7.2"]
[ordered-collections "0.4.0"]
[org.flatland/schematic "0.1.0"]
[org.flatland/useful "0.9.0"]
[com.datomic/datomic-free "0.8.3862"]
...
Installing Jars with Lein
One simple way to install manually downloaded jars would be to use "lein-localrepo":
$ lein localrepo install [-r repo-path]
[-p pom-file]
<filename>
<[groupId/]artifactId>
<version>
Here are a couple of examples (given that you have downloaded the jars):
$ lein localrepo install foo-1.0.6.jar com.example/foo 1.0.6
$ lein localrepo install foomatic-1.3.9.jar foomatic 1.3.9
Take a look at the documentation for more features and examples.
Installing lein-localrepo
You can install lein-localrepo as a plugin by adding the following to your ~/.lein/profiles.clj:
{:user {:plugins [[lein-localrepo "0.5.2"]]}}
Lein Behind a Proxy Server
In case it is "ok" to use a proxy server, you can add it to ~/.lein/profiles.clj under jvm-opts
{:user {:jvm-opts ["-Dhttp.proxyHost=168.1.1.104" "-Dhttp.proxyPort=8080"]}}
where user is a profile name to use.
Or you can export http_proxy environment variable before launching lein.