Skip to content

Commit

Permalink
Optimize docker image build process
Browse files Browse the repository at this point in the history
  - Run affymetrix/agilent tests in parallel
  - Set file permissions to 644 while copying
  - Set directory permissions to 755
  - Exclude unnecessary files vie dockerignore
  • Loading branch information
arkid15r committed Nov 2, 2023
1 parent d95a8e0 commit b8602a9
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 110 deletions.
19 changes: 10 additions & 9 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
.git
*/batch-job-specs
*/test_volume
*/volume
**/.git
**/__pycache__
**/*.pyc
**/batch-job-templates
**/dockerfiles
**/environments
**/test_volume
**/volume
**/volumes_postgres
config/externally_supplied_metadata/metasra/*.tab
config/externally_supplied_metadata/metasra/metasra_keywords.json
config/externally_supplied_metadata/metasra/metasra_translated.json
config/externally_supplied_metadata/metasra/SRAmetadb.sqlite
dr_env
env/
infrastructure/
terraform/
test_volume
volume
volumes_postgres/
infrastructure
2 changes: 1 addition & 1 deletion .github/workflows/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
env:
IMAGES: migrations affymetrix
needs:
- test_affymetrix
- test_base
runs-on: ubuntu-latest-m
steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 2 additions & 1 deletion api/dockerfiles/Dockerfile.api
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN <<EOF
pip install --ignore-installed --no-cache-dir uwsgi
chmod +x /home/user/collect_and_run_uwsgi.sh
mkdir -p /tmp/www/static
mkdir -m 755 -p /tmp/www/static
chown user /tmp/www/static
rm -rf /root/.cache/*
EOF

ENV SYSTEM_VERSION=$SYSTEM_VERSION
Expand Down
19 changes: 13 additions & 6 deletions api/dockerfiles/Dockerfile.api_base
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,24 @@ EOF

WORKDIR /home/user

COPY api/requirements.txt .
COPY --chmod=644 api/requirements.txt .
RUN <<EOF
pip install --upgrade pip
pip install --ignore-installed --no-cache-dir -r requirements.txt
EOF

COPY common/dist/data-refinery-common-* common/
RUN pip install --ignore-installed common/$(ls common -1 | sort --version-sort | tail -1)
COPY --chmod=644 common/dist/data-refinery-common-* common/
RUN <<EOF
pip3 install --ignore-installed --no-cache-dir common/$(ls common -1 | sort --version-sort | tail -1)
rm -r common
EOF

COPY --chmod=644 api/ .
COPY --chmod=644 config/ config/
COPY --chmod=644 setup.cfg .

COPY api/ .
COPY config/ config/
COPY setup.cfg .
RUN <<EOF
find /home/user -type d ! -perm 755 -exec chmod 755 {} \;
EOF

ENTRYPOINT []
10 changes: 7 additions & 3 deletions common/dockerfiles/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ useradd --create-home --home-dir /home/user/ -g user user
chown -R user /home/user/
EOF

ENV R_LIBS=/usr/local/lib/R/site-library
COPY --chmod=644 config/ config/
COPY --chmod=644 setup.cfg .

COPY config/ config/
COPY setup.cfg .
RUN <<EOF
find /home/user -type d ! -perm 755 -exec chmod 755 {} \;
EOF

ENV R_LIBS=/usr/local/lib/R/site-library

ENTRYPOINT []
13 changes: 9 additions & 4 deletions common/dockerfiles/Dockerfile.common_tests
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"]

WORKDIR /home/user

COPY common/R/dependencies/common_tests/renv.lock .
COPY common/R/renv_load.R renv_load_common_tests.R
COPY --chmod=644 common/R/dependencies/common_tests/renv.lock .
COPY --chmod=644 common/R/renv_load.R renv_load_common_tests.R
RUN Rscript renv_load_common_tests.R

COPY common/requirements.txt .
COPY --chmod=644 common/requirements.txt .
RUN pip3 install --ignore-installed --no-cache-dir -r requirements.txt

COPY common/ .
COPY --chmod=644 common/ .

RUN <<EOF
find /home/user -type d ! -perm 755 -exec chmod 755 {} \;
rm -rf /root/.cache/*
EOF

ENV SYSTEM_VERSION=$SYSTEM_VERSION

Expand Down
9 changes: 7 additions & 2 deletions common/dockerfiles/Dockerfile.migrations
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"]

WORKDIR /home/user

COPY common/requirements.txt .
COPY --chmod=644 common/requirements.txt .
RUN pip install --ignore-installed --no-cache-dir -r requirements.txt

COPY common/ .
COPY --chmod=644 common/ .

RUN <<EOF
find /home/user -type d ! -perm 755 -exec chmod 755 {} \;
rm -rf /root/.cache/*
EOF

ENV SYSTEM_VERSION=$SYSTEM_VERSION

Expand Down
20 changes: 14 additions & 6 deletions foreman/dockerfiles/Dockerfile.foreman
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,29 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"]

WORKDIR /home/user

COPY foreman/requirements.txt .
COPY --chmod=644 foreman/requirements.txt .
RUN <<EOF
mkdir -p data/microarray
mkdir -m 755 -p data/microarray
wget -q https://gbnci.cancer.gov/geo/GEOmetadb.sqlite.gz -O data/microarray/GEOmetadb.sqlite.gz
gunzip data/microarray/GEOmetadb.sqlite.gz
chmod 644 data/microarray/GEOmetadb.sqlite
pip3 install --ignore-installed --no-cache-dir -r requirements.txt
EOF

# Get the latest version from the dist directory.
COPY common/dist/data-refinery-common-* common/
RUN pip3 install --ignore-installed --no-cache-dir common/$(ls common -1 | sort --version-sort | tail -1)
COPY --chmod=644 common/dist/data-refinery-common-* common/
RUN <<EOF
pip3 install --ignore-installed --no-cache-dir common/$(ls common -1 | sort --version-sort | tail -1)
rm -r common
EOF

COPY --chmod=644 .boto .boto
COPY --chmod=644 foreman/ .

COPY .boto .boto
COPY foreman/ .
RUN <<EOF
find /home/user -type d ! -perm 755 -exec chmod 755 {} \;
rm -rf /root/.cache/*
EOF

ENV SYSTEM_VERSION=$SYSTEM_VERSION

Expand Down
28 changes: 17 additions & 11 deletions workers/dockerfiles/Dockerfile.affymetrix
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,30 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"]

WORKDIR /home/user

COPY workers/R/dependencies/affymetrix/renv.lock .
COPY common/R/renv_load.R renv_load_affymetrix.R
COPY --chmod=644 workers/R/dependencies/affymetrix/renv.lock .
COPY --chmod=644 common/R/renv_load.R renv_load_affymetrix.R
RUN Rscript renv_load_affymetrix.R

COPY workers/R/dependencies/affymetrix/install_ensg_pkgs.R .
COPY --chmod=644 workers/R/dependencies/affymetrix/install_ensg_pkgs.R .
RUN Rscript install_ensg_pkgs.R

COPY workers/data_refinery_workers/processors/requirements.txt .
COPY --chmod=644 workers/data_refinery_workers/processors/requirements.txt .
RUN pip3 install --ignore-installed --no-cache-dir -r requirements.txt

# Get the latest version from the dist directory.
COPY common/dist/data-refinery-common-* common/
RUN pip3 install --ignore-installed --no-cache-dir common/$(ls common -1 | sort --version-sort | tail -1)

COPY .boto .boto
COPY workers/ .

RUN rm -rf /root/.cache/*
COPY --chmod=644 common/dist/data-refinery-common-* common/
RUN <<EOF
pip3 install --ignore-installed --no-cache-dir common/$(ls common -1 | sort --version-sort | tail -1)
rm -r common
EOF

COPY --chmod=644 .boto .boto
COPY --chmod=644 workers/ .

RUN <<EOF
find /home/user -type d ! -perm 755 -exec chmod 755 {} \;
rm -rf /root/.cache/*
EOF

ENV SYSTEM_VERSION=$SYSTEM_VERSION

Expand Down
28 changes: 17 additions & 11 deletions workers/dockerfiles/Dockerfile.compendia
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ WORKDIR /home/user

ENV R_LIBS=/usr/local/lib/R/site-library

COPY workers/R/dependencies/compendia/renv.lock .
COPY common/R/renv_load.R renv_load_compendia.R
COPY --chmod=644 workers/R/dependencies/compendia/renv.lock .
COPY --chmod=644 common/R/renv_load.R renv_load_compendia.R
RUN Rscript renv_load_compendia.R

COPY workers/data_refinery_workers/requirements/compendia.txt requirements.txt
COPY --chmod=644 workers/data_refinery_workers/requirements/compendia.txt requirements.txt
RUN pip3 install --ignore-installed --no-cache-dir -r requirements.txt

COPY workers/data_refinery_workers/processors/requirements.txt requirements.txt
COPY --chmod=644 workers/data_refinery_workers/processors/requirements.txt requirements.txt
RUN pip3 install --ignore-installed --no-cache-dir -r requirements.txt

# Install phantomjs.
Expand All @@ -87,15 +87,21 @@ rm phantomjs-2.1.1-linux-x86_64.tar.bz2
EOF

# Get the latest version from the dist directory.
COPY common/dist/data-refinery-common-* common/
RUN pip3 install --ignore-installed --no-cache-dir common/$(ls common -1 | sort --version-sort | tail -1)
COPY --chmod=644 common/dist/data-refinery-common-* common/
RUN <<EOF
pip3 install --ignore-installed --no-cache-dir common/$(ls common -1 | sort --version-sort | tail -1)
rm -r common
EOF

COPY .boto .boto
COPY config/ config/
COPY setup.cfg .
COPY workers/ .
COPY --chmod=644 .boto .boto
COPY --chmod=644 config/ config/
COPY --chmod=644 setup.cfg .
COPY --chmod=644 workers/ .

RUN rm -rf /root/.cache/*
RUN <<EOF
find /home/user -type d ! -perm 755 -exec chmod 755 {} \;
rm -rf /root/.cache/*
EOF

ARG SYSTEM_VERSION
ENV SYSTEM_VERSION=$SYSTEM_VERSION
Expand Down
26 changes: 17 additions & 9 deletions workers/dockerfiles/Dockerfile.downloaders
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"]

WORKDIR /home/user

COPY workers/R/dependencies/downloaders/renv.lock .
COPY common/R/renv_load.R renv_load_downloaders.R
COPY --chmod=644 workers/R/dependencies/downloaders/renv.lock .
COPY --chmod=644 common/R/renv_load.R renv_load_downloaders.R
RUN Rscript renv_load_downloaders.R

COPY workers/data_refinery_workers/downloaders/requirements.txt .
COPY --chmod=644 workers/data_refinery_workers/downloaders/requirements.txt .
RUN pip3 install --ignore-installed --no-cache-dir -r requirements.txt

# Install Aspera.
Expand All @@ -23,8 +23,10 @@ EOF

USER user

ENV GNUPG_PATH=/home/user/.gnupg

RUN <<EOF
mkdir -m 700 /home/user/.gnupg
mkdir -m 700 ${GNUPG_PATH}
# Disable IPv6 to avoid "Cannot assign requested address" error.
echo "disable-ipv6" >> /home/user/.gnupg/dirmngr.conf
. /home/user/rvm/scripts/rvm
Expand All @@ -34,13 +36,19 @@ EOF
USER root

# Get the latest version from the dist directory.
COPY common/dist/data-refinery-common-* common/
RUN pip3 install --ignore-installed --no-cache-dir common/$(ls common -1 | sort --version-sort | tail -1)
COPY --chmod=644 common/dist/data-refinery-common-* common/
RUN <<EOF
pip3 install --ignore-installed --no-cache-dir common/$(ls common -1 | sort --version-sort | tail -1)
rm -r common
EOF

COPY .boto .boto
COPY workers/ .
COPY --chmod=644 .boto .boto
COPY --chmod=644 workers/ .

RUN rm -rf /root/.cache/*
RUN <<EOF
rm -rf /root/.cache/*
find /home/user -path ${GNUPG_PATH} -prune -type d ! -perm 755 -exec chmod 755 {} \;
EOF

ENV PATH="$PATH:/home/user/.aspera/sdk"
ENV SYSTEM_VERSION=$SYSTEM_VERSION
Expand Down
30 changes: 18 additions & 12 deletions workers/dockerfiles/Dockerfile.illumina
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"]

WORKDIR /home/user

COPY workers/R/dependencies/illumina/renv.lock .
COPY common/R/renv_load.R renv_load_illumina.R
COPY --chmod=644 workers/R/dependencies/illumina/renv.lock .
COPY --chmod=644 common/R/renv_load.R renv_load_illumina.R
RUN Rscript renv_load_illumina.R

COPY workers/data_refinery_workers/processors/requirements.txt .
COPY --chmod=644 workers/data_refinery_workers/processors/requirements.txt .
RUN pip3 install --ignore-installed --no-cache-dir -r requirements.txt

# Get the latest version from the dist directory.
COPY common/dist/data-refinery-common-* common/
RUN pip3 install --ignore-installed --no-cache-dir common/$(ls common -1 | sort --version-sort | tail -1)

COPY .boto .boto
COPY workers/ .
COPY workers/data_refinery_workers/processors/detect_database.R .
COPY workers/illumina_probe_maps/ probe_maps/

RUN rm -rf /root/.cache/*
COPY --chmod=644 common/dist/data-refinery-common-* common/
RUN <<EOF
pip3 install --ignore-installed --no-cache-dir common/$(ls common -1 | sort --version-sort | tail -1)
rm -r common
EOF

COPY --chmod=644 .boto .boto
COPY --chmod=644 workers/ .
COPY --chmod=644 workers/data_refinery_workers/processors/detect_database.R .
COPY --chmod=644 workers/illumina_probe_maps/ probe_maps/

RUN <<EOF
find /home/user -type d ! -perm 755 -exec chmod 755 {} \;
rm -rf /root/.cache/*
EOF

ENV SYSTEM_VERSION=$SYSTEM_VERSION

Expand Down
Loading

0 comments on commit b8602a9

Please sign in to comment.