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

Structures Dockerfile based on operation, and simplifies dev environment #3295

Merged
merged 3 commits into from
Nov 6, 2023
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
72 changes: 42 additions & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,50 @@ 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;

# Install common dependencies
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
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 \

# Install Postgres
RUN apt-get update && \
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/*; \
:
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ENV PATH $PATH:/usr/lib/postgresql/$PG_MAJOR/bin

#---------- 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/

Expand All @@ -43,26 +64,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"]
18 changes: 12 additions & 6 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Loading