diff --git a/backend/scripts/start-dev b/backend/scripts/start-dev index a25db5350d..88cc5c0c0e 100755 --- a/backend/scripts/start-dev +++ b/backend/scripts/start-dev @@ -10,6 +10,23 @@ if [ ! -e ~/.fixtures-loaded ]; then touch ~/.fixtures-loaded fi -clojure -A:dev -M -m app.main +if [ "$1" = "--watch" ]; then + echo "Start Watch..." + + clojure -A:dev -M -m app.main & + PID=$! + + npx nodemon \ + --watch src \ + --watch ../common \ + --ext "clj" \ + --signal SIGKILL \ + --exec 'echo "(user/restart)" | nc -N localhost 6062' + + kill -9 $PID +else + clojure -A:dev -M -m app.main +fi + diff --git a/docker/devenv/Dockerfile b/docker/devenv/Dockerfile index c4a77675f0..6b8290e3a4 100644 --- a/docker/devenv/Dockerfile +++ b/docker/devenv/Dockerfile @@ -28,6 +28,7 @@ RUN set -ex; \ rlwrap \ unzip \ fakeroot \ + netcat \ ; \ echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen; \ locale-gen; \ @@ -172,9 +173,10 @@ COPY files/vimrc /root/.vimrc COPY files/tmux.conf /root/.tmux.conf COPY files/sudoers /etc/sudoers -COPY files/start-tmux.sh /home/start-tmux.sh -COPY files/entrypoint.sh /home/entrypoint.sh -COPY files/init.sh /home/init.sh +COPY files/start-tmux.sh /home/start-tmux.sh +COPY files/start-tmux-back.sh /home/start-tmux-back.sh +COPY files/entrypoint.sh /home/entrypoint.sh +COPY files/init.sh /home/init.sh ENTRYPOINT ["/home/entrypoint.sh"] CMD ["/home/init.sh"] diff --git a/docker/devenv/docker-compose.yaml b/docker/devenv/docker-compose.yaml index cefb211696..764b638db9 100644 --- a/docker/devenv/docker-compose.yaml +++ b/docker/devenv/docker-compose.yaml @@ -13,6 +13,7 @@ volumes: services: main: + profiles: ["full"] privileged: true image: "penpotapp/devenv:latest" build: @@ -49,6 +50,57 @@ services: - PENPOT_SMTP_PASSWORD= - PENPOT_SMTP_SSL=false - PENPOT_SMTP_TLS=false + - PENPOT_FLAGS="enable-cors" + + # LDAP setup + - PENPOT_LDAP_HOST=ldap + - PENPOT_LDAP_PORT=10389 + - PENPOT_LDAP_SSL=false + - PENPOT_LDAP_STARTTLS=false + - PENPOT_LDAP_BASE_DN=ou=people,dc=planetexpress,dc=com + - PENPOT_LDAP_BIND_DN=cn=admin,dc=planetexpress,dc=com + - PENPOT_LDAP_BIND_PASSWORD=GoodNewsEveryone + - PENPOT_LDAP_ATTRS_USERNAME=uid + - PENPOT_LDAP_ATTRS_EMAIL=mail + - PENPOT_LDAP_ATTRS_FULLNAME=cn + - PENPOT_LDAP_ATTRS_PHOTO=jpegPhoto + + backend: + profiles: ["backend"] + privileged: true + image: "penpotapp/devenv:latest" + build: + context: "." + container_name: "penpot-backend" + stop_signal: SIGINT + + depends_on: + - postgres + - redis + + volumes: + - "user_data:/home/penpot/" + - "${PWD}:/home/penpot/penpot" + + ports: + - 6060:6060 + - 6061:6061 + - 9090:9090 + + environment: + - EXTERNAL_UID=${CURRENT_USER_ID} + - PENPOT_SECRET_KEY=super-secret-devenv-key + # STMP setup + - PENPOT_SMTP_ENABLED=true + - PENPOT_SMTP_DEFAULT_FROM=no-reply@example.com + - PENPOT_SMTP_DEFAULT_REPLY_TO=no-reply@example.com + - PENPOT_SMTP_HOST=mailer + - PENPOT_SMTP_PORT=1025 + - PENPOT_SMTP_USERNAME= + - PENPOT_SMTP_PASSWORD= + - PENPOT_SMTP_SSL=false + - PENPOT_SMTP_TLS=false + - PENPOT_FLAGS="enable-cors" # LDAP setup - PENPOT_LDAP_HOST=ldap diff --git a/docker/devenv/files/start-tmux-back.sh b/docker/devenv/files/start-tmux-back.sh new file mode 100755 index 0000000000..7e427080f5 --- /dev/null +++ b/docker/devenv/files/start-tmux-back.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +sudo chown penpot:users /home/penpot + +cd ~; + +source ~/.bashrc + +set -e; + +echo "[start-tmux.sh] Installing node dependencies" +pushd ~/penpot/exporter/ +yarn install +popd + +tmux -2 new-session -d -s penpot + +tmux rename-window -t penpot:0 'exporter' +tmux select-window -t penpot:0 +tmux send-keys -t penpot 'cd penpot/exporter' enter C-l +tmux send-keys -t penpot 'rm -f target/app.js*' enter C-l +tmux send-keys -t penpot 'clojure -M:dev:shadow-cljs watch main' enter + +tmux split-window -v +tmux send-keys -t penpot 'cd penpot/exporter' enter C-l +tmux send-keys -t penpot './scripts/wait-and-start.sh' enter + +tmux new-window -t penpot:1 -n 'backend' +tmux select-window -t penpot:1 +tmux send-keys -t penpot 'cd penpot/backend' enter C-l +tmux send-keys -t penpot './scripts/start-dev' enter + +tmux -2 attach-session -t penpot diff --git a/docker/devenv/files/start-tmux.sh b/docker/devenv/files/start-tmux.sh index 6676425a8f..2891f18bc9 100755 --- a/docker/devenv/files/start-tmux.sh +++ b/docker/devenv/files/start-tmux.sh @@ -18,6 +18,11 @@ popd tmux -2 new-session -d -s penpot +tmux rename-window -t penpot:0 'gulp' +tmux select-window -t penpot:0 +tmux send-keys -t penpot 'cd penpot/frontend' enter C-l +tmux send-keys -t penpot 'npx gulp watch' enter + tmux new-window -t penpot:1 -n 'shadow watch' tmux select-window -t penpot:1 tmux send-keys -t penpot 'cd penpot/frontend' enter C-l @@ -38,9 +43,4 @@ tmux select-window -t penpot:3 tmux send-keys -t penpot 'cd penpot/backend' enter C-l tmux send-keys -t penpot './scripts/start-dev' enter -tmux rename-window -t penpot:0 'gulp' -tmux select-window -t penpot:0 -tmux send-keys -t penpot 'cd penpot/frontend' enter C-l -tmux send-keys -t penpot 'npx gulp watch' enter - tmux -2 attach-session -t penpot diff --git a/manage.sh b/manage.sh index 80d9c6a855..8a2dd4be99 100755 --- a/manage.sh +++ b/manage.sh @@ -44,15 +44,32 @@ function pull-devenv-if-not-exists { function start-devenv { pull-devenv-if-not-exists $@; - docker-compose -p $DEVENV_PNAME -f docker/devenv/docker-compose.yaml up -d; + + # Check if the "backend-only" container is running. If it is, we need tot stop it first + if [[ ! $(docker ps -f "name=penpot-backend" -q) ]]; then + docker-compose -p $DEVENV_PNAME --profile backend -f docker/devenv/docker-compose.yaml stop -t 2 backend; + fi + + docker-compose -p $DEVENV_PNAME --profile full -f docker/devenv/docker-compose.yaml up -d; +} + +function start-backend { + pull-devenv-if-not-exists $@; + + # Check if the "devenv" container is running. If it is, we need tot stop it first because conflicts with the backend + if [[ ! $(docker ps -f "name=penpot-devenv-main" -q) ]]; then + docker-compose -p $DEVENV_PNAME --profile full -f docker/devenv/docker-compose.yaml stop -t 2 main; + fi + + docker-compose -p $DEVENV_PNAME --profile backend -f docker/devenv/docker-compose.yaml up -d; } function stop-devenv { - docker-compose -p $DEVENV_PNAME -f docker/devenv/docker-compose.yaml stop -t 2; + docker-compose -p $DEVENV_PNAME --profile full --profile backend -f docker/devenv/docker-compose.yaml stop -t 2; } function drop-devenv { - docker-compose -p $DEVENV_PNAME -f docker/devenv/docker-compose.yaml down -t 2 -v; + docker-compose -p $DEVENV_PNAME --profile full --profile backend -f docker/devenv/docker-compose.yaml down -t 2 -v; echo "Clean old development image $DEVENV_IMGNAME..." docker images $DEVENV_IMGNAME -q | awk '{print $3}' | xargs --no-run-if-empty docker rmi @@ -70,6 +87,14 @@ function run-devenv { docker exec -ti penpot-devenv-main sudo -EH -u penpot /home/start-tmux.sh } +function run-backend { + if [[ ! $(docker ps -f "name=penpot-backend" -q) ]]; then + start-backend + fi + + docker exec -ti penpot-backend sudo -EH -u penpot /home/start-tmux-back.sh +} + function build { echo ">> build start: $1" local version=$(print-current-version); @@ -175,6 +200,8 @@ function usage { echo "- stop-devenv Stops the development oriented docker-compose service." echo "- drop-devenv Remove the development oriented docker-compose containers, volumes and clean images." echo "- run-devenv Attaches to the running devenv container and starts development environment" + echo "- start-backend Start the backend only service." + echo "- run-backend Starts a backend-only instance and attach tmux to it" echo " based on tmux (frontend at localhost:3449, backend at localhost:6060)." echo "" } @@ -196,9 +223,15 @@ case $1 in start-devenv) start-devenv ${@:2} ;; + start-backend) + start-backend ${@:2} + ;; run-devenv) run-devenv ${@:2} ;; + run-backend) + run-backend ${@:2} + ;; stop-devenv) stop-devenv ${@:2} ;;