Skip to content

Commit

Permalink
Updates docker configuration for disco
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongundel committed Nov 13, 2024
1 parent 805fd6b commit 7a0758f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 160 deletions.
86 changes: 11 additions & 75 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,102 +1,38 @@
FROM --platform=linux/amd64 ubuntu:22.04 as stage-amd64
USER root
RUN apt-get update
RUN apt-get install -y unzip less vim curl && curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install
FROM public.ecr.aws/l1p7h1f9/archesproject-fargeo:7.6.x-base-dev

FROM --platform=linux/arm64 ubuntu:22.04 as stage-arm64
USER root
RUN apt-get update
RUN apt-get install -y unzip less vim curl && curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install
RUN apt-get update

# Declare TARGETARCH to make it available
ARG TARGETARCH
# Select final stage based on TARGETARCH ARG
FROM stage-${TARGETARCH} as final

ARG ARCHES_FOR_SCIENCE_HOST_DIR
ARG ARCHES_CORE_HOST_DIR
ARG ARCHES_TEMPLATING_HOST_DIR

## Setting default environment variables
ENV WEB_ROOT=/web_root
ENV APP_ROOT=${WEB_ROOT}/disco
# Root project folder
ENV ARCHES_ROOT=${WEB_ROOT}/arches
ENV AFS_ROOT=${WEB_ROOT}/arches-for-science
ENV TEMPLATING_ROOT=${WEB_ROOT}/arches-templating
ENV PYTHONUNBUFFERED=1
ENV NODE_MAJOR=18

RUN apt-get update && apt-get install -y make software-properties-common && apt-get install -y ca-certificates gnupg && 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 && apt-get update
# Get the pre-built python wheels from the build environment
RUN mkdir ${WEB_ROOT}

# Install packages required to run Arches
# Note that the ubuntu/debian package for libgdal1-dev pulls in libgdal1i, which is built
# with everything enabled, and so, it has a huge amount of dependancies (everything that GDAL
# support, directly and indirectly pulling in mysql-common, odbc, jp2, perl! ... )
# a minimised build of GDAL could remove several hundred MB from the container layer.
RUN set -ex \
&& RUN_DEPS=" \
build-essential \
python3.10-dev \
mime-support \
libgdal-dev \
python3-venv \
postgresql-client-14 \
python3.10 \
python3.10-distutils \
python3.10-venv \
dos2unix \
git \
" \
&& apt-get install -y --no-install-recommends curl \
&& curl -sL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -sc)-pgdg main" \
&& apt-get update -y \
&& apt-get install -y --no-install-recommends $RUN_DEPS

RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python3 get-pip.py \
&& pip install setuptools \
&& apt-get install nodejs -y \
&& npm install -g yarn
#ENV ARCHES_TEMPLATING_ROOT=${WEB_ROOT}/arches-templating

WORKDIR ${WEB_ROOT}

