-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot run db migration with the uberjar #5
Comments
I propose the following:
However, this fix also exposes another issue that the the migration files are not located under db/migrations anymore in the uberjar. |
Haha! I accidentally did the right thing! |
For the db/migrations in the uberjar, we could add |
I was thinking al;ong the same line when I first saw the problem. After some digging, the problem is that all the paths are joined into one in the uberjar. For example: The source structure:
Becomes this in the uberjar. Note the
I think we can solve this by:
I'm working on the PRs to make it clearer. |
The following commits
I'm worried that this creates more complexity because the
|
I haven't documented this anywhere, I'm still figuring out the best way to deploy small-ish clojure apps to cheap VPS's, which… is not really a design goal of clojure the language but yeah. So I do two things
; alias in deps.edn
:build {:extra-paths ["build"]
:extra-deps {badigeon/badigeon {:git/url "https://github.com/EwenG/badigeon.git"
:sha "dca97f9680a6ea204a2504c4414cafc4ba182a83"
:tag "0.0.6"}}}
; build/package.clj
(ns package
(:require [badigeon.bundle :refer [bundle make-out-path]]
[badigeon.compile :as c]))
(defn -main []
(bundle (make-out-path 'app nil) {:libs-path "jars"})
(c/compile '[server] {:compile-path "target/classes"
:compiler-options {:disable-locals-clearing false
:elide-meta [:doc :file :line :added]
:direct-linking true}})) The next thing I do is create a #!/bin/bash
name=todayinclojure
home_dir="/home/sean"
git_dir="$home_dir/$name/src"
deploy_to="$home_dir/$name"
releases="$home_dir/$name/releases"
tmp_dir="$home_dir/$name/tmp"
target_dir="$home_dir/$name/tmp/target"
timestamp=$(date "+%Y%m%d%H%M%S")
while read oldrev newrev ref
do
if [[ $ref =~ .*/master$ ]];
then
echo "Deploying master branch to $deploy_to and starting service $name"
# make sure required directories exist
mkdir -p $git_dir $releases $tmp_dir $target_dir
# copy latest version of master branch
git --work-tree=$tmp_dir --git-dir=$git_dir checkout -f
cd $tmp_dir
# run migrations and build
COAST_ENV=prod DB_NAME=$deploy_to/$name.sqlite3 make db/migrate
COAST_ENV=prod make build
# save older version of class files
mkdir -p $releases/$timestamp
cp -R target $releases/$timestamp/
# copy the target out of tmp
cp -R target $deploy_to
# restart web server
supervisorctl restart $name
else
echo "Ref $ref successfully received. Doing nothing: only the master branch will be deployed."
fi
done That bash script is actually todayinclojure.com's post-receive git hook 😅 The assets:
clj -m coast.assets
build: assets
clj -Abuild -m package
So a deploy is just And since I push the code and not a binary, I don't have to worry about migrations being as a resource or anything, I just copy the folder over and run migrations like I do when developing locally. Also, please don't hack my server, it uses ssh pub/private keys and everything but I'm pretty sure it's vulnerable to something somehow haha |
LOL, you don't have to worry me hacking you, but perhaps you'd want to obfuscate the IP. I just reverted the #6 and closed coast-framework/coast#82, since there are other way to do db migration. |
The current
uberjar
alias runs the juxt/pack.alpha capsule with the-m
option.According to the doc:
What is implied here is that we cannot switch the main namespace once the uberjar is built. For example, we cannot do
java -jar <uberjar>.jar -m coast.db create
norjava -jar <uberjar>.jar -m coast.migrations migrate
because all the args will be passed intoserver
, instead ofclojure.main
.The text was updated successfully, but these errors were encountered: