Skip to content

Commit

Permalink
docker build in tmp dir
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanklut committed Jul 12, 2024
1 parent 89fd1b0 commit e3ac547
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 233 deletions.
41 changes: 8 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,6 @@ If not already installed, install the Docker Engine ([install instructions][dock
Laypa now has a release on dockerhub. Using the docker of `loghi/docker.laypa`, should pull the corresponding laypa docker directly from docker hub. If this fails from some reason it can be pulled manually from [here][dockerhub_link]. If it is outdated or requires differences to the source code, please try the [Manual Installation](#manual-installation).

#### Manual Installation
Copy the docker install scripts and Dockerfile(s) to a temporary directory. This is necessary due to the script having to copy the directory it is in. This is not allowed and thus a different external directory is used as build context.

```sh
# Or other location for a temporary directory
tmpdir=$(mktemp -d)
cp -r docker $tmpdir
cd $tmpdir/docker
```

Building the docker using the provided script:
```sh
./buildImage.sh <PATH_TO_LAYPA>
Expand All @@ -122,38 +113,22 @@ Or the multistage build with some profiler tools taken out (might be smaller):
./buildImage.multistage.sh <PATH_TO_LAYPA>
```


Or the alternative docker using micromamba (might be more unstable, but builds are faster):
```sh
./buildImage.micromamba.sh <PATH_TO_LAYPA>
```


<details>
<summary> Click for manual docker install instructions </summary>
<summary> Click for manual docker install instructions (not recommended) </summary>

First copy the Laypa directory to the temporary docker directory:
```sh
cp -r <PARENT_DIR>/laypa $tmpdir/docker
tmp_dir=$(mktemp -d)
cp -r -T <PATH_TO_LAYPA> $tmp_dir/laypa
cp Dockerfile $tmp_dir/Dockerfile
cp _entrypoint.sh $tmp_dir/_entrypoint.sh
cp .dockerignore $tmp_dir/.dockerignore
```

Change the working dir to the docker directory:
Then build the docker image using the following command:
```sh
cd $tmpdir/docker
docker build -t loghi/docker.laypa $tmp_dir
```

Checkout to make sure you are not on the development branch:
```sh
cd laypa
git checkout main
cd ..
```

Build the docker using docker build:
```sh
docker build --no-cache . -t loghi/docker.laypa
```

</details>


Expand Down
6 changes: 3 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM condaforge/mambaforge

ENV DEBIAN_FRONTEND noninteractive
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update -y && \
apt-get dist-upgrade -y && \
Expand All @@ -26,8 +26,8 @@ RUN mamba env create -f environment.yml && \
rm -r /opt/conda/envs/laypa/nsight*

# SHELL ["conda", "run", "-n", "laypa", "/bin/bash", "-c"]
ENV PATH /opt/conda/envs/laypa/bin:$PATH
ENV CONDA_DEFAULT_ENV laypa
ENV PATH=/opt/conda/envs/laypa/bin:$PATH
ENV CONDA_DEFAULT_ENV=laypa
ENV ENV_NAME=laypa

# Fix cuda permissions with the docker
Expand Down
51 changes: 0 additions & 51 deletions docker/Dockerfile.micromamba

This file was deleted.

6 changes: 3 additions & 3 deletions docker/Dockerfile.multistage
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM condaforge/mambaforge as builder

ENV DEBIAN_FRONTEND noninteractive
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update -y && \
apt-get dist-upgrade -y && \
Expand All @@ -26,8 +26,8 @@ RUN mamba env create -p /env -f environment.yml && \
rm -r /env/nsight*


ENV PATH /env/bin:$PATH
ENV CONDA_DEFAULT_ENV /env
ENV PATH=/env/bin:$PATH
ENV CONDA_DEFAULT_ENV=/env
ENV ENV_NAME=/env


Expand Down
139 changes: 0 additions & 139 deletions docker/buildImage.micromamba.sh

This file was deleted.

11 changes: 8 additions & 3 deletions docker/buildImage.multistage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,23 @@ echo "Change to directory of script..."
DIR_OF_SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $DIR_OF_SCRIPT

tmp_dir=$(mktemp -d)

echo "Copy files for building docker..."
cp -r -T $LAYPA/ laypa.multistage
cp -r -T $LAYPA/ $tmp_dir/laypa.multistage
cp Dockerfile.multistage $tmp_dir/laypa.multistage/Dockerfile
cp _entrypoint.sh $tmp_dir/_entrypoint.sh
cp .dockerignore $tmp_dir/.dockerignore

cd $tmp_dir
# HACK Fix git linking in submodules
if [[ -f $LAYPA/.git ]]; then
GIT_DIR=$( cd $LAYPA && git rev-parse --git-dir )
rm laypa.multistage/.git && cp -r $GIT_DIR laypa.multistage/.git
sed 's/.*worktree.*/\tworktree = ../' laypa.multistage/.git/config > laypa.multistage/.git/config
fi

# Checkout to make sure you are not on dev branch
cd laypa.multistage
# git checkout main
git rev-parse HEAD > version_info
cd ..

Expand Down
8 changes: 7 additions & 1 deletion docker/buildImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,15 @@ echo "Change to directory of script..."
DIR_OF_SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $DIR_OF_SCRIPT

tmp_dir=$(mktemp -d)

echo "Copy files for building docker..."
cp -r -T $LAYPA/ $tmp_dir/laypa
cp Dockerfile $tmp_dir/Dockerfile
cp _entrypoint.sh $tmp_dir/_entrypoint.sh
cp .dockerignore $tmp_dir/.dockerignore

cp -r -T $LAYPA/ laypa
cd $tmp_dir
# HACK Fix git linking in submodules
if [[ -f $LAYPA/.git ]]; then
GIT_DIR=$( cd $LAYPA && git rev-parse --git-dir )
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies:
- imagesize
- timm
- gunicorn
- openjpeg
- pillow
- shapely
- natsort
Expand Down
1 change: 1 addition & 0 deletions environment_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies:
- imagesize
- timm
- gunicorn
- openjpeg
- pillow
- shapely
- natsort
Expand Down

0 comments on commit e3ac547

Please sign in to comment.