RUN rm -rf /root/.cache/pip/*

# Install the Arches application
# FIXME: ADD from github repository instead?
COPY ${ARCHES_CORE_HOST_DIR} ${ARCHES_ROOT}
COPY ${ARCHES_FOR_SCIENCE_HOST_DIR} ${AFS_ROOT}
COPY ${ARCHES_TEMPLATING_HOST_DIR} ${TEMPLATING_ROOT}

WORKDIR ${AFS_ROOT}
RUN pip install -e .
COPY ./arches ${ARCHES_ROOT}
RUN apt update && apt install wait-for-it openssh-client -y

RUN pip uninstall arches -y
COPY ../arches-for-science ${WEB_ROOT}/arches-for-science
COPY ../arches-templating ${WEB_ROOT}/arches-templating
COPY ../disco ${APP_ROOT}

WORKDIR ${TEMPLATING_ROOT}
RUN pip install -e .

# afs app installed _before_ arches core - otherwise afs dependencies will overwrite arches editable install.
WORKDIR ${ARCHES_ROOT}
RUN pip install -e . --user && pip install -r arches/install/requirements.txt && pip install -r arches/install/requirements_dev.txt
RUN source ${WEB_ROOT}/ENV/bin/activate && cd ${APP_ROOT} && pip install -e '.[dev]' && \
cd ${WEB_ROOT}/arches-for-science && pip install -e '.[dev]' && \
cd ${WEB_ROOT}/arches-templating && pip install -e '.[dev]' && \
cd ${ARCHES_ROOT} && pip install -e '.[dev]'

# TODO: These are required for non-dev installs, currently only depends on arches/afs
#COPY /disco/disco/install/requirements.txt requirements.txt
#RUN pip install -r requirements.txt

COPY /disco/docker/entrypoint.sh ${WEB_ROOT}/entrypoint.sh
RUN chmod -R 700 ${WEB_ROOT}/entrypoint.sh &&\
dos2unix ${WEB_ROOT}/entrypoint.sh

RUN mkdir /var/log/supervisor
RUN mkdir /var/log/celery

# Set default workdir
WORKDIR ${APP_ROOT}

Expand Down
77 changes: 31 additions & 46 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#!/bin/bash

# APP and YARN folder locations
# APP and npm folder locations
# ${WEB_ROOT} and ${ARCHES_ROOT} is defined in the Dockerfile, ${ARCHES_PROJECT} in env_file.env
if [[ -z ${ARCHES_PROJECT} ]]; then
APP_FOLDER=${ARCHES_ROOT}
PACKAGE_JSON_FOLDER=${ARCHES_ROOT}
else
APP_FOLDER=${WEB_ROOT}/${ARCHES_PROJECT}
APP_FOLDER=${WEB_ROOT}/${ARCHES_PROJECT_ROOT_DIRECTORY}
PACKAGE_JSON_FOLDER=${ARCHES_ROOT}
fi

YARN_MODULES_FOLDER=${PACKAGE_JSON_FOLDER}/$(awk \
-F '--install.modules-folder' '{print $2}' ${PACKAGE_JSON_FOLDER}/.yarnrc \
| awk '{print $1}' \
| tr -d $'\r' \
| tr -d '"' \
| sed -e "s/^\.\///g")
# npm_MODULES_FOLDER=${PACKAGE_JSON_FOLDER}/$(awk \
# -F '--install.modules-folder' '{print $2}' ${PACKAGE_JSON_FOLDER}/.npmrc \
# | awk '{print $1}' \
# | tr -d $'\r' \
# | tr -d '"' \
# | sed -e "s/^\.\///g")

# Environmental Variables
export DJANGO_PORT=${DJANGO_PORT:-8000}
Expand Down Expand Up @@ -94,14 +94,14 @@ init_arches() {
fi
}

# Yarn
install_yarn_components() {
if [[ ! -d ${YARN_MODULES_FOLDER} ]] || [[ ! "$(ls ${YARN_MODULES_FOLDER})" ]]; then
echo "Yarn modules do not exist, installing..."
cd ${PACKAGE_JSON_FOLDER}
yarn install
fi
}
# npm
# install_npm_components() {
# if [[ ! -d ${npm_MODULES_FOLDER} ]] || [[ ! "$(ls ${npm_MODULES_FOLDER})" ]]; then
# echo "npm modules do not exist, installing..."
# cd ${PACKAGE_JSON_FOLDER}
# npm install
# fi
# }

#### Misc
copy_settings_local() {
Expand All @@ -125,65 +125,53 @@ run_migrations() {
echo "----- RUNNING DATABASE MIGRATIONS -----"
echo ""
cd ${APP_FOLDER}
python3 manage.py migrate
../ENV/bin/python manage.py migrate
}

run_setup_db() {
echo ""
echo "----- RUNNING SETUP_DB -----"
echo ""
cd ${APP_FOLDER}
python3 manage.py setup_db --force
../ENV/bin/python manage.py setup_db --force
}

run_load_package() {
echo ""
echo "----- *** LOADING PACKAGE: ${ARCHES_PROJECT} *** -----"
echo ""
cd ${APP_FOLDER}
python3 manage.py packages -o load_package -a arches_for_science -db -dev -y
../ENV/bin/python manage.py packages -o load_package -s ca_shpo_online/pkg -db -dev -y
}

# "exec" means that it will finish building???
run_django_server() {
echo ""
echo "----- *** RUNNING DJANGO DEVELOPMENT SERVER *** -----"
echo ""
echo ${APP_FOLDER}
cd ${APP_FOLDER}
echo "Running Django"
exec sh -c "pip install debugpy -t /tmp && python3 -Wdefault /tmp/debugpy --listen 0.0.0.0:5678 manage.py runserver 0.0.0.0:${DJANGO_PORT}"
}

run_livereload_server() {
echo ""
echo "----- *** RUNNING LIVERELOAD SERVER *** -----"
echo ""
cd ${APP_FOLDER}
echo "Running livereload"
exec sh -c "python3 manage.py developer livereload --livereloadhost 0.0.0.0"
}

activate_virtualenv() {
. ${WEB_ROOT}/ENV/bin/activate
exec /bin/bash -c "source ../ENV/bin/activate && pip3 install debugpy -t /tmp && python -Wdefault /tmp/debugpy --listen 0.0.0.0:5678 manage.py runserver 0.0.0.0:${DJANGO_PORT}"
}

#### Main commands
run_arches() {
init_arches
install_yarn_components
run_django_server
}

#### Main commands
run_livereload() {
run_livereload_server
run_webpack() {
echo ""
echo "----- *** RUNNING WEBPACK DEVELOPMENT SERVER *** -----"
echo ""
cd ${APP_FOLDER}
# echo "Running Webpack"
#eval `ssh-agent -s` && cat /run/secrets/ssh_passphrase | SSH_ASKPASS=/bin/cat setsid -w ssh-add 2>> /dev/null
exec /bin/bash -c "source ../ENV/bin/activate && cd /web_root/disco && npm i && wait-for-it disco:80 -t 1200 && npm start"
}

### Starting point ###

# trying not to use virtualenv???
# activate_virtualenv

# Use -gt 1 to consume two arguments per pass in the loop
# (e.g. each argument has a corresponding value to go with it).
# Use -gt 0 to consume one or more arguments per pass in the loop
Expand All @@ -210,9 +198,6 @@ do
wait_for_db
run_arches
;;
run_livereload)
run_livereload_server
;;
setup_arches)
start_celery_supervisor
copy_settings_local
Expand All @@ -229,8 +214,8 @@ do
wait_for_db
run_migrations
;;
install_yarn_components)
install_yarn_components
install_npm_components)
install_npm_components
;;
help|-h)
display_help
Expand Down
1 change: 1 addition & 0 deletions docker/env_file.env
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ DJANGO_PORT=80
PYTHONUNBUFFERED=0
TZ=PST
ELASTICSEARCH_PREFIX=$ARCHES_PROJECT
ARCHES_PROJECT_ROOT_DIRECTORY=disco

#rabbitmq
RABBITMQ_USER=guest
Expand Down
50 changes: 13 additions & 37 deletions docker/webpack/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,50 +1,26 @@
FROM ubuntu:22.04 as base
USER root
FROM public.ecr.aws/l1p7h1f9/archesproject-fargeo:7.6.x-base-dev
ENV WEB_ROOT=/web_root
ENV ARCHES_ROOT=${WEB_ROOT}/arches
ENV APP_ROOT=${WEB_ROOT}/disco
ENV AFS_ROOT=${WEB_ROOT}/arches-for-science
ENV NODE_MAJOR=18
RUN mkdir -p ${APP_ROOT}/disco/webpack
ENV NODE_MAJOR=20
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y make software-properties-common && apt-get install -y ca-certificates curl gnupg && 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 && apt-get update
COPY ./arches ${ARCHES_ROOT}
RUN apt update && apt install wait-for-it openssh-client -y

RUN set -ex \
&& apt-get update -y \
&& RUN_DEPS=" \
build-essential \
python3.10-dev \
mime-support \
libgdal-dev \
python3-venv \
python3.10 \
python3.10-distutils \
python3.10-venv \
dos2unix \
git \
" \
&& apt-get install -y --no-install-recommends curl \
&& apt-get install -y --no-install-recommends $RUN_DEPS
COPY ../arches-for-science ${WEB_ROOT}/arches-for-science
COPY ../arches-templating ${WEB_ROOT}/arches-templating

RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python3 get-pip.py \
&& pip install setuptools
COPY ../disco ${APP_ROOT}

COPY ./arches ${ARCHES_ROOT}
COPY ../arches-for-science ${AFS_ROOT}
RUN apt-get update && apt-get -y install curl \
&& apt-get install nodejs && npm install -g yarn && apt install wait-for-it
RUN source ${WEB_ROOT}/ENV/bin/activate && cd ${APP_ROOT} && pip install -e '.[dev]' && \
cd ${WEB_ROOT}/arches-for-science && pip install -e '.[dev]' && \
cd ${ARCHES_ROOT} && pip install -e '.[dev]'

WORKDIR ${AFS_ROOT}
RUN pip show setuptools && pip --version && pip install -e . && pip uninstall arches -y

WORKDIR ${ARCHES_ROOT}
RUN pip install -e . --user
RUN pip install -r arches/install/requirements.txt
RUN pip install -r arches/install/requirements_dev.txt
RUN mkdir /root/.ssh/

COPY /disco/docker/webpack/entrypoint.sh ${WEB_ROOT}/entrypoint.sh
COPY /disco/docker/entrypoint.sh ${WEB_ROOT}/entrypoint.sh
RUN chmod -R 700 ${WEB_ROOT}/entrypoint.sh
WORKDIR ${WEB_ROOT}
ENTRYPOINT [ "./entrypoint.sh" ]
Expand Down
2 changes: 1 addition & 1 deletion docker/webpack/env_file.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

NODE_OPTIONS=--max-old-space-size=10000
ARCHES_PROJECT=disco

ARCHES_PROJECT_ROOT_DIRECTORY=disco
#arches
INSTALL_DEFAULT_GRAPHS=False
INSTALL_DEFAULT_CONCEPTS=False
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7a0758f

Please sign in to comment.