瀏覽代碼

Do not guess app name/version from mix task

This requires actually compiling the project in dev mode, which is quite
costly wrt the added benefit.
theenglishway (time) 4 年之前
父節點
當前提交
d205d5b19f
共有 2 個文件被更改,包括 9 次插入14 次删除
  1. 4 0
      README.md
  2. 5 14
      priv/build/cross_build.sh

+ 4 - 0
README.md

@@ -30,6 +30,10 @@ updated with the `from_file` function.
 The version can then be read directly from the VERSION file or using the command :
 `mix run -e "Mix.Project.config[:version] |> IO.puts"`
 
+This command is not really handy to run to get build metadata, though, because
+it requires the project to have been compiled at least once in `dev` mode. It is
+therefore more handy to read the VERSION file.
+
 ### PostgreSQL role
 
 In `dev` as well as in `prod` modes, the role used in `config/#{mode}.exs` must 

+ 5 - 14
priv/build/cross_build.sh

@@ -1,28 +1,19 @@
 #!/bin/bash
 set -euo pipefail
 
-get_app() {
-  mix run --no-start -e "Mix.Project.config[:app] |> IO.puts" | tail -1
-}
-
-get_version() {
-  mix run --no-start -e "Mix.Project.config[:version] |> IO.puts" | tail -1
-}
-
-APP_NAME=`get_app`
-APP_VERSION=`get_version`
-OS_VERSION=${OS_VERSION?not set}
-MIX_ENV=${MIX_ENV-prod}
-
 ROOT_DIR=`pwd`
 SOURCE_DIR=$ROOT_DIR
 BUILD_DIR=$ROOT_DIR/priv/build/
 
+APP_NAME=${APP_NAME?not set}
+OS_VERSION=${OS_VERSION?not set}
+MIX_ENV=${MIX_ENV-prod}
+APP_VERSION=$(cat $SOURCE_DIR/VERSION | tail -1)
+
 DOCKER_DIR=$BUILD_DIR/$OS_VERSION
 DOCKER_IMAGE_VERSION=`echo $APP_VERSION | sed "s#+#-#"`
 DOCKER_IMAGE_TAG=$APP_NAME-$OS_VERSION:$DOCKER_IMAGE_VERSION
 
-
 build_image() {
   docker build -t $DOCKER_IMAGE_TAG $DOCKER_DIR
 }