From ceb3749dabf13ce09e1c2eb6ebefbf19346b4229 Mon Sep 17 00:00:00 2001 From: pavish Date: Mon, 6 Nov 2023 18:19:16 +0530 Subject: [PATCH 1/3] Structure dockerfile contents based on operation, add gettext to dependencies, remove dockerize --- Dockerfile | 68 +++++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0157d41368..bbc15c2175 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,29 +6,44 @@ ENV NODE_MAJOR 18 ARG BUILD_PG_MAJOR=15 ENV PG_MAJOR=$BUILD_PG_MAJOR -# Install dependencies -RUN apt-get update -RUN apt-get install -y sudo ca-certificates curl gnupg -RUN set -eux; \ - apt-get update; apt-get install -y --no-install-recommends locales; rm -rf /var/lib/apt/lists/*; \ - localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 - -# Install PostgreSQL +RUN set -eux; + +#---------- 1. INSTALL SYSTEM DEPENDENCIES -----------------------------------# + +RUN mkdir -p /etc/apt/keyrings; + +# Add Postgres source +RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - ; \ + echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list; + +# Add Node.js source +RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg; \ + echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list; + +RUN apt-get update -y; + +# Install common dependencies +RUN apt-get install -y --no-install-recommends sudo ca-certificates curl gnupg gettext nodejs locales; + +# Define Locale +RUN localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 ENV LANG en_US.utf8 -RUN set -ex; \ - curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - ; \ - echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list; \ - apt-get update -y; \ - apt-get install -y --no-install-recommends \ - postgresql-$PG_MAJOR postgresql-client-$PG_MAJOR postgresql-contrib-$PG_MAJOR \ - ; \ - apt-get clean; \ - rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*; \ - : -ENV PATH $PATH:/usr/lib/postgresql/$PG_MAJOR/bin +# Install Postgres +RUN apt-get install -y --no-install-recommends \ + postgresql-$PG_MAJOR postgresql-client-$PG_MAJOR postgresql-contrib-$PG_MAJOR; +RUN apt-get clean; \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*; + + +#---------- 2. CONFIGURE SYSTEM DEPENDENCIES ---------------------------------# + +# Postgres + +ENV PATH $PATH:/usr/lib/postgresql/$PG_MAJOR/bin ENV PGDATA /var/lib/postgresql/mathesar + VOLUME /etc/postgresql/ VOLUME /var/lib/postgresql/ @@ -43,26 +58,17 @@ STOPSIGNAL SIGINT EXPOSE 5432 -# Install dockerize, we still need it when running Postgres using docker-compose -RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ - && tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ - && rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz -# Install Node -RUN mkdir -p /etc/apt/keyrings -RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg -RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list -RUN apt-get update -RUN apt-get install nodejs -y +#---------- 3. SETUP MATHESAR ------------------------------------------------# -# Change work directory WORKDIR /code/ -# Copy all the requirements COPY requirements* ./ RUN pip install --no-cache-dir -r ${PYTHON_REQUIREMENTS} --force-reinstall sqlalchemy-filters COPY . . RUN cd mathesar_ui && npm ci && npm run build + EXPOSE 8000 3000 6006 + ENTRYPOINT ["./run.sh"] \ No newline at end of file From d8b13721f2c9dbdc53f3b2917e2e299ab56ea99f Mon Sep 17 00:00:00 2001 From: pavish Date: Mon, 6 Nov 2023 18:21:30 +0530 Subject: [PATCH 2/3] Remove inheritance between dev-service and service --- docker-compose.dev.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 12ed83d262..3a79decc16 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -22,6 +22,12 @@ services: volumes: - dev_postgres_data:/var/lib/postgresql/data - ./db/sql:/sql/ + healthcheck: + test: [ "CMD-SHELL", "pg_isready -d $${POSTGRES_DB-mathesar_django} -U $${POSTGRES_USER-mathesar}"] + interval: 5s + timeout: 1s + retries: 30 + start_period: 5s test-service: extends: file: docker-compose.yml @@ -52,23 +58,23 @@ services: dockerfile: Dockerfile args: PYTHON_REQUIREMENTS: requirements-dev.txt - extends: - file: docker-compose.yml - service: service environment: - MODE=${MODE-DEVELOPMENT} - DEBUG=${DEBUG-True} - DJANGO_ALLOW_ASYNC_UNSAFE=true - - DJANGO_SUPERUSER_PASSWORD=password - DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE-config.settings.development} + - ALLOWED_HOSTS=${ALLOWED_HOSTS-*} + - SECRET_KEY=${SECRET_KEY} - DJANGO_DATABASE_URL=postgres://mathesar:mathesar@mathesar_dev_db:5432/mathesar_django - MATHESAR_DATABASES=(mathesar_tables|postgresql://mathesar:mathesar@mathesar_dev_db:5432/mathesar) - entrypoint: dockerize -wait tcp://mathesar_dev_db:5432 -timeout 30s ./dev-run.sh + - DJANGO_SUPERUSER_PASSWORD=password + entrypoint: ./dev-run.sh volumes: - .:/code/ - ui_node_modules:/code/mathesar_ui/node_modules/ depends_on: - - dev-db + dev-db: + condition: service_healthy # On dev, following ports are exposed to other containers, and the host. ports: - "8000:8000" From f8011db570393363955bf29c4e19e31471eaa2c4 Mon Sep 17 00:00:00 2001 From: pavish Date: Mon, 6 Nov 2023 22:00:39 +0530 Subject: [PATCH 3/3] Combine apt-get update and install in the same RUN command --- Dockerfile | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index bbc15c2175..7a3fdb20c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,21 +20,27 @@ RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - ; \ RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg; \ echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list; -RUN apt-get update -y; - # Install common dependencies -RUN apt-get install -y --no-install-recommends sudo ca-certificates curl gnupg gettext nodejs locales; +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + sudo \ + ca-certificates \ + curl \ + gnupg \ + gettext \ + nodejs \ + locales \ + && rm -rf /var/lib/apt/lists/* # Define Locale RUN localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 ENV LANG en_US.utf8 # Install Postgres -RUN apt-get install -y --no-install-recommends \ - postgresql-$PG_MAJOR postgresql-client-$PG_MAJOR postgresql-contrib-$PG_MAJOR; - -RUN apt-get clean; \ - rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*; +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + postgresql-$PG_MAJOR postgresql-client-$PG_MAJOR postgresql-contrib-$PG_MAJOR \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* #---------- 2. CONFIGURE SYSTEM DEPENDENCIES ---------------------------------#