♻️ Refactor on docker and build scripts.

- Migrate to from ubuntu to debian.
- Add new buildenv image.
- Remove production images building from this repo.
- Better comaptibility with other architectures (arm64).
- Improved config management.
This commit is contained in:
Andrey Antukh 2020-01-20 13:03:01 +01:00
parent 655c7ae023
commit f57ce57cb3
26 changed files with 400 additions and 5348 deletions

View file

@ -50,7 +50,7 @@
mount/mount {:mvn/version "0.1.16"} mount/mount {:mvn/version "0.1.16"}
environ/environ {:mvn/version "1.1.0"}} environ/environ {:mvn/version "1.1.0"}}
:paths ["src" "resources" "../common"] :paths ["src" "resources" "../common" "common"]
:aliases :aliases
{:dev {:dev
{:extra-deps {:extra-deps

View file

@ -11,6 +11,8 @@
"A configuration management." "A configuration management."
(:require (:require
[clojure.tools.logging :as log] [clojure.tools.logging :as log]
[clojure.spec.alpha :as s]
[uxbox.common.spec :as us]
[cuerdas.core :as str] [cuerdas.core :as str]
[environ.core :refer [env]] [environ.core :refer [env]]
[mount.core :refer [defstate]] [mount.core :refer [defstate]]
@ -29,37 +31,82 @@
(log/warn (str/istr "can't parse `~{key}` env value")) (log/warn (str/istr "can't parse `~{key}` env value"))
default))))) default)))))
;; --- Configuration Loading & Parsing ;; --- Configuration Loading & Parsing
(defn read-config (defn read-config
[] []
{:http-server-port (lookup-env env :uxbox-http-server-port 6060) {:http-server-port (:uxbox-http-server-port env 6060)
:http-server-debug (lookup-env env :uxbox-http-server-debug true) :http-server-debug (:uxbox-http-server-debug env true)
:http-server-cors (lookup-env env :uxbox-http-server-cors "http://localhost:3449") :http-server-cors (:uxbox-http-server-cors env "http://localhost:3449")
:database-username (lookup-env env :uxbox-database-username nil) :database-username (:uxbox-database-username env nil)
:database-password (lookup-env env :uxbox-database-password nil) :database-password (:uxbox-database-password env nil)
:database-uri (lookup-env env :uxbox-database-uri "postgresql://127.0.0.1/uxbox") :database-uri (:uxbox-database-uri env "postgresql://127.0.0.1/uxbox")
:media-directory (lookup-env env :uxbox-media-directory "resources/public/media") :media-directory (:uxbox-media-directory env "resources/public/media")
:media-uri (lookup-env env :uxbox-media-uri "http://localhost:6060/media/") :media-uri (:uxbox-media-uri env "http://localhost:6060/media/")
:assets-directory (lookup-env env :uxbox-assets-directory "resources/public/static") :assets-directory (:uxbox-assets-directory env "resources/public/static")
:assets-uri (lookup-env env :uxbox-assets-uri "http://localhost:6060/static/") :assets-uri (:uxbox-assets-uri env "http://localhost:6060/static/")
:google-api-key (lookup-env env :uxbox-google-api-key nil) :google-api-key (:uxbox-google-api-key env nil)
:email-reply-to (lookup-env env :uxbox-email-reply-to "no-reply@nodomain.com") :email-reply-to (:uxbox-email-reply-to env "no-reply@nodomain.com")
:email-from (lookup-env env :uxbox-email-from "no-reply@nodomain.com") :email-from (:uxbox-email-from env "no-reply@nodomain.com")
:smtp-host (lookup-env env :uxbox-smtp-host "smtp") :smtp-host (:uxbox-smtp-host env "smtp")
:smtp-port (lookup-env env :uxbox-smtp-port 25) :smtp-port (:uxbox-smtp-port env 25)
:smtp-user (lookup-env env :uxbox-smtp-user nil) :smtp-user (:uxbox-smtp-user env nil)
:smtp-password (lookup-env env :uxbox-smtp-password nil) :smtp-password (:uxbox-smtp-password env nil)
:smtp-tls (lookup-env env :uxbox-smtp-tls false) :smtp-tls (:uxbox-smtp-tls env false)
:smtp-ssl (lookup-env env :uxbox-smtp-ssl false) :smtp-ssl (:uxbox-smtp-ssl env false)
:smtp-enabled (lookup-env env :uxbox-smtp-enabled false) :smtp-enabled (:uxbox-smtp-enabled env false)
:allow-demo-users (lookup-env env :uxbox-allow-demo-users true) :allow-demo-users (:uxbox-allow-demo-users env true)
:registration-enabled (lookup-env env :uxbox-registration-enabled true)}) :registration-enabled (:uxbox-registration-enabled env true)})
(s/def ::http-server-port ::us/integer)
(s/def ::http-server-debug ::us/boolean)
(s/def ::http-server-cors ::us/string)
(s/def ::database-username (s/nilable ::us/string))
(s/def ::database-password (s/nilable ::us/string))
(s/def ::database-uri ::us/string)
(s/def ::assets-uri ::us/string)
(s/def ::assets-directory ::us/string)
(s/def ::media-uri ::us/string)
(s/def ::media-directory ::us/string)
(s/def ::email-reply-to ::us/email)
(s/def ::email-from ::us/email)
(s/def ::smtp-host ::us/string)
(s/def ::smtp-user (s/nilable ::us/string))
(s/def ::smtp-password (s/nilable ::us/string))
(s/def ::smtp-tls ::us/boolean)
(s/def ::smtp-ssl ::us/boolean)
(s/def ::smtp-enabled ::us/boolean)
(s/def ::allow-demo-users ::us/boolean)
(s/def ::registration-enabled ::us/boolean)
(s/def ::config
(s/keys :req-un [::http-server-cors
::http-server-debug
::http-server-port
::database-username
::database-password
::database-uri
::assets-directory
::assets-uri
::media-directory
::media-uri
::email-reply-to
::email-from
::smtp-host
::smtp-user
::smtp-password
::smtp-tls
::smtp-ssl
::smtp-enabled
::allow-demo-users
::registration-enabled]))
(defn read-test-config (defn read-test-config
[] []
@ -70,7 +117,7 @@
:migrations-verbose false)) :migrations-verbose false))
(defstate config (defstate config
:start (read-config)) :start (us/conform ::config (read-config)))
;; --- Secret Loading & Parsing ;; --- Secret Loading & Parsing

