mirror of
https://github.com/penpot/penpot.git
synced 2025-02-08 08:09:14 -05:00
✨ Improve build scripts.
This commit is contained in:
parent
6891826c78
commit
32afe57e18
16 changed files with 174 additions and 144 deletions
81
backend/scripts/build
Executable file
81
backend/scripts/build
Executable file
|
@ -0,0 +1,81 @@
|
||||||
|
#!/usr/bin/env bb
|
||||||
|
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
|
;; defined by the Mozilla Public License, v. 2.0.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) UXBOX Labs SL
|
||||||
|
|
||||||
|
(ns build
|
||||||
|
(:require
|
||||||
|
[clojure.string :as str]
|
||||||
|
[clojure.java.io :as io]
|
||||||
|
[clojure.pprint :refer [pprint]]
|
||||||
|
[babashka.fs :as fs]
|
||||||
|
[babashka.process :refer [$ check]]))
|
||||||
|
|
||||||
|
(defn split-cp
|
||||||
|
[data]
|
||||||
|
(str/split data #":"))
|
||||||
|
|
||||||
|
(def classpath
|
||||||
|
(->> ($ clojure -Spath)
|
||||||
|
(check)
|
||||||
|
(:out)
|
||||||
|
(slurp)
|
||||||
|
(split-cp)
|
||||||
|
(map str/trim)))
|
||||||
|
|
||||||
|
(def classpath-jars
|
||||||
|
(let [xfm (filter #(str/ends-with? % ".jar"))]
|
||||||
|
(into #{} xfm classpath)))
|
||||||
|
|
||||||
|
(def classpath-paths
|
||||||
|
(let [xfm (comp (remove #(str/ends-with? % ".jar"))
|
||||||
|
(filter #(.isDirectory (io/file %))))]
|
||||||
|
(into #{} xfm classpath)))
|
||||||
|
|
||||||
|
(def version
|
||||||
|
(or (first *command-line-args*) "%version%"))
|
||||||
|
|
||||||
|
;; Clean previous dist
|
||||||
|
(-> ($ rm -rf "./target/dist") check)
|
||||||
|
|
||||||
|
;; Create a new dist
|
||||||
|
(-> ($ mkdir -p "./target/dist/deps") check)
|
||||||
|
|
||||||
|
;; Copy all jar deps into dist
|
||||||
|
(run! (fn [item] (-> ($ cp ~item "./target/dist/deps/") check)) classpath-jars)
|
||||||
|
|
||||||
|
;; Create the application jar
|
||||||
|
(spit "./target/dist/version.txt" version)
|
||||||
|
(-> ($ jar cvf "./target/dist/deps/app.jar" -C ~(first classpath-paths) ".") check)
|
||||||
|
(-> ($ jar uvf "./target/dist/deps/app.jar" -C "./target/dist" "version.txt") check)
|
||||||
|
(run! (fn [item]
|
||||||
|
(-> ($ jar uvf "./target/dist/deps/app.jar" -C ~item ".") check))
|
||||||
|
(rest classpath-paths))
|
||||||
|
|
||||||
|
;; Copy logging configuration
|
||||||
|
(-> ($ cp "./resources/log4j2.xml" "./target/dist/") check)
|
||||||
|
|
||||||
|
;; Create classpath file
|
||||||
|
(let [jars (->> (into ["app.jar"] classpath-jars)
|
||||||
|
(map fs/file-name)
|
||||||
|
(map #(fs/path "deps" %))
|
||||||
|
(map str))]
|
||||||
|
(spit "./target/dist/classpath" (str/join ":" jars)))
|
||||||
|
|
||||||
|
;; Copy run script template
|
||||||
|
(-> ($ cp "./scripts/run.template.sh" "./target/dist/run.sh") check)
|
||||||
|
|
||||||
|
;; Copy run script template
|
||||||
|
(-> ($ cp "./scripts/manage.template.sh" "./target/dist/manage.sh") check)
|
||||||
|
|
||||||
|
;; Add exec permisions to scripts.
|
||||||
|
(-> ($ chmod +x "./target/dist/run.sh") check)
|
||||||
|
(-> ($ chmod +x "./target/dist/manage.sh") check)
|
||||||
|
|
||||||
|
nil
|
|
@ -1,75 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
CLASSPATH=`(clojure -Spath)`
|
|
||||||
NEWCP="./main:./common"
|
|
||||||
|
|
||||||
rm -rf ./target/dist
|
|
||||||
mkdir -p ./target/dist/deps
|
|
||||||
|
|
||||||
for item in $(echo $CLASSPATH | tr ":" "\n"); do
|
|
||||||
if [ "${item: -4}" == ".jar" ]; then
|
|
||||||
cp $item ./target/dist/deps/;
|
|
||||||
BN="$(basename -- $item)"
|
|
||||||
NEWCP+=":./deps/$BN"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
cp ./resources/log4j2.xml ./target/dist/log4j2.xml
|
|
||||||
cp -r ./src ./target/dist/main
|
|
||||||
cp -r ./resources/emails ./target/dist/main/
|
|
||||||
cp -r ./resources/error-report.tmpl ./target/dist/main/
|
|
||||||
cp -r ../common ./target/dist/common
|
|
||||||
|
|
||||||
echo $NEWCP > ./target/dist/classpath;
|
|
||||||
|
|
||||||
tee -a ./target/dist/run.sh >> /dev/null <<EOF
|
|
||||||
#!/usr/bin/env bash
|
|
||||||
CP="$NEWCP"
|
|
||||||
|
|
||||||
set +e
|
|
||||||
JAVA_CMD=\$(type -p java)
|
|
||||||
|
|
||||||
set -e
|
|
||||||
if [[ ! -n "\$JAVA_CMD" ]]; then
|
|
||||||
if [[ -n "\$JAVA_HOME" ]] && [[ -x "\$JAVA_HOME/bin/java" ]]; then
|
|
||||||
JAVA_CMD="\$JAVA_HOME/bin/java"
|
|
||||||
else
|
|
||||||
>&2 echo "Couldn't find 'java'. Please set JAVA_HOME."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f ./environ ]; then
|
|
||||||
source ./environ
|
|
||||||
fi
|
|
||||||
|
|
||||||
set -x
|
|
||||||
exec \$JAVA_CMD \$JVM_OPTS -classpath \$CP -Dlog4j2.configurationFile=./log4j2.xml "\$@" clojure.main -m app.main
|
|
||||||
EOF
|
|
||||||
|
|
||||||
tee -a ./target/dist/manage.sh >> /dev/null <<EOF
|
|
||||||
#!/usr/bin/env bash
|
|
||||||
CP="$NEWCP"
|
|
||||||
|
|
||||||
set +e
|
|
||||||
JAVA_CMD=\$(type -p java)
|
|
||||||
|
|
||||||
set -e
|
|
||||||
if [[ ! -n "\$JAVA_CMD" ]]; then
|
|
||||||
if [[ -n "\$JAVA_HOME" ]] && [[ -x "\$JAVA_HOME/bin/java" ]]; then
|
|
||||||
JAVA_CMD="\$JAVA_HOME/bin/java"
|
|
||||||
else
|
|
||||||
>&2 echo "Couldn't find 'java'. Please set JAVA_HOME."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f ./environ ]; then
|
|
||||||
source ./environ
|
|
||||||
fi
|
|
||||||
|
|
||||||
exec \$JAVA_CMD \$JVM_OPTS -classpath \$CP -Dlog4j2.configurationFile=./log4j2.xml clojure.main -m app.cli.manage "\$@"
|
|
||||||
EOF
|
|
||||||
|
|
||||||
chmod +x ./target/dist/run.sh
|
|
||||||
chmod +x ./target/dist/manage.sh
|
|
|
@ -1,4 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
clojure -Adev -m app.cli.collimp $@
|
|
||||||
|
|
19
backend/scripts/manage.template.sh
Normal file
19
backend/scripts/manage.template.sh
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set +e
|
||||||
|
JAVA_CMD=$(type -p java)
|
||||||
|
|
||||||
|
set -e
|
||||||
|
if [[ ! -n "$JAVA_CMD" ]]; then
|
||||||
|
if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
|
||||||
|
JAVA_CMD="$JAVA_HOME/bin/java"
|
||||||
|
else
|
||||||
|
>&2 echo "Couldn't find 'java'. Please set JAVA_HOME."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f ./environ ]; then
|
||||||
|
source ./environ
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec $JAVA_CMD $JVM_OPTS -classpath $(cat classpath) -Dlog4j2.configurationFile=./log4j2.xml clojure.main -m app.cli.manage "\$@"
|
|
@ -1,16 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
if [ "$#" -e 0 ]; then
|
|
||||||
echo "Expecting parameters: 1=path to backend; 2=destination directory"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -rf $2 || exit 1;
|
|
||||||
|
|
||||||
rsync -avr \
|
|
||||||
--exclude="/test" \
|
|
||||||
--exclude="/resources/public/media" \
|
|
||||||
--exclude="/target" \
|
|
||||||
--exclude="/scripts" \
|
|
||||||
--exclude="/.*" \
|
|
||||||
$1 $2;
|
|
|
@ -1,2 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
PGPASSWORD=$PENPOT_DATABASE_PASSWORD psql $PENPOT_DATABASE_URI -U $PENPOT_DATABASE_USERNAME
|
|
|
@ -1,4 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -xe
|
|
||||||
clojure -Adev -m app.tests.main;
|
|
20
backend/scripts/run.template.sh
Normal file
20
backend/scripts/run.template.sh
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set +e
|
||||||
|
JAVA_CMD=$(type -p java)
|
||||||
|
|
||||||
|
set -e
|
||||||
|
if [[ ! -n "$JAVA_CMD" ]]; then
|
||||||
|
if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
|
||||||
|
JAVA_CMD="$JAVA_HOME/bin/java"
|
||||||
|
else
|
||||||
|
>&2 echo "Couldn't find 'java'. Please set JAVA_HOME."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f ./environ ]; then
|
||||||
|
source ./environ
|
||||||
|
fi
|
||||||
|
|
||||||
|
set -x
|
||||||
|
exec $JAVA_CMD $JVM_OPTS -classpath "$(cat classpath)" -Dlog4j2.configurationFile=./log4j2.xml "$@" clojure.main -m app.main
|
|
@ -1,2 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
python -m smtpd -n -c DebuggingServer localhost:25
|
|
|
@ -1,2 +0,0 @@
|
||||||
#!/usr/bin/env sh
|
|
||||||
exec clojure -M:dev:tests "$@"
|
|
|
@ -5,7 +5,7 @@
|
||||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
;; defined by the Mozilla Public License, v. 2.0.
|
;; defined by the Mozilla Public License, v. 2.0.
|
||||||
;;
|
;;
|
||||||
;; Copyright (c) 2020-2021 UXBOX Labs SL
|
;; Copyright (c) UXBOX Labs SL
|
||||||
|
|
||||||
(ns app.config
|
(ns app.config
|
||||||
"A configuration management."
|
"A configuration management."
|
||||||
|
@ -15,6 +15,7 @@
|
||||||
[app.common.version :as v]
|
[app.common.version :as v]
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[clojure.core :as c]
|
[clojure.core :as c]
|
||||||
|
[clojure.java.io :as io]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[environ.core :refer [env]]))
|
[environ.core :refer [env]]))
|
||||||
|
@ -251,7 +252,10 @@
|
||||||
:migrations-verbose false}
|
:migrations-verbose false}
|
||||||
(read-config env)))
|
(read-config env)))
|
||||||
|
|
||||||
(def version (v/parse "%version%"))
|
(def version (v/parse (or (some-> (io/resource "version.txt")
|
||||||
|
(slurp)
|
||||||
|
(str/trim))
|
||||||
|
"%version%")))
|
||||||
(def config (read-config env))
|
(def config (read-config env))
|
||||||
(def test-config (read-test-config env))
|
(def test-config (read-test-config env))
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
source ~/.bashrc
|
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
yarn install
|
yarn install
|
17
frontend/scripts/build
Executable file
17
frontend/scripts/build
Executable file
|
@ -0,0 +1,17 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
CURRENT_VERSION=$1;
|
||||||
|
CURRENT_HASH=$(git rev-parse --short HEAD);
|
||||||
|
EXTRA_PARAMS=$SHADOWCLJS_EXTRA_PARAMS;
|
||||||
|
|
||||||
|
yarn install || exit 1;
|
||||||
|
npx gulp clean || exit 1;
|
||||||
|
npx shadow-cljs release main --config-merge "{:release-version \"${CURRENT_HASH}\"}" $EXTRA_PARAMS || exit 1
|
||||||
|
npx gulp build || exit 1;
|
||||||
|
npx gulp dist:clean || exit 1;
|
||||||
|
npx gulp dist:copy || exit 1;
|
||||||
|
|
||||||
|
sed -i -re "s/\%version\%/$CURRENT_VERSION/g" ./target/dist/index.html;
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
source ~/.bashrc
|
|
||||||
|
|
||||||
set -ex;
|
|
||||||
|
|
||||||
yarn install
|
|
||||||
clojure -Adev tools.clj build:tests
|
|
||||||
node ./target/tests/main
|
|
|
@ -1,21 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
source ~/.bashrc
|
|
||||||
|
|
||||||
set -ex
|
|
||||||
|
|
||||||
if [ -z "${TAG}" ]; then
|
|
||||||
export TAG=$(git log -n 1 --pretty=format:%H -- ./);
|
|
||||||
fi
|
|
||||||
|
|
||||||
yarn install
|
|
||||||
|
|
||||||
export NODE_ENV=production;
|
|
||||||
|
|
||||||
# Clean the output directory
|
|
||||||
npx gulp clean || exit 1;
|
|
||||||
|
|
||||||
npx shadow-cljs release main --config-merge "{:release-version \"${TAG}\"}" $SHADOWCLJS_EXTRA_PARAMS
|
|
||||||
npx gulp build || exit 1;
|
|
||||||
npx gulp dist:clean || exit 1;
|
|
||||||
npx gulp dist:copy || exit 1;
|
|
38
manage.sh
38
manage.sh
|
@ -71,6 +71,9 @@ function run-devenv {
|
||||||
}
|
}
|
||||||
|
|
||||||
function build {
|
function build {
|
||||||
|
echo ">> build start: $1"
|
||||||
|
local version=$(print-current-version);
|
||||||
|
|
||||||
pull-devenv-if-not-exists;
|
pull-devenv-if-not-exists;
|
||||||
docker volume create ${DEVENV_PNAME}_user_data;
|
docker volume create ${DEVENV_PNAME}_user_data;
|
||||||
docker run -t --rm \
|
docker run -t --rm \
|
||||||
|
@ -79,10 +82,28 @@ function build {
|
||||||
-e EXTERNAL_UID=$CURRENT_USER_ID \
|
-e EXTERNAL_UID=$CURRENT_USER_ID \
|
||||||
-e SHADOWCLJS_EXTRA_PARAMS=$SHADOWCLJS_EXTRA_PARAMS \
|
-e SHADOWCLJS_EXTRA_PARAMS=$SHADOWCLJS_EXTRA_PARAMS \
|
||||||
-w /home/penpot/penpot/$1 \
|
-w /home/penpot/penpot/$1 \
|
||||||
$DEVENV_IMGNAME:latest sudo -EH -u penpot ./scripts/build.sh
|
$DEVENV_IMGNAME:latest sudo -EH -u penpot ./scripts/build $version
|
||||||
|
|
||||||
|
echo ">> build end: $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
function put-license-file {
|
||||||
|
local target=$1;
|
||||||
|
tee -a $target/LICENSE >> /dev/null <<EOF
|
||||||
|
This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
|
defined by the Mozilla Public License, v. 2.0.
|
||||||
|
|
||||||
|
Copyright (c) UXBOX Labs SL
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
function build-app-bundle {
|
function build-app-bundle {
|
||||||
|
echo ">> bundle app start";
|
||||||
|
|
||||||
local version=$(print-current-version);
|
local version=$(print-current-version);
|
||||||
local bundle_dir="./bundle-app";
|
local bundle_dir="./bundle-app";
|
||||||
|
|
||||||
|
@ -91,25 +112,28 @@ function build-app-bundle {
|
||||||
|
|
||||||
rm -rf $bundle_dir
|
rm -rf $bundle_dir
|
||||||
mkdir -p $bundle_dir;
|
mkdir -p $bundle_dir;
|
||||||
cp -r ./frontend/target/dist $bundle_dir/frontend;
|
mv ./frontend/target/dist $bundle_dir/frontend;
|
||||||
cp -r ./backend/target/dist $bundle_dir/backend;
|
mv ./backend/target/dist $bundle_dir/backend;
|
||||||
|
|
||||||
echo $version > $bundle_dir/version.txt
|
echo $version > $bundle_dir/version.txt
|
||||||
|
put-license-file $bundle_dir;
|
||||||
sed -i -re "s/\%version\%/$version/g" $bundle_dir/frontend/index.html;
|
echo ">> bundle app end";
|
||||||
sed -i -re "s/\%version\%/$version/g" $bundle_dir/backend/main/app/config.clj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function build-exporter-bundle {
|
function build-exporter-bundle {
|
||||||
|
echo ">> bundle exporter start";
|
||||||
local version=$(print-current-version);
|
local version=$(print-current-version);
|
||||||
local bundle_dir="./bundle-exporter";
|
local bundle_dir="./bundle-exporter";
|
||||||
|
|
||||||
build "exporter";
|
build "exporter";
|
||||||
|
|
||||||
rm -rf $bundle_dir;
|
rm -rf $bundle_dir;
|
||||||
cp -r ./exporter/target $bundle_dir;
|
mv ./exporter/target $bundle_dir;
|
||||||
|
|
||||||
echo $version > $bundle_dir/version.txt
|
echo $version > $bundle_dir/version.txt
|
||||||
|
put-license-file $bundle_dir;
|
||||||
|
|
||||||
|
echo ">> bundle exporter end";
|
||||||
}
|
}
|
||||||
|
|
||||||
function usage {
|
function usage {
|
||||||
|
|
Loading…
Add table
Reference in a new issue