diff --git a/tutor/templates/build/forum/Dockerfile b/tutor/templates/build/forum/Dockerfile index 91b612a..b6a6bd0 100644 --- a/tutor/templates/build/forum/Dockerfile +++ b/tutor/templates/build/forum/Dockerfile @@ -7,8 +7,14 @@ RUN apt update && \ apt upgrade -y && \ apt install -y git wget autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm-dev +# Install dockerize to wait for mongodb/elasticsearch availability +ARG DOCKERIZE_VERSION=v0.6.1 +RUN wget -O /tmp/dockerize.tar.gz https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ + && tar -C /usr/local/bin -xzvf /tmp/dockerize.tar.gz \ + && rm /tmp/dockerize.tar.gz + # Install ruby-build for building specific version of ruby -RUN git clone https://github.com/sstephenson/ruby-build.git /openedx/ruby-build +RUN git clone https://github.com/rbenv/ruby-build.git /openedx/ruby-build WORKDIR /openedx/ruby-build RUN PREFIX=/usr/local ./install.sh @@ -28,10 +34,17 @@ RUN git clone https://github.com/edx/cs_comments_service.git --branch open-relea WORKDIR /openedx/cs_comments_service RUN bundle install --deployment +COPY ./bin /openedx/bin +ENV PATH /openedx/bin:${PATH} +ENTRYPOINT ["docker-entrypoint.sh"] + ENV RACK_ENV staging ENV NEW_RELIC_ENABLE false ENV API_KEY forumapikey ENV SEARCH_SERVER "http://elasticsearch:9200" -ENV MONGOHQ_URL "mongodb://mongodb/cs_comments_service" +ENV MONGODB_AUTH "" +ENV MONGODB_HOST "mongodb" +ENV MONGODB_PORT "27017" +ENV MONGOHQ_URL "mongodb://$MONGODB_AUTH$MONGODB_HOST:$MONGODB_PORT/cs_comments_service" EXPOSE 4567 CMD ./bin/unicorn -c config/unicorn_tcp.rb -I '.' diff --git a/tutor/templates/build/forum/bin/docker-entrypoint.sh b/tutor/templates/build/forum/bin/docker-entrypoint.sh new file mode 100755 index 0000000..de18574 --- /dev/null +++ b/tutor/templates/build/forum/bin/docker-entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/sh -e + +echo "Waiting for mongodb/elasticsearch..." +dockerize -wait tcp://$MONGODB_HOST:$MONGODB_PORT -wait $SEARCH_SERVER/content -wait-retry-interval 5s -timeout 600s + +exec "$@" diff --git a/tutor/templates/k8s/deployments.yml b/tutor/templates/k8s/deployments.yml index 03e27af..64fb4ce 100644 --- a/tutor/templates/k8s/deployments.yml +++ b/tutor/templates/k8s/deployments.yml @@ -69,8 +69,12 @@ spec: env: - name: SEARCH_SERVER value: "http://{{ ELASTICSEARCH_HOST }}:{{ ELASTICSEARCH_PORT }}" - - name: MONGOHQ_URL - value: "mongodb://{% if MONGODB_USERNAME and MONGODB_PASSWORD %}{{ MONGODB_USERNAME}}:{{ MONGODB_PASSWORD }}@{% endif %}{{ MONGODB_HOST }}:{{ MONGODB_PORT }}/cs_comments_service" + - name: MONGODB_AUTH + value: "{% if MONGODB_USERNAME and MONGODB_PASSWORD %}{{ MONGODB_USERNAME}}:{{ MONGODB_PASSWORD }}@{% endif %}" + - name: MONGODB_HOST + value: "{{ MONGODB_HOST }}" + - name: MONGODB_PORT + value: "{{ MONGODB_PORT }}" {% endif %} --- apiVersion: apps/v1 diff --git a/tutor/templates/local/docker-compose.yml b/tutor/templates/local/docker-compose.yml index 1186376..817a491 100644 --- a/tutor/templates/local/docker-compose.yml +++ b/tutor/templates/local/docker-compose.yml @@ -95,7 +95,9 @@ services: image: {{ DOCKER_REGISTRY }}{{ DOCKER_IMAGE_FORUM }} environment: SEARCH_SERVER: "http://{{ ELASTICSEARCH_HOST }}:{{ ELASTICSEARCH_PORT }}" - MONGOHQ_URL: "mongodb://{% if MONGODB_USERNAME and MONGODB_PASSWORD %}{{ MONGODB_USERNAME}}:{{ MONGODB_PASSWORD }}@{% endif %}{{ MONGODB_HOST }}:{{ MONGODB_PORT }}/cs_comments_service" + MONGODB_AUTH: "{% if MONGODB_USERNAME and MONGODB_PASSWORD %}{{ MONGODB_USERNAME}}:{{ MONGODB_PASSWORD }}@{% endif %}" + MONGODB_HOST: "{{ MONGODB_HOST }}" + MONGODB_PORT: "{{ MONGODB_PORT }}" restart: unless-stopped depends_on: {% if ACTIVATE_ELASTICSEARCH %}- elasticsearch{% endif %}