Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add wait-for-it to ensure processes start in the correct order #371

Merged
merged 2 commits into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ MAINTAINER Nicholas Long nicholas.long@nrel.gov

RUN ruby -r openstudio -e "require 'openstudio'; puts OpenStudio.openStudioLongVersion"

# Install required libaries
# Install required libaries.
# realpath - needed for wait-for-it
RUN sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 && \
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | \
sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list && \
Expand Down Expand Up @@ -47,6 +48,7 @@ RUN sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 &
libsm-dev \
mongodb-org-tools \
procps \
realpath \
tar \
unzip \
wget \
Expand Down Expand Up @@ -106,34 +108,28 @@ RUN bundle install --jobs=3 --retry=3
ADD /docker/server/ipvs-keepalive.conf /etc/sysctl.d/ipvs-keepalive.conf
RUN sudo sysctl --system

RUN chmod 775 /opt/openstudio/server/log
RUN chmod 666 /opt/openstudio/server/log/*.log

ADD /docker/server/start-server.sh /usr/local/bin/start-server
ADD /docker/server/run-server-tests.sh /usr/local/bin/run-server-tests
ADD /docker/server/memfix-controller.rb /usr/local/lib/memfix-controller.rb
ADD /docker/server/memfix.rb /usr/local/lib/memfix.rb
# Add in scripts for running server. This includes the wait-for-it scripts to ensure other processes (mongo, redis) have
# started before starting the main process.
COPY /docker/server/wait-for-it.sh /usr/local/bin/wait-for-it
COPY /docker/server/start-server.sh /usr/local/bin/start-server
COPY /docker/server/run-server-tests.sh /usr/local/bin/run-server-tests
COPY /docker/server/rails-entrypoint.sh /usr/local/bin/rails-entrypoint
COPY /docker/server/start-web-background.sh /usr/local/bin/start-web-background
COPY /docker/server/start-workers.sh /usr/local/bin/start-workers
COPY /docker/server/memfix-controller.rb /usr/local/lib/memfix-controller.rb
COPY /docker/server/memfix.rb /usr/local/lib/memfix.rb
RUN chmod 755 /usr/local/bin/wait-for-it
RUN chmod +x /usr/local/bin/start-server
RUN chmod +x /usr/local/bin/run-server-tests
RUN chmod 755 /usr/local/bin/rails-entrypoint
RUN chmod 755 /usr/local/bin/start-web-background
RUN chmod 755 /usr/local/bin/start-workers
RUN chmod +x /usr/local/lib/memfix-controller.rb
RUN chmod +x /usr/local/lib/memfix.rb

# set the permissions for windows users
RUN chmod +x /opt/openstudio/server/bin/*

# permissions on where server assets (e.g. paperclip, data points, R images, etc) are stored
RUN mkdir -p /mnt/openstudio/server/R && chmod 777 /mnt/openstudio/server/R
RUN mkdir -p /mnt/openstudio/server/assets && chmod 777 /mnt/openstudio/server/assets
#RUN mkdir -p /mnt/openstudio/server/assets/data_points && chmod 777 /mnt/openstudio/server/assets/data_points
RUN mkdir -p /mnt/openstudio/server/assets/variables && chmod 777 /mnt/openstudio/server/assets/variables
RUN mkdir -p /opt/openstudio/server/tmp && chmod 777 /opt/openstudio/server/tmp

# Test adding the git repo to the container for coveralls
# The #TEST# will be removed in the travis test script to be run in the test container
#TEST#ADD .git /opt/openstudio/.git

ADD /docker/server/rails-entrypoint.sh /usr/local/bin/rails-entrypoint
RUN chmod 755 /usr/local/bin/rails-entrypoint
ENTRYPOINT ["rails-entrypoint"]

CMD ["/usr/local/bin/start-server"]
Expand Down Expand Up @@ -162,3 +158,6 @@ RUN echo "Running in testing environment - Installing Firefox and Gecko Driver"
rm geckodriver-$GECKODRIVER_VERSION-linux64.tar.gz && \
chmod +x geckodriver;

# Test adding the git repo to the container for coveralls
# The #TEST# will be removed in the travis test script to be run in the test container
#TEST#COPY .git /opt/openstudio/.git
5 changes: 3 additions & 2 deletions docker-compose.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ services:
resources:
reservations:
cpus: "1"
command: /usr/local/bin/start-server
web-background:
image: nrel/openstudio-server:latest
environment:
- OS_SERVER_NUMBER_OF_WORKERS=${OS_SERVER_NUMBER_OF_WORKERS}
- QUEUES=background,analyses
volumes:
- osdata:/mnt/openstudio
command: bundle exec rake environment resque:work
depends_on:
- db
- queue
Expand All @@ -54,9 +54,9 @@ services:
resources:
reservations:
cpus: "1"
command: /usr/local/bin/start-web-background
worker:
image: nrel/openstudio-server:latest
command: bundle exec rake environment resque:workers
environment:
- QUEUES=simulations
- COUNT=1
Expand All @@ -71,6 +71,7 @@ services:
resources:
reservations:
cpus: "0.99"
command: /usr/local/bin/start-workers
rserve:
image: nrel/openstudio-rserve:latest
volumes:
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ services:
- "8080:80"
volumes:
- osdata:/mnt/openstudio
command: /usr/local/bin/start-server
web-background:
image: 127.0.0.1:5000/openstudio-server
build:
Expand All @@ -44,7 +45,7 @@ services:
- web
volumes:
- osdata:/mnt/openstudio
command: bundle exec rake environment resque:work
command: /usr/local/bin/start-web-background
worker:
image: 127.0.0.1:5000/openstudio-server
build:
Expand All @@ -61,7 +62,7 @@ services:
- db
- queue
- rserve
command: bundle exec rake environment resque:workers
command: /usr/local/bin/start-workers
rserve:
image: 127.0.0.1:5000/openstudio-rserve
build: ./docker/R
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ services:
- "8080:80"
volumes:
- osdata:/mnt/openstudio
command: /usr/local/bin/start-server
web-background:
image: nrel/openstudio-server:latest
build:
Expand All @@ -44,7 +45,7 @@ services:
- web
volumes:
- osdata:/mnt/openstudio
command: bundle exec rake environment resque:work
command: /usr/local/bin/start-web-background
worker:
image: nrel/openstudio-server:latest
build:
Expand All @@ -61,7 +62,7 @@ services:
- db
- queue
- rserve
command: bundle exec rake environment resque:workers
command: /usr/local/bin/start-workers
rserve:
image: nrel/openstudio-rserve:latest
build: ./docker/R
Expand Down
5 changes: 3 additions & 2 deletions docker/deployment/docker-compose.aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ services:
resources:
reservations:
cpus: "AWS_WEB_CORES"
command: /usr/local/bin/start-server
web-background:
image: localhost:5000/openstudio-server
environment:
- OS_SERVER_NUMBER_OF_WORKERS=AWS_OS_SERVER_NUMBER_OF_WORKERS
- QUEUES=background,analyses
volumes:
- osdata:/mnt/openstudio
command: bundle exec rake environment resque:work
depends_on:
- db
- web
Expand All @@ -65,12 +65,12 @@ services:
resources:
reservations:
cpus: "1"
command: /usr/local/bin/start-web-background
worker:
image: localhost:5000/openstudio-server
environment:
- QUEUES=simulations
- COUNT=1
command: bundle exec rake environment resque:workers
volumes:
- /mnt/openstudio
depends_on:
Expand All @@ -83,6 +83,7 @@ services:
resources:
reservations:
cpus: "1"
command: /usr/local/bin/start-workers
rserve:
image: localhost:5000/openstudio-rserve
volumes:
Expand Down
1 change: 1 addition & 0 deletions docker/development/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ services:
volumes:
- osdata:/mnt/openstudio
- ../..:/opt/openstudio/
# TODO: This is not using the wait-for-it script, not sure if we still want this file.
command: ../server/bin/delayed_job -i server --queues=analyses,background run
worker:
build:
Expand Down
7 changes: 5 additions & 2 deletions docker/server/rails-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ mkdir -p /opt/openstudio/server/tmp && chmod 777 /opt/openstudio/server/tmp
mkdir -p /mnt/coredumps/ && chmod 777 /mnt/coredumps/
sleep 1

echo 'Defaulting required variables which are not present'
echo 'Setting permissions on logs'
chmod 775 /opt/openstudio/server/log
chmod 666 /opt/openstudio/server/log/*.log
sleep 1

echo 'Defaulting required variables which are not present'
[ -z "$MAX_REQUESTS" ] && export MAX_REQUESTS=50;
[ -z "$MAX_POOL" ] && export MAX_POOL=16;
sleep 1

echo 'Configuring nginx'
sleep 1
{ rm /opt/nginx/conf/nginx.conf && awk -v MAX_REQUESTS=$MAX_REQUESTS '{gsub("MAX_REQUESTS_SUB", MAX_REQUESTS, $0); print}' > /opt/nginx/conf/nginx.conf; } < /opt/nginx/conf/nginx.conf
{ rm /opt/nginx/conf/nginx.conf && awk -v MAX_POOL=$MAX_POOL '{gsub("MAX_POOL_SUB", MAX_POOL, $0); print}' > /opt/nginx/conf/nginx.conf; } < /opt/nginx/conf/nginx.conf
sleep 1
Expand Down
6 changes: 6 additions & 0 deletions docker/server/run-server-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ do
sleep 1s
done

echo "Waiting for Mongo to start"
/usr/local/bin/wait-for-it --strict db:27017

echo "Waiting for Redis to start"
/usr/local/bin/wait-for-it --strict queue:6379

# Always create new indexes in case the models have changed
cd /opt/openstudio/server && bundle exec rspec; (( exit_status = exit_status || $? ))
cd /opt/openstudio/server && bundle exec rake rubocop:run; (( exit_status = exit_status || $? ))
Expand Down
6 changes: 6 additions & 0 deletions docker/server/start-server-dev.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/usr/bin/env bash

echo "Waiting for Mongo to start"
/usr/local/bin/wait-for-it --strict db:27017

echo "Waiting for Redis to start"
/usr/local/bin/wait-for-it --strict queue:6379

# Always create new indexes in case the models have changed
cd /opt/openstudio/server && bundle exec rake db:mongoid:create_indexes

Expand Down
8 changes: 8 additions & 0 deletions docker/server/start-server.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#!/usr/bin/env bash

echo "Waiting for Mongo to start"
/usr/local/bin/wait-for-it --strict db:27017

echo "Waiting for Redis to start"
/usr/local/bin/wait-for-it --strict queue:6379

# Always create new indexes in case the models have changed
cd /opt/openstudio/server && bundle exec rake db:mongoid:create_indexes

# The memfix-controller seems to have causes some issues with NRCan, need to revisit.
# https://github.com/NREL/OpenStudio-server/issues/348
ruby /usr/local/lib/memfix-controller.rb start

/opt/nginx/sbin/nginx
9 changes: 9 additions & 0 deletions docker/server/start-web-background.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

echo "Waiting for Mongo to start"
/usr/local/bin/wait-for-it --strict db:27017

echo "Waiting for Redis to start"
/usr/local/bin/wait-for-it --strict queue:6379

cd /opt/openstudio/server && bundle exec rake environment resque:work
9 changes: 9 additions & 0 deletions docker/server/start-workers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

echo "Waiting for Mongo to start"
/usr/local/bin/wait-for-it --strict db:27017

echo "Waiting for Redis to start"
/usr/local/bin/wait-for-it --strict queue:6379

cd /opt/openstudio/server && bundle exec rake environment resque:workers
Loading