diff --git a/.dockerenv.example b/.dockerenv.example new file mode 100644 index 0000000000..324b7a5441 --- /dev/null +++ b/.dockerenv.example @@ -0,0 +1,6 @@ + +DOCKER_DEV_IMAGE=complat/dev:v1.10.3-37-ga95534401 +#DOCKER_PG_IMAGE=postgres:16 +## User another named volume for homedir (asdf, gems, etc) +#VOLUME_NAME_HOMEDIR=homedir2 +#VOLUME_NAME_DB=database2 diff --git a/.tool-versions b/.tool-versions index a2c2b48d42..10a935d975 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -nodejs 18.20.4 18.20.3 +nodejs 18.20.5 18.20.4 ruby 2.7.8 diff --git a/Dockerfile.chemotion-dev b/Dockerfile.chemotion-dev index 03022f78ef..626e418639 100644 --- a/Dockerfile.chemotion-dev +++ b/Dockerfile.chemotion-dev @@ -6,6 +6,8 @@ FROM --platform=linux/amd64 ubuntu:jammy ARG DEBIAN_FRONTEND=noninteractive +ARG FULL_BUILD=false +ARG BRANCH=main RUN set -xe && apt-get update -yqqq --fix-missing && apt-get upgrade -y RUN apt update && apt-get install -yqq --fix-missing bash ca-certificates wget apt-transport-https git gpg\ @@ -39,3 +41,27 @@ SHELL ["/bin/bash", "-c"] # Even if asdf and the related tools are only installed by running run-ruby-dev.sh, we set the PATH variables here, so when we enter the container via docker exec, we have the path set correctly ENV ASDF_DIR=/home/chemotion-dev/.asdf ENV PATH=/home/chemotion-dev/.asdf/shims:/home/chemotion-dev/.asdf/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +ENV NODE_PATH=/home/chemotion-dev/node_modules + +RUN git clone --single-branch --branch=$BRANCH https://github.com/complat/chemotion_ELN app + +# Install asdf if FULL_BUILD is set to true +WORKDIR /home/chemotion-dev/app +RUN if [ "$FULL_BUILD" = "true" ]; then \ + ./prepare-asdf.sh; \ + fi + +# Install ruby and nodejs if FULL_BUILD is set to true +RUN if [ "$FULL_BUILD" = "true" ]; then \ + ./prepare-rubygems.sh; \ + fi + +# Install nodejs packages if FULL_BUILD is set to true +RUN if [ "$FULL_BUILD" = "true" ]; then \ + echo -e "--modules-folder ${NODE_PATH}\n" > /home/chemotion-dev/app/.yarnrc; \ + ./prepare-nodejs.sh; \ + ./prepare-nodejspkg.sh; \ + fi + +WORKDIR /home/chemotion-dev +RUN rm -rf /home/chemotion-dev/app diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 54e5e8d198..85e0bf4a5b 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -11,7 +11,7 @@ # services: postgres: - image: 'postgres:14' + image: ${DOCKER_PG_IMAGE:-postgres:14} environment: - 'POSTGRES_HOST_AUTH_METHOD=trust' expose: # expose port to app container @@ -19,12 +19,13 @@ services: ports: # expose port to host machine in case we want to use external db gui tools - '5432:5432' volumes: - - 'database:/var/lib/postgresql/data' + - ${VOLUME_NAME_DB:-database}:/var/lib/postgresql/data' app: build: context: '.' dockerfile: 'Dockerfile.chemotion-dev' + image: ${DOCKER_DEV_IMAGE:-} depends_on: - 'postgres' healthcheck: @@ -38,7 +39,7 @@ services: ports: # expose default rails port to host machine - "3000:3000" volumes: - - 'homedir:/home/chemotion-dev/' + - ${VOLUME_NAME_HOMEDIR:-homedir}:/home/chemotion-dev/ - '.:/home/chemotion-dev/app' working_dir: "/home/chemotion-dev/app" command: "./run-ruby-dev.sh" @@ -47,6 +48,7 @@ services: build: context: '.' dockerfile: 'Dockerfile.chemotion-dev' + image: ${DOCKER_DEV_IMAGE:-} depends_on: app: condition: service_healthy @@ -56,7 +58,7 @@ services: - 'SHAKAPACKER_DEV_SERVER_PORT=3035' env_file: ./.env volumes: - - 'homedir:/home/chemotion-dev/' + - ${VOLUME_NAME_HOMEDIR:-homedir}:/home/chemotion-dev/ - '.:/home/chemotion-dev/app' ports: # expose webpacker dev server port to app container - '3035:3035' diff --git a/prepare-nodejs.sh b/prepare-nodejs.sh index 85f85087e5..d71ea0df67 100755 --- a/prepare-nodejs.sh +++ b/prepare-nodejs.sh @@ -7,6 +7,7 @@ set -e +echo '>>> check nodejs version as set in package.json: install if mismatch, and correct .tool-versions' # Get the currently installed Node.js version using asdf CURRENT_NODE_VERSION=$(asdf current nodejs 2>/dev/null | awk '{print $2}') diff --git a/prepare-nodejspkg.sh b/prepare-nodejspkg.sh index 3811d13989..9d4f285a11 100755 --- a/prepare-nodejspkg.sh +++ b/prepare-nodejspkg.sh @@ -24,5 +24,4 @@ fi echo '>>> Installing JS packages...' yarn install --production=false -yarn install diff --git a/prepare-ruby-dev.sh b/prepare-ruby-dev.sh index 280b54ed73..dfe3e47dfb 100755 --- a/prepare-ruby-dev.sh +++ b/prepare-ruby-dev.sh @@ -5,17 +5,14 @@ # asdf-vm installation with ruby and nodejs plugins export ASDF_BRANCH=v0.14.0 echo '>>> checking asdf installation' -./prepare-asdf.sh -# check nodejs version as set in package.json: install if mismatch, and correct .tool-versions' -echo '>>> check nodejs version as set in package.json: install if mismatch, and correct .tool-versions' -./prepare-nodejs.sh +./prepare-asdf.sh # ruby gems installation ./prepare-rubygems.sh # node packages installation -./prepare-nodejspkg.sh +# ./prepare-nodejspkg.sh # prepare rails server rm -f tmp/pids/server.pid diff --git a/run-js-dev.sh b/run-js-dev.sh index a7d4005bf7..e38605f8c1 100755 --- a/run-js-dev.sh +++ b/run-js-dev.sh @@ -1,14 +1,19 @@ #!/bin/bash -if command -v yarn; then - echo '>>> yarn is installed -> continue' + +# if NODE_PATH is set, add --modules-folder option to .yarnrc and create a symlink to the node_modules folder +if [ -z "$NODE_PATH" ]; then + echo ">>> NODE_PATH is not set" else - echo '>>> Missing yarn. Installing...' - npm install -g yarn + echo ">>> NODE_PATH is set to $NODE_PATH" +# echo ">>> Adding --modules-folder option to .yarnrc" +# echo -e "--modules-folder $NODE_PATH" > .yarnrc +# create a symlink unless it already exists + [ -L "${HOME}/app/node_modules" ] || ln -s "${NODE_PATH}/" "${HOME}/app/node_modules" fi -echo '>>> Installing JS packages...' -yarn install + +./prepare-nodejspkg.sh echo "==========================================================================================================" echo "THIS WILL FAIL UNTIL THE RUBY GEMS ARE INSTALLED BY run-ruby-dev.sh. JUST TRY AGAIN AFTER INSTALLING THEM."