Skip to content
Snippets Groups Projects
Commit dbee7489 authored by Cam Saül's avatar Cam Saül
Browse files

Merge pull request #1049 from metabase/tag-version-when-building-uberjar

A lil bit of script magic to generate file containing latest git tag :sunglasses:
parents b3263c30 407125e8
Branches
Tags
No related merge requests found
......@@ -25,3 +25,4 @@ profiles.clj
/coverage
/resources/sample-dataset.db.trace.db
/deploy/artifacts/*
/resources/version.properties
#! /bin/bash
echo "Running 'npm install' to download javascript dependencies..." &&
npm install &&
# Generate the resources/version.properties file
version() {
# Skip on CircleCI since this is interactive
if [ ! $CI ]; then
VERSION=$(./version)
SHORT_VERSION=$(./version --short)
echo "Running 'webpack -p' to assemble and minify frontend assets..." &&
./node_modules/webpack/bin/webpack.js -p &&
echo "Tagging uberjar with version '$VERSION'..."
if [ -f resources/sample-dataset.db.mv.db ]; then
echo "Sample Dataset already generated."
else
echo "Running 'lein generate-sample-dataset' to generate the sample dataset..."
lein generate-sample-dataset
fi &&
# Ok, now generate the appropriate version.properties file.
echo "long=$VERSION" > resources/version.properties
echo "short=$SHORT_VERSION" >> resources/version.properties
fi
}
frontend() {
echo "Running 'npm install' to download javascript dependencies..." &&
npm install &&
echo "Running 'webpack -p' to assemble and minify frontend assets..." &&
./node_modules/webpack/bin/webpack.js -p
}
sample-dataset() {
if [ -f resources/sample-dataset.db.mv.db ]; then
echo "Sample Dataset already generated."
else
echo "Running 'lein generate-sample-dataset' to generate the sample dataset..."
lein generate-sample-dataset
fi
}
echo "Running 'lein uberjar'..." &&
lein uberjar
uberjar() {
echo "Running 'lein uberjar'..."
lein uberjar
}
all() {
version && frontend && sample-dataset && uberjar
}
# Default to running all but let someone specify one or more sub-tasks to run instead if desired
# e.g.
# ./build-uberjar # do everything
# ./build-uberjar version # just update version.properties
# ./build-uberjar version uberjar # just update version.properties and build uberjar
if [ "$1" ]; then
for cmd in "$@"; do
$cmd
done
else
all
fi
......@@ -70,7 +70,7 @@
[expectations "2.1.2"] ; unit tests
[marginalia "0.8.0"] ; for documentation
[ring/ring-mock "0.2.0"]]
:plugins [[cider/cider-nrepl "0.9.1"] ; Interactive development w/ cider NREPL in Emacs
:plugins [[cider/cider-nrepl "0.10.0-SNAPSHOT"] ; Interactive development w/ cider NREPL in Emacs
[jonase/eastwood "0.2.1"] ; Linting
[lein-ancient "0.6.7"] ; Check project for outdated dependencies + plugins w/ 'lein ancient'
[lein-bikeshed "0.2.0"] ; Linting
......@@ -78,8 +78,9 @@
[lein-expectations "0.0.8"] ; run unit tests with 'lein expectations'
[lein-instant-cheatsheet "2.1.4"] ; use awesome instant cheatsheet created by yours truly w/ 'lein instant-cheatsheet'
[lein-marginalia "0.8.0"] ; generate documentation with 'lein marg'
[refactor-nrepl "1.1.0"]] ; support for advanced refactoring in Emacs/LightTable
[refactor-nrepl "2.0.0-SNAPSHOT"]] ; support for advanced refactoring in Emacs/LightTable
:global-vars {*warn-on-reflection* true} ; Emit warnings on all reflection calls
:env {:mb-run-mode "dev"}
:jvm-opts ["-Dlogfile.path=target/log"
"-Xms1024m" ; give JVM a decent heap size to start with
"-Xmx2048m" ; hard limit of 2GB so we stop hitting the 4GB container limit on CircleCI
......
(ns metabase.config
(:require [environ.core :as environ]
(:require (clojure.java [io :as io]
[shell :as shell])
[clojure.string :as s]
[environ.core :as environ]
[medley.core :as m])
(:import (clojure.lang Keyword)))
(:import clojure.lang.Keyword))
(def ^:const app-defaults
(def ^:private ^:const app-defaults
"Global application defaults"
{;; Database Configuration (general options? dburl?)
:mb-run-mode "prod"
......@@ -39,15 +42,16 @@
;; These are convenience functions for accessing config values that ensures a specific return type
(defn ^Integer config-int [k] (when-let [val (config-str k)] (Integer/parseInt val)))
(defn ^Boolean config-bool [k] (when-let [val (config-str k)] (Boolean/parseBoolean val)))
(defn ^Keyword config-kw [k] (when-let [val (config-str k)] (keyword val)))
(defn ^Integer config-int [k] (some-> k config-str Integer/parseInt))
(defn ^Boolean config-bool [k] (some-> k config-str Boolean/parseBoolean))
(defn ^Keyword config-kw [k] (some-> k config-str keyword))
(def ^:const config-all
"Global application configuration as a dictionary.
Combines hard coded defaults with optional user specified overrides from environment variables."
(into {} (map (fn [k] [k (config-str k)]) (keys app-defaults))))
(into {} (for [k (keys app-defaults)]
[k (config-str k)])))
(defn config-match
......@@ -64,5 +68,31 @@
(m/filter-keys (fn [k] (re-matches prefix-regex (str k))) environ/env))
(m/map-keys (fn [k] (let [kstr (str k)] (keyword (subs kstr (+ 1 (count prefix))))))))))
(defn ^Boolean is-dev? [] (= :dev (config-kw :mb-run-mode)))
(defn ^Boolean is-prod? [] (= :prod (config-kw :mb-run-mode)))
(defn ^Boolean is-test? [] (= :test (config-kw :mb-run-mode)))
;;; Version stuff
;; Metabase version is of the format `GIT-TAG (GIT-SHORT-HASH GIT-BRANCH)`
(defn- version-info-from-shell-script []
{:long (-> (shell/sh "./version") :out s/trim)
:short (-> (shell/sh "./version" "--short") :out s/trim)})
(defn- version-info-from-properties-file []
(with-open [reader (io/reader "resources/version.properties")]
(let [props (java.util.Properties.)]
(.load props reader)
(into {} (for [[k v] props]
[(keyword k) v])))))
(defn mb-version-info
"Return information about the current version of Metabase.
This comes from `resources/version.properties` for prod builds and is fetched from `git` via the `./version` script for dev.
(mb-version) -> {:long \"v0.11.1 (6509c49 master)\", :short \"v0.11.1\"}"
[]
(if (is-prod?)
(version-info-from-properties-file)
(version-info-from-shell-script)))
......@@ -95,7 +95,7 @@
(defn init
"General application initialization function which should be run once at application startup."
[]
(log/info "Metabase Initializing ... ")
(log/info (format "Starting Metabase version %s..." ((config/mb-version-info) :long)))
;; First of all, lets register a shutdown hook that will tidy things up for us on app exit
(.addShutdownHook (Runtime/getRuntime) (Thread. ^Runnable destroy))
(log/debug "Using Config:\n" (with-out-str (clojure.pprint/pprint config/config-all)))
......
(ns metabase.routes
(:require [cheshire.core :as cheshire]
[compojure.core :refer [context defroutes GET]]
[compojure.route :as route]
(:require [clojure.java.io :as io]
[cheshire.core :as json]
(compojure [core :refer [context defroutes GET]]
[route :as route])
[ring.util.response :as resp]
[stencil.core :as stencil]
[metabase.api.routes :as api]
[metabase.setup :as setup]
[metabase.util :as u]))
(metabase.models common
[setting :as setting])
(metabase [config :as config]
[setup :as setup]
[util :as u])
metabase.util.password))
(defn- load-index-template
"Slurp in the Metabase index.html file as a `String`"
[]
(slurp (clojure.java.io/resource "frontend_client/index.html")))
(def load-index
"Memoized version of `load-index-template`"
;(memoize load-index-template)
load-index-template)
(def date-format-rfc2616
(def ^:private ^:const date-format-rfc2616
"Java SimpleDateFormat representing rfc2616 style date used in http headers."
"EEE, dd MMM yyyy HH:mm:ss zzz")
(defn index-page-vars
(defn- index-page-vars
"Static values that we inject into the index.html page via Mustache."
[]
{:ga_code "UA-60817802-1"
......@@ -30,23 +26,26 @@
:password_complexity (metabase.util.password/active-password-complexity)
:setup_token (setup/token-value)
:timezones metabase.models.common/timezones
:version (config/mb-version-info)
;; all of these values are dynamic settings from the admin UI but we include them here for bootstrapping availability
:anon-tracking-enabled (metabase.models.setting/get :anon-tracking-enabled)
:-site-name (metabase.models.setting/get :-site-name)})
:anon-tracking-enabled (setting/get :anon-tracking-enabled)
:-site-name (setting/get :-site-name)})
(defn- index [request]
(-> (io/resource "frontend_client/index.html")
slurp
(stencil/render-string {:bootstrap_json (json/generate-string (index-page-vars))})
resp/response
(resp/content-type "text/html")
(resp/header "Last-Modified" (u/now-with-format date-format-rfc2616))))
;; Redirect naughty users who try to visit a page other than setup if setup is not yet complete
(let [index (fn [request]
(-> (resp/response (stencil/render-string
(load-index)
{:bootstrap_json (cheshire/generate-string (index-page-vars))}))
(resp/content-type "text/html")
(resp/header "Last-Modified" (u/now-with-format date-format-rfc2616))))]
(defroutes routes
(GET "/" [] index) ; ^/$ -> index.html
(GET "/favicon.ico" [] (resp/resource-response "frontend_client/favicon.ico"))
(context "/api" [] api/routes) ; ^/api/ -> API routes
(context "/app" []
(route/resources "/" {:root "frontend_client/app"}) ; ^/app/ -> static files under frontend_client/app
(route/not-found {:status 404 ; return 404 for anything else starting with ^/app/ that doesn't exist
:body "Not found."}))
(GET "*" [] index))) ; Anything else (e.g. /user/edit_current) should serve up index.html; Angular app will handle the rest
(defroutes routes
(GET "/" [] index) ; ^/$ -> index.html
(GET "/favicon.ico" [] (resp/resource-response "frontend_client/favicon.ico"))
(context "/api" [] api/routes) ; ^/api/ -> API routes
(context "/app" []
(route/resources "/" {:root "frontend_client/app"}) ; ^/app/ -> static files under frontend_client/app
(route/not-found {:status 404 ; return 404 for anything else starting with ^/app/ that doesn't exist
:body "Not found."}))
(GET "*" [] index)) ; Anything else (e.g. /user/edit_current) should serve up index.html; Angular app will handle the rest
version 0 → 100755
#! /bin/bash
# Return the version string used to describe this version of Metabase.
TAG=$(git describe origin/master --tags --abbrev=0)
HASH=$(git show-ref --head --hash=7 head) # first 7 letters of hash should be enough; that's what GitHub uses
BRANCH=$(git symbolic-ref --short HEAD)
# ./version -> v0.11.1 (346cbe2 master)
# ./version --short -> v0.11.1
if [ "$1" == "--short" ]; then
echo "$TAG"
else
echo "$TAG ($HASH $BRANCH)"
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment