diff --git a/backend/scripts/run-tests-in-docker.sh b/backend/scripts/run-tests-in-docker.sh index d2ac2226c..81a3bc5a7 100755 --- a/backend/scripts/run-tests-in-docker.sh +++ b/backend/scripts/run-tests-in-docker.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -x - -clj -Adev -m uxbox.tests.main +set -xe +sudo pg_ctlcluster 11 main start; +clojure -Adev -m uxbox.tests.main; diff --git a/docker/devenv/Dockerfile b/docker/devenv/Dockerfile index 40d3dc9f1..968287408 100644 --- a/docker/devenv/Dockerfile +++ b/docker/devenv/Dockerfile @@ -2,6 +2,7 @@ FROM ubuntu:bionic LABEL maintainer="Andrey Antukh " ARG EXTERNAL_UID=1000 +ARG DEBIAN_FRONTEND=noninteractive ENV NODE_VERSION=v10.16.3 \ CLOJURE_VERSION=1.10.1.469 \ @@ -37,7 +38,6 @@ RUN set -ex; \ 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; -ARG DEBIAN_FRONTEND=noninteractive RUN set -ex; \ apt-get -qq update; \ @@ -86,9 +86,10 @@ RUN set -ex; \ COPY files/bashrc /home/uxbox/.bashrc COPY files/zshrc /home/uxbox/.zshrc COPY files/vimrc /home/uxbox/.vimrc -COPY files/start.sh /home/uxbox/start-tmux.sh +COPY files/start.sh /home/uxbox/start.sh COPY files/tmux.conf /home/uxbox/.tmux.conf COPY files/entrypoint.sh /home/uxbox/ +COPY files/init.sh /home/uxbox/ ENTRYPOINT ["zsh", "/home/uxbox/entrypoint.sh"] -CMD ["/home/uxbox/start-tmux.sh"] +CMD ["/home/uxbox/start.sh"] diff --git a/docker/devenv/docker-compose.yaml b/docker/devenv/docker-compose.yaml new file mode 100644 index 000000000..a373a7489 --- /dev/null +++ b/docker/devenv/docker-compose.yaml @@ -0,0 +1,55 @@ +version: '3' + +networks: + default: + driver: bridge + ipam: + config: + - subnet: 172.177.09.0/24 + +volumes: + postgres_data: + user_data: + +services: + uxbox: + privileged: true + build: + context: ./ + hostname: 'uxbox-devenv' + container_name: 'uxbox-devenv' + command: "/home/uxbox/init.sh" + stop_signal: SIGINT + depends_on: + - postgres + volumes: + - "user_data:/home/uxbox/local" + - "${PWD}:/home/uxbox/uxbox" + - "${HOME}/.m2:/home/uxbox/.m2" + - "${HOME}/.gitconfig:/home/uxbox/.gitconfig" + + ports: + - 3449:3449 + - 6060:6060 + + environment: + - UXBOX_HTTP_SERVER_DEBUG=false + - UXBOX_DATABASE_URI="jdbc:postgresql://postgres/uxbox" + - UXBOX_DATABASE_USERNAME="uxbox" + - UXBOX_DATABASE_PASSWORD="uxbox_postgres_password" + + postgres: + image: postgres:11 + hostname: 'uxbox-devenv-postgres' + container_name: 'uxbox-devenv-postgres' + restart: always + stop_signal: SIGINT + ports: + - 5432:5432 + environment: + - POSTGRES_INITDB_ARGS="--data-checksums" + - POSTGRES_DB=uxbox + - POSTGRES_USER=uxbox + - POSTGRES_PASSWORD=uxbox_postgres_password + volumes: + - postgres_data:/var/lib/postgresql/data diff --git a/docker/devenv/files/entrypoint.sh b/docker/devenv/files/entrypoint.sh index 39082837c..e2f98cf75 100644 --- a/docker/devenv/files/entrypoint.sh +++ b/docker/devenv/files/entrypoint.sh @@ -1,5 +1,3 @@ #!/usr/bin/env zsh set -ex -sudo pg_ctlcluster 11 main start - exec "$@" diff --git a/docker/devenv/files/init.sh b/docker/devenv/files/init.sh new file mode 100755 index 000000000..104e18f5b --- /dev/null +++ b/docker/devenv/files/init.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env zsh +set -e; + +echo "[init.sh] Setting up local permissions." +sudo chown -R uxbox /home/uxbox/local + +echo "[init.sh] Ready!" +tail -f /dev/null diff --git a/docker/devenv/files/start.sh b/docker/devenv/files/start.sh index d5bb65752..4a8976d52 100755 --- a/docker/devenv/files/start.sh +++ b/docker/devenv/files/start.sh @@ -10,7 +10,7 @@ tmux send-keys -t uxbox 'clojure -Adev tools.clj figwheel' enter tmux new-window -t uxbox:2 -n 'backend' tmux select-window -t uxbox:2 tmux send-keys -t uxbox 'cd uxbox/backend' enter C-l -tmux send-keys -t uxbox 'clojure -Adev -m uxbox.fixtures' enter C-l +# tmux send-keys -t uxbox 'clojure -Adev -m uxbox.fixtures' enter C-l tmux send-keys -t uxbox 'clojure -Adev:repl' enter tmux rename-window -t uxbox:0 'gulp' diff --git a/docker/devenv/files/zshrc b/docker/devenv/files/zshrc index 0f4b86593..e5c654b1c 100644 --- a/docker/devenv/files/zshrc +++ b/docker/devenv/files/zshrc @@ -47,7 +47,7 @@ setopt NOBEEP setopt INC_APPEND_HISTORY export HISTSIZE=100000 export SAVEHIST=100000 -export HISTFILE=~/.zhistory +export HISTFILE=~/local/.zhistory setopt hist_ignore_all_dups setopt hist_ignore_space diff --git a/manage.sh b/manage.sh index 152f3e9be..1b154bc5f 100755 --- a/manage.sh +++ b/manage.sh @@ -2,55 +2,42 @@ set -e REV=`git log -n 1 --pretty=format:%h -- docker/` -IMGNAME="uxbox-devenv" - -function kill-devenv-container { - echo "Cleaning development container $IMGNAME:$REV..." - docker ps -a -f name=$IMGNAME -q | xargs --no-run-if-empty docker kill -} +IMGNAME="devenv_uxbox" 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-image { +function build-devenv { + echo "Building development image $IMGNAME:latest with UID $EXTERNAL_UID..." + local EXTERNAL_UID=${1:-$(id -u)} - echo "Building development image $IMGNAME:$REV with UID $EXTERNAL_UID..." - docker build --rm=true \ - -t $IMGNAME:$REV \ - -t $IMGNAME:latest \ - --build-arg EXTERNAL_UID=$EXTERNAL_UID \ - --label="io.uxbox.devenv" \ - docker/devenv + docker-compose -f docker/devenv/docker-compose.yaml \ + build --build-arg EXTERNAL_UID=$EXTERNAL_UID --force-rm; } -function build-devenv-image-if-not-exists { - if [[ ! $(docker images $IMGNAME:$REV -q) ]]; then - build-devenv-image $@ +function build-devenv-if-not-exists { + if [[ ! $(docker images $IMGNAME:latest -q) ]]; then + build-devenv $@ fi } +function start-devenv { + build-devenv-if-not-exists $@; + docker-compose -f docker/devenv/docker-compose.yaml up -d; +} + +function stop-devenv { + docker-compose -f docker/devenv/docker-compose.yaml stop -t 2; +} + function run-devenv { - kill-devenv-container; - build-devenv-image-if-not-exists $@; + if [[ ! $(docker ps -f "name=uxbox-devenv" -q) ]]; then + start-devenv + fi - mkdir -p $HOME/.m2 - rm -rf ./frontend/node_modules - mkdir -p \ - ./frontend/resources/public/css \ - ./frontend/resources/public/view/css - - CONTAINER=$IMGNAME:latest - - echo "Running development image $CONTAINER..." - docker run --rm -ti \ - -v `pwd`:/home/uxbox/uxbox \ - -v $HOME/.m2:/home/uxbox/.m2 \ - -v $HOME/.gitconfig:/home/uxbox/.gitconfig \ - -p 3449:3449 -p 6060:6060 -p 9090:9090 \ - --name "uxbox-devenv" \ - $CONTAINER + docker exec -ti uxbox-devenv /home/uxbox/start.sh; } function run-all-tests { @@ -61,7 +48,7 @@ function run-all-tests { } function run-frontend-tests { - build-devenv-image-if-not-exists $@; + build-devenv-if-not-exists $@; CONTAINER=$IMGNAME:latest @@ -74,7 +61,7 @@ function run-frontend-tests { } function run-backend-tests { - build-devenv-image-if-not-exists $@; + build-devenv-if-not-exists $@; CONTAINER=$IMGNAME:latest @@ -86,7 +73,7 @@ function run-backend-tests { } function build-frontend-local { - build-devenv-image-if-not-exists $@; + build-devenv-if-not-exists $@; mkdir -p $HOME/.m2 rm -rf ./frontend/node_modules @@ -158,6 +145,8 @@ function build-backend-image { } function build-images { + build-devenv-if-not-exists $@; + echo "Building frontend image ..." build-frontend-image || exit 1; echo "Building frontend dbg image ..." @@ -197,11 +186,17 @@ function usage { echo "USAGE: $0 OPTION" echo "Options:" echo "- clean Stop and clean up docker containers" - echo "- build-devenv-image Build docker container for development with tmux. Can specify external user id in parameter" - echo "- run-devenv Run (and build if necessary) development container (frontend at localhost:3449, backend at localhost:6060). Can specify external user id in parameter" - echo "- run-all-tests Execute unit tests for both backend and frontend. Can specify external user id in parameter" - echo "- run-frontend-tests Execute unit tests for frontend only. Can specify external user id in parameter" - echo "- run-backend-tests Execute unit tests for backend only. Can specify external user id in parameter" + echo "" + 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 "- stop-devenv Stops the development oriented docker-compose service." + echo "- run-devenv Attaches to the running devenv container and starts development environment" + echo " based on tmux (frontend at localhost:3449, backend at localhost:6060)." + echo "" + echo "- run-all-tests Execute unit tests for both backend and frontend." + echo "- run-frontend-tests Execute unit tests for frontend only." + echo "- run-backend-tests Execute unit tests for backend only." + echo "" echo "- build-images Build a 'release ready' docker images for both backend and frontend" echo "- build-frontend-image Build a 'release ready' docker image for frontend (debug version)" echo "- build-frontend-dbg-image Build a debug docker image for frontend" @@ -213,15 +208,26 @@ function usage { case $1 in clean) - kill-devenv-container remove-devenv-images ;; - build-devenv-image) - build-devenv-image ${@:2} + + ## devenv related commands + + build-devenv) + build-devenv ${@:2} + ;; + start-devenv) + start-devenv ${@:2} ;; run-devenv) run-devenv ${@:2} ;; + stop-devenv) + stop-devenv ${@:2} + ;; + + ## testin related commands + run-all-tests) run-all-tests ${@:2} ;; @@ -232,6 +238,8 @@ case $1 in run-backend-tests ${@:2} ;; + # production related comands + build-images) build-images ;;