0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-01 11:59:17 -05:00

Improve the current docker development environment.

This commit is contained in:
Andrey Antukh 2019-09-20 17:31:03 +02:00
parent affb1480ce
commit e45ad2197a
8 changed files with 126 additions and 56 deletions

View file

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -x set -xe
sudo pg_ctlcluster 11 main start;
clj -Adev -m uxbox.tests.main clojure -Adev -m uxbox.tests.main;

View file

@ -2,6 +2,7 @@ FROM ubuntu:bionic
LABEL maintainer="Andrey Antukh <niwi@niwi.nz>" LABEL maintainer="Andrey Antukh <niwi@niwi.nz>"
ARG EXTERNAL_UID=1000 ARG EXTERNAL_UID=1000
ARG DEBIAN_FRONTEND=noninteractive
ENV NODE_VERSION=v10.16.3 \ ENV NODE_VERSION=v10.16.3 \
CLOJURE_VERSION=1.10.1.469 \ 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://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; 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; \ RUN set -ex; \
apt-get -qq update; \ apt-get -qq update; \
@ -86,9 +86,10 @@ RUN set -ex; \
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
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/tmux.conf /home/uxbox/.tmux.conf
COPY files/entrypoint.sh /home/uxbox/ COPY files/entrypoint.sh /home/uxbox/
COPY files/init.sh /home/uxbox/
ENTRYPOINT ["zsh", "/home/uxbox/entrypoint.sh"] ENTRYPOINT ["zsh", "/home/uxbox/entrypoint.sh"]
CMD ["/home/uxbox/start-tmux.sh"] CMD ["/home/uxbox/start.sh"]

View file

@ -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

View file

@ -1,5 +1,3 @@
#!/usr/bin/env zsh #!/usr/bin/env zsh
set -ex set -ex
sudo pg_ctlcluster 11 main start
exec "$@" exec "$@"

8
docker/devenv/files/init.sh Executable file
View file

@ -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

View file

@ -10,7 +10,7 @@ tmux send-keys -t uxbox 'clojure -Adev tools.clj figwheel' enter
tmux new-window -t uxbox:2 -n 'backend' tmux new-window -t uxbox:2 -n 'backend'
tmux select-window -t uxbox:2 tmux select-window -t uxbox:2
tmux send-keys -t uxbox 'cd uxbox/backend' enter C-l 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 send-keys -t uxbox 'clojure -Adev:repl' enter
tmux rename-window -t uxbox:0 'gulp' tmux rename-window -t uxbox:0 'gulp'

View file

@ -47,7 +47,7 @@ setopt NOBEEP
setopt INC_APPEND_HISTORY setopt INC_APPEND_HISTORY
export HISTSIZE=100000 export HISTSIZE=100000
export SAVEHIST=100000 export SAVEHIST=100000
export HISTFILE=~/.zhistory export HISTFILE=~/local/.zhistory
setopt hist_ignore_all_dups setopt hist_ignore_all_dups
setopt hist_ignore_space setopt hist_ignore_space

100
manage.sh
View file

@ -2,55 +2,42 @@
set -e set -e
REV=`git log -n 1 --pretty=format:%h -- docker/` REV=`git log -n 1 --pretty=format:%h -- docker/`
IMGNAME="uxbox-devenv" IMGNAME="devenv_uxbox"
function kill-devenv-container {
echo "Cleaning development container $IMGNAME:$REV..."
docker ps -a -f name=$IMGNAME -q | xargs --no-run-if-empty docker kill
}
function remove-devenv-images { function remove-devenv-images {
echo "Clean old development image $IMGNAME..." echo "Clean old development image $IMGNAME..."
docker images $IMGNAME -q | awk '{print $3}' | xargs --no-run-if-empty docker rmi 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)} local EXTERNAL_UID=${1:-$(id -u)}
echo "Building development image $IMGNAME:$REV with UID $EXTERNAL_UID..." docker-compose -f docker/devenv/docker-compose.yaml \
docker build --rm=true \ build --build-arg EXTERNAL_UID=$EXTERNAL_UID --force-rm;
-t $IMGNAME:$REV \
-t $IMGNAME:latest \
--build-arg EXTERNAL_UID=$EXTERNAL_UID \
--label="io.uxbox.devenv" \
docker/devenv
} }
function build-devenv-image-if-not-exists { function build-devenv-if-not-exists {
if [[ ! $(docker images $IMGNAME:$REV -q) ]]; then if [[ ! $(docker images $IMGNAME:latest -q) ]]; then
build-devenv-image $@ build-devenv $@
fi 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 { function run-devenv {
kill-devenv-container; if [[ ! $(docker ps -f "name=uxbox-devenv" -q) ]]; then
build-devenv-image-if-not-exists $@; start-devenv
fi
mkdir -p $HOME/.m2 docker exec -ti uxbox-devenv /home/uxbox/start.sh;
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
} }
function run-all-tests { function run-all-tests {
@ -61,7 +48,7 @@ function run-all-tests {
} }
function run-frontend-tests { function run-frontend-tests {
build-devenv-image-if-not-exists $@; build-devenv-if-not-exists $@;
CONTAINER=$IMGNAME:latest CONTAINER=$IMGNAME:latest
@ -74,7 +61,7 @@ function run-frontend-tests {
} }
function run-backend-tests { function run-backend-tests {
build-devenv-image-if-not-exists $@; build-devenv-if-not-exists $@;
CONTAINER=$IMGNAME:latest CONTAINER=$IMGNAME:latest
@ -86,7 +73,7 @@ function run-backend-tests {
} }
function build-frontend-local { function build-frontend-local {
build-devenv-image-if-not-exists $@; build-devenv-if-not-exists $@;
mkdir -p $HOME/.m2 mkdir -p $HOME/.m2
rm -rf ./frontend/node_modules rm -rf ./frontend/node_modules
@ -158,6 +145,8 @@ function build-backend-image {
} }
function build-images { function build-images {
build-devenv-if-not-exists $@;
echo "Building frontend image ..." echo "Building frontend image ..."
build-frontend-image || exit 1; build-frontend-image || exit 1;
echo "Building frontend dbg image ..." echo "Building frontend dbg image ..."
@ -197,11 +186,17 @@ function usage {
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 "- build-devenv-image Build docker container for development with tmux. Can specify external user id in parameter" echo ""
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 "- build-devenv Build docker development oriented image; (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 "- start-devenv Start the development oriented docker-compose service."
echo "- run-frontend-tests Execute unit tests for frontend only. Can specify external user id in parameter" echo "- stop-devenv Stops the development oriented docker-compose service."
echo "- run-backend-tests Execute unit tests for backend only. Can specify external user id in parameter" 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-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-image Build a 'release ready' docker image for frontend (debug version)"
echo "- build-frontend-dbg-image Build a debug docker image for frontend" echo "- build-frontend-dbg-image Build a debug docker image for frontend"
@ -213,15 +208,26 @@ function usage {
case $1 in case $1 in
clean) clean)
kill-devenv-container
remove-devenv-images 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)
run-devenv ${@:2} run-devenv ${@:2}
;; ;;
stop-devenv)
stop-devenv ${@:2}
;;
## testin related commands
run-all-tests) run-all-tests)
run-all-tests ${@:2} run-all-tests ${@:2}
;; ;;
@ -232,6 +238,8 @@ case $1 in
run-backend-tests ${@:2} run-backend-tests ${@:2}
;; ;;
# production related comands
build-images) build-images)
build-images build-images
;; ;;