View file

@ -78,6 +78,9 @@
(vh/server ctx {:handler handler (vh/server ctx {:handler handler
:port (:http-server-port cfg/config)}))) :port (:http-server-port cfg/config)})))
(defstate instances
:start (.availableProcessors (Runtime/getRuntime)))
(defstate server (defstate server
:start (let [factory (vc/verticle {:on-start on-start})] :start (let [factory (vc/verticle {:on-start on-start})]
@(vc/deploy! system factory {:instances 1}))) @(vc/deploy! system factory {:instances instances})))

View file

@ -1,7 +1,6 @@
/target /target
/classes /classes
/checkouts /checkouts
pom.xml
pom.xml.asc pom.xml.asc
*.jar *.jar
*.class *.class

View file

@ -1,4 +1,4 @@
FROM azul/zulu-openjdk:12 FROM debian:buster
LABEL maintainer="Andrey Antukh <niwi@niwi.nz>" LABEL maintainer="Andrey Antukh <niwi@niwi.nz>"
ENV CLOJURE_VERSION=1.10.1.492 \ ENV CLOJURE_VERSION=1.10.1.492 \
@ -12,6 +12,9 @@ RUN set -ex; \
wget \ wget \
rsync \ rsync \
git \ git \
vim \
rlwrap \
openjdk-11-jdk \
imagemagick \ imagemagick \
webp webp

View file

