preserve docker build cache on orchestra musician

produce docker build speedup

- git checkout produce docker cache invalidation, do it when needed
- use /opt/app PATH for the two containers
- use two different layers: one to do the pip requirements, the other
  for the rest of the sourcecode
This commit is contained in:
pedro 2024-01-24 01:05:37 +01:00
parent b5359d77b0
commit 78a79e69e9
3 changed files with 27 additions and 18 deletions

View File

@ -8,14 +8,16 @@ RUN apt update && apt-get install -y \
python3-dev \ python3-dev \
python-is-python3 python-is-python3
WORKDIR /home WORKDIR /opt/musician
RUN python3 -m pip install --upgrade pip RUN python3 -m pip install --upgrade pip
RUN pip install wheel RUN pip install wheel
COPY django-musician . COPY django-musician/requirements.txt .
RUN pip install -r requirements.txt RUN pip install -r requirements.txt
COPY django-musician .
COPY docker/musician.entrypoint.sh . COPY docker/musician.entrypoint.sh .
ENTRYPOINT sh ./musician.entrypoint.sh ENTRYPOINT sh ./musician.entrypoint.sh

View File

@ -3,12 +3,12 @@ FROM debian:bullseye-slim
# based on https://github.com/glic3rinu/django-orchestra/blob/master/INSTALL.md # based on https://github.com/glic3rinu/django-orchestra/blob/master/INSTALL.md
# HOW TO RUN THIS # HOW TO RUN THIS
# #
# 0. rsync -avhP root@109.69.8.140:/home/orchestra orchestra # 0. rsync -avhP root@109.69.8.140:/opt/orchestra orchestra
# 1. copy this Dockerfile into a dir containing orchestra, like: # 1. copy this Dockerfile into a dir containing orchestra, like:
# $ ls # $ ls
# Dockerfile orchestra # Dockerfile orchestra
# 2. docker build -f orchestra . # 2. docker build -f orchestra .
# 3. docker rm orchestra; docker run -v /Users/maymerichgubern/orchestra/orchestra/:/home/orchestra -p 8443:443 -p 8080:80 -it --name orchestra orchestra bash # 3. docker rm orchestra; docker run -v /Users/maymerichgubern/orchestra/orchestra/:/opt/orchestra -p 8443:443 -p 8080:80 -it --name orchestra orchestra bash
# 4. sed -i "s/ALLOWED_HOSTS = .*/ALLOWED_HOSTS = ('orchestra.pangea.org', 'localhost')/" panel/settings.py # 4. sed -i "s/ALLOWED_HOSTS = .*/ALLOWED_HOSTS = ('orchestra.pangea.org', 'localhost')/" panel/settings.py
# 5. service postgresql start; service uwsgi start; service nginx start # 5. service postgresql start; service uwsgi start; service nginx start
# 6. goto https://localhost:8443/admin/ # 6. goto https://localhost:8443/admin/
@ -78,31 +78,32 @@ RUN apt clean && rm -rf /var/lib/apt/lists/*
# cracklib \ # cracklib \
# lxml # lxml
# this is to ensure django project is created on top of this working directory
WORKDIR /opt/orchestra/
# TODO maybe from here goes to docker entrypoint? # TODO maybe from here goes to docker entrypoint?
# TODO assumes that the project already exists, and in some cases that would be interesting # TODO assumes that the project already exists, and in some cases that would be interesting
#COPY django-orchestra /home/orchestra COPY django-orchestra/requirements.txt .
COPY django-orchestra /home/orchestra
# this is to ensure django project is created on top of this working directory
WORKDIR /home/orchestra/
# TODO fix this better in the repo itself # TODO fix this better in the repo itself
RUN pip3 install -r requirements.txt RUN pip3 install -r requirements.txt
RUN pip3 install lxml==4.9.3 RUN pip3 install lxml==4.9.3
COPY django-orchestra .
#RUN sed -i 's/lxml==3.3.5/lxml==4.9.3/' requirements.txt #RUN sed -i 's/lxml==3.3.5/lxml==4.9.3/' requirements.txt
# solves "No module named 'orchestra'" # solves "No module named 'orchestra'"
RUN pip install -e . RUN pip install -e .
RUN django-admin startproject panel --template=/home/orchestra/orchestra/conf/project_template/ RUN django-admin startproject panel --template=/opt/orchestra/orchestra/conf/project_template/
RUN adduser orchestra \ RUN adduser orchestra \
&& sudo adduser orchestra sudo \ && sudo adduser orchestra sudo \
&& su - orchestra && su - orchestra
ENV PATH=$PATH:/home/orchestra/django-orchestra/orchestra/bin ENV PATH=$PATH:/opt/orchestra/django-orchestra/orchestra/bin
WORKDIR /home/orchestra/panel WORKDIR /opt/orchestra/panel
COPY docker/orchestra.migrate.exp /home/orchestra/panel COPY docker/orchestra.migrate.exp /opt/orchestra/panel
COPY docker/orchestra.entrypoint.sh . COPY docker/orchestra.entrypoint.sh .
ENTRYPOINT sh ./orchestra.entrypoint.sh ENTRYPOINT sh ./orchestra.entrypoint.sh
@ -114,10 +115,10 @@ ENTRYPOINT sh ./orchestra.entrypoint.sh
# CMD ./manage.py runserver 0.0.0.0:9080 # CMD ./manage.py runserver 0.0.0.0:9080
# EXPOSE 9080:9080 # EXPOSE 9080:9080
#RUN echo /home/orchestra/django-orchestra/ > /usr/local/lib/python3.9/dist-packages/orchestra.pth #RUN echo /opt/orchestra/django-orchestra/ > /usr/local/lib/python3.9/dist-packages/orchestra.pth
# TODO move this to entrypoint, with fakedata # TODO move this to entrypoint, with fakedata
# && su postgres bash -c 'psql -f <(zcat /home/orchestra/orchestra_db_20230907.sql)' \ # && su postgres bash -c 'psql -f <(zcat /opt/orchestra/orchestra_db_20230907.sql)' \
#RUN service postgresql start \ #RUN service postgresql start \
# && python3 manage.py setupnginx --user orchestra \ # && python3 manage.py setupnginx --user orchestra \

View File

@ -8,22 +8,28 @@ set -x
# clone or pull git repo # clone or pull git repo
_pull() { _pull() {
myurl="${1}" myurl="${1}"
expected_branch="${2}"
mydir_raw="$(basename "${myurl}")" mydir_raw="$(basename "${myurl}")"
mydir="${mydir_raw%.git}" mydir="${mydir_raw%.git}"
mybranch="${2}"
if [ -d "${mydir}" ]; then if [ -d "${mydir}" ]; then
cd "${mydir}" cd "${mydir}"
git checkout "${mybranch}" current_branch="$(git branch --show-current)"
# ensure we are in the right branch without invalidating docker build cache
# yes, even without no branch switch and no new commits
if [ ! "${current_branch}" = "${expected_branch}" ]; then
git checkout "${expected_branch}"
fi
git pull git pull
cd - cd -
else else
git clone -b "${mybranch}" "${myurl}" "${mydir}" git clone -b "${expected_branch}" "${myurl}" "${mydir}"
fi fi
} }
main() { main() {
figlet 'pull repositories'
_pull 'https://gitea.pangea.org/pangea/django-orchestra' 'sso' _pull 'https://gitea.pangea.org/pangea/django-orchestra' 'sso'
_pull 'https://gitea.pangea.org/pangea/django-musician' 'sso' _pull 'https://gitea.pangea.org/pangea/django-musician' 'sso'
_pull 'git@gitea.pangea.org:trustchain-oc1-orchestral/IdHub.git' 'main' _pull 'git@gitea.pangea.org:trustchain-oc1-orchestral/IdHub.git' 'main'