Skip to content

Commit

Permalink
feat: getting rid of dockerize
Browse files Browse the repository at this point in the history
  getting rid of dockerize might resolve #33 and provide other
  solution for #35

  dockerize is used for waiting for other services, in order
  replicate it's effect, we set `MONGOID_TIMEOUT` 600 second
  for mongodb, related upstream PR:
  - openedx/cs_comments_service/pull/432
  • Loading branch information
ghassanmas committed Oct 14, 2024
1 parent 58f1cb2 commit 905565a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Improvement] get rid of of `dockerize`. (by @ghassanmas)
26 changes: 25 additions & 1 deletion tutorforum/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@

FORUM_ENV_BASE: dict[str, str] = {
"SEARCH_SERVER": "{{ ELASTICSEARCH_SCHEME }}://{{ ELASTICSEARCH_HOST }}:{{ ELASTICSEARCH_PORT }}",
"MONGODB_AUTH": "{% if MONGODB_USERNAME and MONGODB_PASSWORD %}{{ MONGODB_USERNAME}}:{{ MONGODB_PASSWORD }}@{% endif %}",
"MONGODB_AUTH": "{{ get_mongo_auth(MONGODB_USERNAME, MONGODB_PASSWORD) }}",
"MONGODB_HOST": "{{ MONGODB_HOST|forum_mongodb_host }}",
"MONGODB_PORT": "{{ MONGODB_PORT }}",
"MONGODB_DATABASE": "{{ FORUM_MONGODB_DATABASE }}",
"MONGOID_AUTH_SOURCE": "{{ MONGODB_AUTH_SOURCE }}",
"MONGOID_AUTH_MECH": "{{ MONGODB_AUTH_MECHANISM|auth_mech_as_ruby }}",
"MONGOID_USE_SSL": "{{ 'true' if MONGODB_USE_SSL else 'false' }}",
"MONGOHQ_URL": "{{ get_mongohq_url(MONGODB_HOST, MONGODB_PORT,MONGODB_DATABASE, get_mongo_auth(MONGODB_USERNAME, MONGODB_PASSWORD)) }}",
}

with open(
Expand Down Expand Up @@ -69,6 +70,29 @@
)


def get_mongohq_url(
mongo_host: str, mongo_port: str, mongo_database: str, mongo_auth: str
) -> str:
"""
Used to return mongo, to handle the special case when mongodb+srv used
For more info look at the following PR https://github.com/overhangio/tutor-forum/pull/10
"""
if "mongodb+srv" in mongo_host:
return f"{mongo_host}/{mongo_database}"
return f"mongodb://{mongo_auth}{mongo_host}:{mongo_port}/{mongo_database}"


def get_mongo_auth(monogo_username: str, mongo_password: str) -> str:
if monogo_username and mongo_password:
return f"{monogo_username}:{mongo_password}@"
return ""


tutor_hooks.Filters.ENV_TEMPLATE_VARIABLES.add_items(
[("get_mongohq_url", get_mongohq_url), ("get_mongo_auth", get_mongo_auth)]
)


# Bind-mount repo at runtime
@tutor_hooks.Filters.COMPOSE_MOUNTS.add()
def _mount_cs_comments_service(
Expand Down
14 changes: 4 additions & 10 deletions tutorforum/templates/forum/build/forum/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ RUN apt update && \
apt upgrade -y && \
apt install -y wget curl autoconf bison build-essential libffi-dev libgdbm-dev libncurses5-dev libssl-dev libyaml-dev libreadline6-dev zlib1g-dev git

# Install dockerize to wait for mongodb/elasticsearch availability
# https://hub.docker.com/r/powerman/dockerize/tags
COPY --from=docker.io/powerman/dockerize:0.19.0 /usr/local/bin/dockerize /usr/local/bin/dockerize

# Create unprivileged "app" user
# From then on, run as unprivileged app user
RUN useradd --home-dir /app --create-home --shell /bin/bash --uid 1000 app
Expand Down Expand Up @@ -42,18 +38,16 @@ WORKDIR /app/cs_comments_service
RUN bundle config set --local deployment 'true'
RUN bundle install

# Copy entrypoint
COPY --chown=app:app ./bin/docker-entrypoint.sh /app/bin/docker-entrypoint.sh
RUN chmod a+x /app/bin/docker-entrypoint.sh
ENTRYPOINT ["/app/bin/docker-entrypoint.sh"]

ENV SINATRA_ENV=staging
ENV NEW_RELIC_ENABLE=false
ENV API_KEY=forumapikey
ENV SEARCH_SERVER=http://elasticsearch:9200
ENV SEARCH_SERVER_ES7=http://elasticsearch:9200
ENV MONGODB_AUTH=""
ENV MONGODB_HOST=mongodb
ENV MONGODB_PORT=27017
ENV MONGODB_DATABASE=cs_comments_service
# Duplicating the function of dockerize
ENV MONGOID_CONNECT_TIMEOUT=600

EXPOSE 4567
CMD ./bin/unicorn -c config/unicorn_tcp.rb -I '.'
19 changes: 0 additions & 19 deletions tutorforum/templates/forum/build/forum/bin/docker-entrypoint.sh

This file was deleted.

0 comments on commit 905565a

Please sign in to comment.