@ -0,0 +1,55 @@
FROM debian:buster
LABEL maintainer="Andrey Antukh <niwi@niwi.nz>"
ARG DEBIAN_FRONTEND=noninteractive
ENV NODE_VERSION=v12.14.1 \
CLOJURE_VERSION=1.10.1.492 \
LANG=en_US.UTF-8 \
LC_ALL=C.UTF-8
RUN set -ex; \
mkdir -p /etc/resolvconf/resolv.conf.d; \
echo "nameserver 8.8.8.8" > /etc/resolvconf/resolv.conf.d/tail;
RUN set -ex; \
apt-get update && \
apt-get install -yq \
locales \
gnupg2 \
ca-certificates \
wget \
sudo \
vim \
curl \
bash \
git \
rlwrap \
python \
build-essential \
openjdk-11-jdk \
; \
rm -rf /var/lib/apt/lists/*;
COPY files/bashrc /root/.bashrc
COPY files/vimrc /root/.vimrc
COPY files/entrypoint.sh /entrypoint.sh
COPY files/package.json /root/package.json
WORKDIR /root
RUN set -ex; \
wget "https://download.clojure.org/install/linux-install-$CLOJURE_VERSION.sh"; \
chmod +x "linux-install-$CLOJURE_VERSION.sh"; \
"./linux-install-$CLOJURE_VERSION.sh"; \
rm -rf "linux-install-$CLOJURE_VERSION.sh"
RUN set -ex; \
git clone https://github.com/creationix/nvm.git .nvm; \
bash -c "source .nvm/nvm.sh && nvm install $NODE_VERSION"; \
bash -c "source .nvm/nvm.sh && nvm alias default $NODE_VERSION"; \
bash -c "source .nvm/nvm.sh && nvm use default";
RUN set -ex; \
bash -c "source .nvm/nvm.sh && npm install";
ENTRYPOINT ["bash", "/entrypoint.sh"]

View file

@ -0,0 +1,12 @@
export PATH=$HOME/.local/bin:$PATH
alias l='ls --color -GFlh'
alias rm='rm -r'
alias ls='ls --color -F'
alias lsd='ls -d *(/)'
alias lsf='ls -h *(.)'
export LEIN_FAST_TRAMPOLINE=y
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

View file

@ -0,0 +1,4 @@
#!/usr/bin/env zsh
set -ex
exec "$@"

26
docker/buildenv/files/vimrc Executable file
View file

@ -0,0 +1,26 @@
set nocompatible
set bs=2
set ts=4
set tw=1000000000
set expandtab
set tabstop=8
set softtabstop=4
set shiftwidth=4
filetype indent off
filetype plugin on
syntax on
set autoindent
set showmatch
set showmode
set mousehide
set nowrapscan
set hlsearch
set incsearch
set fileencoding=utf8
set encoding=utf8

View file

@ -1,4 +1,4 @@
FROM ubuntu:bionic FROM debian:buster
LABEL maintainer="Andrey Antukh <niwi@niwi.nz>" LABEL maintainer="Andrey Antukh <niwi@niwi.nz>"
ARG EXTERNAL_UID=1000 ARG EXTERNAL_UID=1000
@ -9,6 +9,10 @@ ENV NODE_VERSION=v12.14.1 \
LANG=en_US.UTF-8 \ LANG=en_US.UTF-8 \
LC_ALL=C.UTF-8 LC_ALL=C.UTF-8
RUN set -ex; \
mkdir -p /etc/resolvconf/resolv.conf.d; \
echo "nameserver 8.8.8.8" > /etc/resolvconf/resolv.conf.d/tail;
RUN set -ex; \ RUN set -ex; \
apt-get update && \ apt-get update && \
apt-get install -yq \ apt-get install -yq \
@ -24,45 +28,17 @@ RUN set -ex; \
bash \ bash \
git \ git \
rlwrap \ rlwrap \
python \
build-essential \ build-essential \
imagemagick \ imagemagick \
webp \ webp \
openjdk-11-jdk \
; \ ; \
rm -rf /var/lib/apt/lists/*; rm -rf /var/lib/apt/lists/*;
RUN set -ex; \
mkdir -p /etc/resolvconf/resolv.conf.d; \
echo "nameserver 8.8.8.8" > /etc/resolvconf/resolv.conf.d/tail; \
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0xB1998361219BD9C9; \
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -; \
echo "deb http://repos.azulsystems.com/ubuntu stable main" >> /etc/apt/sources.list.d/zulu.list; \
echo "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main" >> /etc/apt/sources.list.d/postgresql.list;
RUN set -ex; \
apt-get -qq update; \
apt-get install -qqy zulu-12; \
apt-get install -qqy \
postgresql-12 \
postgresql-contrib-12 \
;\
rm -rf /var/lib/apt/lists/*;
COPY files/pg_hba.conf /etc/postgresql/12/main/pg_hba.conf
COPY files/bashrc /root/.bashrc COPY files/bashrc /root/.bashrc
COPY files/vimrc /root/.vimrc COPY files/vimrc /root/.vimrc
RUN set -ex; \
/etc/init.d/postgresql start \
&& createuser -U postgres -sl uxbox \
&& createdb -U uxbox uxbox \
&& createdb -U uxbox test \
&& /etc/init.d/postgresql stop
EXPOSE 3449
EXPOSE 6060
EXPOSE 9090
RUN set -ex; \ RUN set -ex; \
useradd -m -g users -s /bin/zsh -u $EXTERNAL_UID uxbox; \ useradd -m -g users -s /bin/zsh -u $EXTERNAL_UID uxbox; \
passwd uxbox -d; \ passwd uxbox -d; \
@ -77,12 +53,7 @@ RUN set -ex; \
USER uxbox USER uxbox
WORKDIR /home/uxbox WORKDIR /home/uxbox
RUN set -ex; \ COPY files/package.json /home/uxbox/package.json
git clone https://github.com/creationix/nvm.git .nvm; \
bash -c "source .nvm/nvm.sh && nvm install $NODE_VERSION"; \
bash -c "source .nvm/nvm.sh && nvm alias default $NODE_VERSION"; \
bash -c "source .nvm/nvm.sh && nvm use default";
COPY files/bashrc /home/uxbox/.bashrc COPY files/bashrc /home/uxbox/.bashrc
COPY files/zshrc /home/uxbox/.zshrc COPY files/zshrc /home/uxbox/.zshrc
COPY files/vimrc /home/uxbox/.vimrc COPY files/vimrc /home/uxbox/.vimrc
@ -91,5 +62,18 @@ COPY files/tmux.conf /home/uxbox/.tmux.conf
COPY files/entrypoint.sh /home/uxbox/ COPY files/entrypoint.sh /home/uxbox/
COPY files/init.sh /home/uxbox/ COPY files/init.sh /home/uxbox/
RUN set -ex; \
git clone https://github.com/creationix/nvm.git .nvm; \
bash -c "source .nvm/nvm.sh && nvm install $NODE_VERSION"; \
bash -c "source .nvm/nvm.sh && nvm alias default $NODE_VERSION"; \
bash -c "source .nvm/nvm.sh && nvm use default";
RUN set -ex; \
bash -c "source .nvm/nvm.sh && npm install";
EXPOSE 3449
EXPOSE 6060
EXPOSE 9090
ENTRYPOINT ["zsh", "/home/uxbox/entrypoint.sh"] ENTRYPOINT ["zsh", "/home/uxbox/entrypoint.sh"]
CMD ["/home/uxbox/init.sh"] CMD ["/home/uxbox/init.sh"]

View file

@ -14,10 +14,9 @@ volumes:
services: services:
main: main:
privileged: true privileged: true
build: image: "uxbox-devenv"
context: ./ hostname: 'uxbox-devenv-main'
hostname: 'uxboxdev-main' container_name: 'uxbox-devenv-main'
container_name: 'uxboxdev-main'
command: "/home/uxbox/init.sh" command: "/home/uxbox/init.sh"
stop_signal: SIGINT stop_signal: SIGINT
depends_on: depends_on:
@ -25,9 +24,8 @@ services:
- smtp - smtp
volumes: volumes:
- "user_data:/home/uxbox/local" - "user_data:/home/uxbox/local"
- "${PWD}:/home/uxbox/uxbox"
- "${HOME}/.m2:/home/uxbox/.m2" - "${HOME}/.m2:/home/uxbox/.m2"
- "${HOME}/.gitconfig:/home/uxbox/.gitconfig" - "${PWD}:/home/uxbox/uxbox"
ports: ports:
- 3449:3449 - 3449:3449
@ -35,13 +33,13 @@ services:
- 9090:9090 - 9090:9090
environment: environment:
- CLOJURE_OPTS="-J-XX:-OmitStackTraceInFastThrow" - CLOJURE_OPTS=-J-XX:-OmitStackTraceInFastThrow
- UXBOX_DATABASE_URI="postgresql://postgres/uxbox" - UXBOX_DATABASE_URI=postgresql://postgres/uxbox
- UXBOX_DATABASE_USERNAME="uxbox" - UXBOX_DATABASE_USERNAME=uxbox
- UXBOX_DATABASE_PASSWORD="uxbox" - UXBOX_DATABASE_PASSWORD=uxbox
smtp: smtp:
container_name: 'uxboxdev-smtp' container_name: 'uxbox-devenv-smtp'
image: mwader/postfix-relay image: mwader/postfix-relay
restart: always restart: always
environment: environment:
@ -51,14 +49,14 @@ services:
postgres: postgres:
image: postgres:12 image: postgres:12
command: postgres -c config_file=/etc/postgresql.conf command: postgres -c config_file=/etc/postgresql.conf
hostname: 'uxboxdev-postgres' hostname: 'uxbox-devenv-postgres'
container_name: 'uxboxdev-postgres' container_name: 'uxbox-devenv-postgres'
restart: always restart: always
stop_signal: SIGINT stop_signal: SIGINT
ports: ports:
- 5432:5432 - 5432:5432
environment: environment:
- POSTGRES_INITDB_ARGS="--data-checksums" - POSTGRES_INITDB_ARGS=--data-checksums
- POSTGRES_DB=uxbox - POSTGRES_DB=uxbox
- POSTGRES_USER=uxbox - POSTGRES_USER=uxbox
- POSTGRES_PASSWORD=uxbox - POSTGRES_PASSWORD=uxbox

View file

@ -8,5 +8,5 @@ alias lsf='ls -h *(.)'
export LEIN_FAST_TRAMPOLINE=y export LEIN_FAST_TRAMPOLINE=y
export NVM_DIR="/home/uxbox/.nvm" export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

View file

@ -15,7 +15,6 @@ tmux send-keys -t uxbox './bin/start-dev' enter
tmux rename-window -t uxbox:0 'gulp' tmux rename-window -t uxbox:0 'gulp'
tmux select-window -t uxbox:0 tmux select-window -t uxbox:0
tmux send-keys -t uxbox 'cd uxbox/frontend' enter C-l tmux send-keys -t uxbox 'cd uxbox/frontend' enter C-l
tmux send-keys -t uxbox 'if [ ! -e ./node_modules ]; then npm ci; fi' enter C-l
tmux send-keys -t uxbox 'npx gulp watch' enter tmux send-keys -t uxbox 'npx gulp watch' enter
tmux -2 attach-session -t uxbox tmux -2 attach-session -t uxbox

View file

@ -10,7 +10,7 @@ bindkey -e
autoload -U promptinit autoload -U promptinit
promptinit promptinit
prompt zefram prompt suse
#------------------------------ #------------------------------
## Comp stuff ## Comp stuff
@ -52,5 +52,5 @@ setopt hist_ignore_all_dups
setopt hist_ignore_space setopt hist_ignore_space
export PATH=$HOME/.local/bin:$PATH export PATH=$HOME/.local/bin:$PATH
export NVM_DIR="/home/uxbox/.nvm" export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

View file

@ -41,7 +41,8 @@ services:
environment: environment:
# HTTP setup # HTTP setup
- UXBOX_HTTP_SERVER_CORS=* # - CLOJURE_OPTIONS=
- UXBOX_HTTP_SERVER_CORS="*"
# Media & Assets # Media & Assets
- UXBOX_MEDIA_URI="/media/" - UXBOX_MEDIA_URI="/media/"

View file

@ -1,4 +1,4 @@
FROM nginx:1.17.3 FROM nginx:1.17.7
LABEL maintainer="Andrey Antukh <niwi@niwi.nz>" LABEL maintainer="Andrey Antukh <niwi@niwi.nz>"
ENV LANG=en_US.UTF-8 \ ENV LANG=en_US.UTF-8 \

View file

@ -1,20 +1,19 @@
const gulp = require("gulp");
const scss = require("gulp-sass");
const autoprefixer = require('gulp-autoprefixer'); const autoprefixer = require('gulp-autoprefixer');
const rimraf = require("rimraf");
const mustache = require("gulp-mustache");
const rename = require("gulp-rename");
const gulpif = require("gulp-if");
const gzip = require("gulp-gzip");
const cleancss = require("gulp-clean-css"); const cleancss = require("gulp-clean-css");
const fs = require("fs"); const fs = require("fs");
const gulp = require("gulp");
const gulpif = require("gulp-if");
const gzip = require("gulp-gzip");
const l = require("lodash"); const l = require("lodash");
const mustache = require("gulp-mustache");
const rename = require("gulp-rename");
const rimraf = require("rimraf");
const scss = require("gulp-sass");
const paths = {}; const paths = {};
paths.app = "./resources/"; paths.app = "./resources/";
paths.output = "./resources/public/"; paths.output = "./resources/public/";
paths.dist = "./dist/"; paths.dist = "./target/dist/";
paths.target = "./target/";
paths.scss = paths.app + "styles/**/*.scss"; paths.scss = paths.app + "styles/**/*.scss";
/*********************************************** /***********************************************
@ -34,10 +33,7 @@ gulp.task("dist:clean", function(next) {
}); });
function makeAutoprefixer() { function makeAutoprefixer() {
return autoprefixer('last 2 version', return autoprefixer('last 2 version');
'safari 5',
'ios 6',
'android 4');
} }
@ -74,12 +70,12 @@ gulp.task("scss:main", scssPipeline({
output: paths.output + "css/" output: paths.output + "css/"
})); }));
gulp.task("scss:view", scssPipeline({ // gulp.task("scss:view", scssPipeline({
input: paths.app + "styles/view.scss", // input: paths.app + "styles/view.scss",
output: paths.output + "css/" // output: paths.output + "css/"
})); // }));
gulp.task("scss", gulp.parallel("scss:main", "scss:view")); gulp.task("scss", gulp.parallel("scss:main"));
function readLocales() { function readLocales() {
const path = __dirname + "/resources/locales.json"; const path = __dirname + "/resources/locales.json";
@ -125,12 +121,12 @@ gulp.task("template:main", templatePipeline({
output: paths.output output: paths.output
})); }));
gulp.task("template:view", templatePipeline({ // gulp.task("template:view", templatePipeline({
input: paths.app + "templates/view.mustache", // input: paths.app + "templates/view.mustache",
output: paths.output + "view/" // output: paths.output + "view/"
})); // }));
gulp.task("templates", gulp.parallel("template:view", "template:main")); gulp.task("templates", gulp.parallel("template:main"));
// Entry Point // Entry Point
@ -157,16 +153,16 @@ gulp.task("dist:clean", function(next) {
// Templates // Templates
gulp.task("dist:template:main", templatePipeline({ gulp.task("dist:template:main", templatePipeline({
input: paths.app + "index.mustache", input: paths.app + "templates/index.mustache",
output: paths.dist, output: paths.dist,
})); }));
gulp.task("dist:template:view", templatePipeline({ // gulp.task("dist:template:view", templatePipeline({
input: paths.app + "view.mustache", // input: paths.app + "view.mustache",
output: paths.dist + "view/", // output: paths.dist + "view/",
})); // }));
gulp.task("dist:templates", gulp.parallel("dist:template:view", "dist:template:main")); gulp.task("dist:templates", gulp.parallel("dist:template:main"));
// Styles // Styles
@ -175,12 +171,12 @@ gulp.task("dist:scss:main", scssPipeline({
output: paths.dist + "css/" output: paths.dist + "css/"
})); }));
gulp.task("dist:scss:view", scssPipeline({ // gulp.task("dist:scss:view", scssPipeline({
input: paths.app + "styles/view.scss", // input: paths.app + "styles/view.scss",
output: paths.dist + "css/" // output: paths.dist + "css/"
})); // }));
gulp.task("dist:scss", gulp.parallel("dist:scss:main", "dist:scss:view")); gulp.task("dist:scss", gulp.parallel("dist:scss:main"));
// Copy // Copy

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,7 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" /> <meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>UXBOX - The Open-Source prototyping tool</title> <title>UXBOX - The Open-Source prototyping tool</title>
<link href="/css/main.css?ts={{& ts}}" rel="stylesheet" type="text/css" /> <link href="css/main.css?ts={{& ts}}" rel="stylesheet" type="text/css" />
<link rel="icon" href="/images/favicon.png" /> <link rel="icon" href="/images/favicon.png" />
</head> </head>
<body> <body>
@ -13,8 +13,8 @@
<section id="loader"></section> <section id="loader"></section>
<section id="modal"></section> <section id="modal"></section>
<script src="/js/cljs_base.js?ts={{& ts}}"></script> <script src="js/cljs_base.js?ts={{& ts}}"></script>
<script src="/js/main.js?ts={{& ts}}"></script> <script src="js/main.js?ts={{& ts}}"></script>
<script>uxbox.main.init({{& tr }})</script> <script>uxbox.main.init({{& tr }})</script>
</body> </body>
</html> </html>

16
frontend/scripts/build-app.sh Executable file
View file

@ -0,0 +1,16 @@
#!/usr/bin/env bash
source ~/.bashrc
export NODE_ENV=production;
set -ex
npx gulp dist:clean || exit 1;
npx gulp dist || exit 1;
cp -r ./target/dist ./target/dist2
mv ./target/dist2 ./target/dist/dbg
clojure -Adev tools.clj dist:all || exit 1;
npx gulp dist:gzip || exit 1;

View file

@ -1,13 +0,0 @@
#!/usr/bin/env bash
source ~/.bashrc
set -ex
npm ci
npx gulp dist:clean || exit 1
npx gulp dist || exit 1
clojure -Adev tools.clj dbg-dist:all || exit 1
npx gulp dist:gzip || exit 1

View file

@ -1,16 +0,0 @@
#!/usr/bin/env bash
source ~/.bashrc
set -ex
npm ci
export NODE_ENV=production;
npx gulp dist:clean || exit 1;
npx gulp dist || exit 1;
clojure -Adev tools.clj dist:all || exit 1
npx gulp dist:gzip || exit 1

View file

@ -26,7 +26,7 @@
;; This excludes webworker instantiation on nodejs where ;; This excludes webworker instantiation on nodejs where
;; the tests are run. ;; the tests are run.
(when (not= *target* "nodejs") (when (not= *target* "nodejs")
(defonce worker (uw/init "/js/worker.js"))) (defonce worker (uw/init "js/worker.js")))
(defn align-point (defn align-point
[point] [point]

View file

@ -43,7 +43,7 @@
:anon-fn-naming-policy :mapped :anon-fn-naming-policy :mapped
:optimizations :none :optimizations :none
:infer-externs true :infer-externs true
:verbose false :verbose true
:source-map true :source-map true
:static-fns false :static-fns false
:pretty-print true :pretty-print true
@ -63,9 +63,9 @@
:asset-path "/js" :asset-path "/js"
:modules {:main {:entries #{"uxbox.main"} :modules {:main {:entries #{"uxbox.main"}
:output-to "resources/public/js/main.js"} :output-to "resources/public/js/main.js"}
:view {:entries #{"uxbox.view"} ;; :view {:entries #{"uxbox.view"}
:output-to "resources/public/js/view.js" ;; :output-to "resources/public/js/view.js"}
}}}) }})
(def worker-build-options (def worker-build-options
{:main 'uxbox.worker {:main 'uxbox.worker
@ -78,36 +78,42 @@
(-> (merge default-build-options (-> (merge default-build-options
main-build-options main-build-options
dist-build-options) dist-build-options)
(assoc :output-dir "dist/js") (assoc :output-dir "target/dist/js/")
(assoc-in [:modules :main :output-to] "dist/js/main.js") (assoc-in [:modules :main :output-to] "target/dist/js/main.js")
(assoc-in [:modules :view :output-to] "dist/js/view.js"))) #_(assoc-in [:modules :view :output-to] "target/dist/js/view.js")))
(def main-dbg-dist-build-options (def main-dist-dbg-build-options
(merge main-dist-build-options (-> (merge main-dist-build-options
{:optimizations :advanced {:optimizations :advanced
:pseudo-names true :pseudo-names true
:pretty-print true})) :pretty-print true})
(assoc :output-dir "target/dist/dbg/js/")
(assoc-in [:modules :main :output-to] "target/dist/dbg/js/main.js")
#_(assoc-in [:modules :view :output-to] "target/dist/dbg/js/view.js")))
(def worker-dist-build-options (def worker-dist-build-options
(merge default-build-options (merge default-build-options
worker-build-options worker-build-options
dist-build-options dist-build-options
{:output-to "dist/js/worker.js" {:output-to "target/dist/js/worker.js"
:output-dir "dist/js/worker" :output-dir "target/dist/js/worker"
:source-map "dist/js/worker.js.map"})) :source-map "target/dist/js/worker.js.map"}))
(def worker-dbg-dist-build-options (def worker-dist-dbg-build-options
(merge worker-dist-build-options (merge worker-dist-build-options
{:optimizations :advanced {:optimizations :advanced
:pseudo-names true :pseudo-names true
:pretty-print true})) :pretty-print true
:output-to "target/dist/dbg/js/worker.js"
:output-dir "target/dist/dbg/js/worker"
:source-map "target/dist/dbg/js/worker.js.map"}))
;; --- Tasks Definitions ;; --- Tasks Definitions
(defmethod task "dist:main" (defmethod task "dist:main"
[args] [args]
(let [cfg main-dist-build-options] (let [cfg main-dist-build-options]
(pprint cfg) ;; (pprint cfg)
(api/build (api/inputs "src") cfg))) (api/build (api/inputs "src") cfg)))
(defmethod task "dist:worker" (defmethod task "dist:worker"
@ -116,27 +122,24 @@
;; (pprint cfg) ;; (pprint cfg)
(api/build (api/inputs "src") cfg))) (api/build (api/inputs "src") cfg)))
(defmethod task "dbg-dist:main" (defmethod task "dist-dbg:main"
[args] [args]
(let [cfg main-dbg-dist-build-options] (let [cfg main-dist-dbg-build-options]
;; (pprint cfg) ;; (pprint cfg)
(api/build (api/inputs "src") cfg))) (api/build (api/inputs "src") cfg)))
(defmethod task "dbg-dist:worker" (defmethod task "dist-dbg:worker"
[args] [args]
(let [cfg worker-dbg-dist-build-options] (let [cfg worker-dist-dbg-build-options]
;; (pprint cfg) ;; (pprint cfg)
(api/build (api/inputs "src") cfg))) (api/build (api/inputs "src") cfg)))
(defmethod task "dist:all" (defmethod task "dist:all"
[args] [args]
(task ["dist:main"]) (task ["dist:main"])
(task ["dist:worker"])) (task ["dist:worker"])
(task ["dist-dbg:main"])
(defmethod task "dbg-dist:all" (task ["dist-dbg:worker"]))
[args]
(task ["dbg-dist:main"])
(task ["dbg-dist:worker"]))
(defmethod task "repl:node" (defmethod task "repl:node"
[args] [args]
@ -157,7 +160,7 @@
(api/build (api/inputs "src" "test") (api/build (api/inputs "src" "test")
(assoc default-build-options (assoc default-build-options
:main 'uxbox.tests.main :main 'uxbox.tests.main
:verbose false :verbose true
:target :nodejs :target :nodejs
:source-map true :source-map true
:output-to "target/tests/main.js" :output-to "target/tests/main.js"

306
manage.sh
View file

@ -2,27 +2,50 @@
set -e set -e
REV=`git log -n 1 --pretty=format:%h -- docker/` REV=`git log -n 1 --pretty=format:%h -- docker/`
IMGNAME="uxboxdev_main" DEVENV_IMGNAME="uxbox-devenv"
BUILDENV_IMGNAME="uxbox-buildenv"
function remove-devenv-images {
echo "Clean old development image $IMGNAME..."
docker images $IMGNAME -q | awk '{print $3}' | xargs --no-run-if-empty docker rmi
}
function build-devenv { function build-devenv {
echo "Building development image $IMGNAME:latest with UID $EXTERNAL_UID..." echo "Building development image $DEVENV_IMGNAME:latest with UID $EXTERNAL_UID..."
cp ./frontend/build/package.json docker/devenv/files/package.json;
local EXTERNAL_UID=${1:-$(id -u)} local EXTERNAL_UID=${1:-$(id -u)}
docker-compose -p uxboxdev -f docker/devenv/docker-compose.yaml \
build --build-arg EXTERNAL_UID=$EXTERNAL_UID --force-rm; docker build --rm=true --force-rm \
-t $DEVENV_IMGNAME:latest \
--build-arg EXTERNAL_UID=$EXTERNAL_UID \
docker/devenv/;
rm -rf docker/devenv/files/package.json;
}
function build-buildenv {
echo "Building buildenv image..."
docker volume create ${BUILDENV_IMGNAME}-m2
cp ./frontend/build/package.json docker/buildenv/files/package.json;
docker build --rm=true \
-t $BUILDENV_IMGNAME:latest \
docker/buildenv/;
rm -rf docker/buildenv/files/package.json;
} }
function build-devenv-if-not-exists { function build-devenv-if-not-exists {
if [[ ! $(docker images $IMGNAME:latest -q) ]]; then if [[ ! $(docker images $DEVENV_IMGNAME:latest -q) ]]; then
build-devenv $@ build-devenv $@
fi fi
} }
function build-buildenv-if-not-exists {
if [[ ! $(docker images $BUILDENV_IMGNAME:latest -q) ]]; then
build-buildenv $@
fi
}
function start-devenv { function start-devenv {
build-devenv-if-not-exists $@; build-devenv-if-not-exists $@;
docker-compose -p uxboxdev -f docker/devenv/docker-compose.yaml up -d; docker-compose -p uxboxdev -f docker/devenv/docker-compose.yaml up -d;
@ -34,194 +57,94 @@ function stop-devenv {
function drop-devenv { function drop-devenv {
docker-compose -p uxboxdev -f docker/devenv/docker-compose.yaml down -t 2 -v; docker-compose -p uxboxdev -f docker/devenv/docker-compose.yaml down -t 2 -v;
remove-devenv-images;
echo "Clean old development image $DEVENV_IMGNAME..."
docker images $DEVENV_IMGNAME -q | awk '{print $3}' | xargs --no-run-if-empty docker rmi
} }
function run-devenv { function run-devenv {
if [[ ! $(docker ps -f "name=uxboxdev-main" -q) ]]; then if [[ ! $(docker ps -f "name=uxbox-devenv-main" -q) ]]; then
start-devenv start-devenv
fi fi
docker exec -ti uxboxdev-main /home/uxbox/start-tmux.sh docker exec -ti uxbox-devenv-main /home/uxbox/start-tmux.sh
} }
function run-all-tests { # function run-all-tests {
echo "Testing frontend..." # echo "Testing frontend..."
run-frontend-tests $@ || exit 1; # run-frontend-tests $@ || exit 1;
echo "Testing backend..." # echo "Testing backend..."
run-backend-tests $@ || exit 1; # run-backend-tests $@ || exit 1;
} # }
function run-frontend-tests { # function run-frontend-tests {
build-devenv-if-not-exists $@; # build-devenv-if-not-exists $@;
CONTAINER=$IMGNAME:latest # IMAGE=$DEVENV_IMGNAME:latest
echo "Running development image $CONTAINER to test backend..." # echo "Running development image $CONTAINER to test backend..."
docker run -ti --rm \ # docker run -ti --rm \
-w /home/uxbox/uxbox/frontend \ # -w /home/uxbox/uxbox/frontend \
-v `pwd`:/home/uxbox/uxbox \ # -v `pwd`:/home/uxbox/uxbox \
-v $HOME/.m2:/home/uxbox/.m2 \ # -v $HOME/.m2:/home/uxbox/.m2 \
$CONTAINER ./scripts/build-and-run-tests.sh # $IMAGE ./scripts/build-and-run-tests.sh
} # }
function run-backend-tests { # function run-backend-tests {
build-devenv-if-not-exists $@; # build-devenv-if-not-exists $@;
CONTAINER=$IMGNAME:latest # IMAGE=$DEVENV_IMGNAME:latest
docker run -ti --rm \ # docker run -ti --rm \
-w /home/uxbox/uxbox/backend \ # -w /home/uxbox/uxbox/backend \
-v `pwd`:/home/uxbox/uxbox \ # -v `pwd`:/home/uxbox/uxbox \
-v $HOME/.m2:/home/uxbox/.m2 \ # -v $HOME/.m2:/home/uxbox/.m2 \
$CONTAINER ./scripts/run-tests-in-docker.sh # $IMAGE ./scripts/run-tests-in-docker.sh
} # }
function build-frontend-local { function build-frontend {
build-devenv-if-not-exists; build-buildenv-if-not-exists;
mkdir -p $HOME/.m2 local IMAGE=$BUILDENV_IMGNAME:latest;
rm -rf ./frontend/node_modules
CONTAINER=$IMGNAME:latest; echo "Running development image $IMAGE to build frontend."
BUILD_TYPE=$1; docker run -t --rm \
--mount source=`pwd`,type=bind,target=/root/uxbox \
echo "Running development image $CONTAINER to build frontend $BUILD_TYPE ..." --mount source=${BUILDENV_IMGNAME}-m2,target=/root/.m2 \
docker run -ti --rm \ -w /root/uxbox/frontend \
-w /home/uxbox/uxbox/frontend \
-v `pwd`:/home/uxbox/uxbox \
-v $HOME/.m2:/home/uxbox/.m2 \
-e UXBOX_API_URL="/api" \ -e UXBOX_API_URL="/api" \
-e UXBOX_VIEW_URL="/view" \ -e UXBOX_VIEW_URL="/view" \
-e UXBOX_DEMO_WARNING=true \ -e UXBOX_DEMO_WARNING=true \
$CONTAINER ./scripts/build-$BUILD_TYPE.sh $IMAGE ./scripts/build-app.sh
} }
function build-frontend-image { function build-backend {
echo "#############################################" rm -rf ./backend/target/dist
echo "## START build 'uxbox-frontend' image. ##" mkdir -p ./backend/target/dist
echo "#############################################"
build-frontend-local "dist" || exit 1;
rm -rf docker/frontend/dist || exit 1;
cp -vr frontend/dist docker/frontend/ || exit 1;
docker build --rm=true \
-t uxbox-frontend:$REV \
-t uxbox-frontend:latest \
docker/frontend/;
rm -rf docker/frontend/dist || exit 1;
echo "#############################################"
echo "## END build 'uxbox-frontend' image. ##"
echo "#############################################"
}
function build-frontend-dbg-image {
echo "#############################################"
echo "## START build 'uxbox-frontend-dbg' image. ##"
echo "#############################################"
build-frontend-local "dbg-dist" || exit 1;
rm -rf docker/frontend/dist || exit 1;
cp -vr frontend/dist docker/frontend/ || exit 1;
docker build --rm=true \
-t uxbox-frontend-dbg:$REV \
-t uxbox-frontend-dbg:latest \
docker/frontend/;
rm -rf docker/frontend/dist || exit 1;
echo "#############################################"
echo "## END build 'uxbox-frontend-dbg' image. ##"
echo "#############################################"
}
function build-backend-local {
echo "Prepare backend dist..."
rm -rf ./backend/dist
rsync -ar \ rsync -ar \
--exclude="/test" \ --exclude="/tests*" \
--exclude="/resources/public/media" \ --exclude="/resources/public/media" \
--exclude="/target" \ --exclude="/file-uploads" \
--exclude="/scripts" \ --exclude="/target" \
--exclude="/.*" \ --exclude="/scripts" \
./backend/ ./backend/dist/ --exclude="/.*" \
} ./backend/ ./backend/target/dist/
function build-backend-image { rsync -ar \
echo "#############################################" ./common/ ./backend/target/dist/common/
echo "## START build 'uxbox-backend' image. ##"
echo "#############################################"
build-backend-local || exit 1;
rm -rf docker/backend/dist || exit 1;
cp -vr backend/dist docker/backend/ || exit 1;
docker build --rm=true \
-t uxbox-backend:$REV \
-t uxbox-backend:latest \
docker/backend/;
rm -rf docker/backend/dist || exit 1;
echo "#############################################"
echo "## END build 'uxbox-backend' image. ##"
echo "#############################################"
}
function build-images {
build-devenv-if-not-exists $@;
echo "Building frontend image ..."
build-frontend-image || exit 1;
echo "Building frontend dbg image ..."
build-frontend-dbg-image || exit 1;
echo "Building backend image ..."
build-backend-image || exit 1;
}
function run {
if [[ ! $(docker images uxbox-backend:latest) ]]; then
build-backend-image
fi
if [[ ! $(docker images uxbox-frontend:latest) ]]; then
build-frontend-image
fi
if [[ ! $(docker images uxbox-frontend-dbg:latest) ]]; then
build-frontend-dbg-image
fi
echo "Running images..."
docker-compose -p uxbox -f ./docker/docker-compose.yml up -d
}
function log {
docker-compose -p uxbox -f docker/docker-compose.yml logs -f --tail=50
} }
function log-devenv { function log-devenv {
docker-compose -p uxboxdev -f docker/devenv/docker-compose.yaml logs -f --tail=50 docker-compose -p uxboxdev -f docker/devenv/docker-compose.yaml logs -f --tail=50
} }
function stop {
echo "Stoping containers..."
docker-compose -p uxbox -f ./docker/docker-compose.yml stop
}
function drop {
docker-compose -p uxbox -f docker/docker-compose.yml down -t 2 -v;
}
function usage { function usage {
echo "UXBOX build & release manager v$REV" echo "UXBOX build & release manager v$REV"
echo "USAGE: $0 OPTION" echo "USAGE: $0 OPTION"
echo "Options:" echo "Options:"
echo "- clean Stop and clean up docker containers" # echo "- clean Stop and clean up docker containers"
echo "" # echo ""
echo "- build-devenv Build docker development oriented image; (can specify external user id in parameter)" echo "- build-devenv Build docker development oriented image; (can specify external user id in parameter)"
echo "- start-devenv Start the development oriented docker-compose service." echo "- start-devenv Start the development oriented docker-compose service."
echo "- stop-devenv Stops the development oriented docker-compose service." echo "- stop-devenv Stops the development oriented docker-compose service."
@ -244,12 +167,11 @@ function usage {
} }
case $1 in case $1 in
clean) build-buildenv)
remove-devenv-images build-buildenv ${@:2}
;; ;;
## devenv related commands ## devenv related commands
build-devenv) build-devenv)
build-devenv ${@:2} build-devenv ${@:2}
;; ;;
@ -271,45 +193,23 @@ case $1 in
## testin related commands ## testin related commands
run-all-tests) # run-all-tests)
run-all-tests ${@:2} # run-all-tests ${@:2}
;; # ;;
run-frontend-tests) # run-frontend-tests)
run-frontend-tests ${@:2} # run-frontend-tests ${@:2}
;; # ;;
run-backend-tests) # run-backend-tests)
run-backend-tests ${@:2} # run-backend-tests ${@:2}
# ;;
# production builds
build-frontend)
build-frontend
;; ;;
# production related comands build-backend)
build-backend
build-images)
build-images
;;
build-frontend-dbg-image)
build-frontend-dbg-image
;;
build-frontend-image)
build-frontend-image
;;
build-backend-image)
build-backend-image
;;
run)
run
;;
log)
log
;;
stop)
stop
;;
drop)
drop
;; ;;
*) *)