Skip to content

Commit

Permalink
Merge pull request #3 from bacpop/docker
Browse files Browse the repository at this point in the history
Docker
  • Loading branch information
samhorsfield96 committed Apr 3, 2024
2 parents 7d95c24 + 263f0e7 commit 61849b5
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 5 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/docker_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build and push Docker image

on:
push:
branches:
- 'main'
- 'docker'
tags:
- 'v*'
pull_request:
branches:
- 'main'
create:
tags:
- v*

jobs:
docker-upload:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: samhorsfield96/celebrimbor
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v3
with:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: docker/Dockerfile
provenance: false
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ You can also use the light bakta database if using a suitable version of bakta:
bakta_db download --output /path/to/database --type light
```

Install [cgt](https://github.com/bacpop/cgt)
Install [cgt](https://github.com/bacpop/cgt) (will install `cgt_bacpop` executable in `./bin` directory)
```
cargo add cgt_bacpop
cargo install cgt_bacpop --root .
```

Or to build from source:
Expand All @@ -50,6 +50,24 @@ cd cgt
cargo install --path "."
```

### Running inside a container

An alternative, if you are having trouble with the above, is to use the CELEBRIMBOR docker
container. If you are comfortable running commands inside docker containers and mounting
your external files, the whole pipeline is in the container available by running:

```
docker pull samhorsfield96/celebrimbor:main
```

To run within the container, use the below command, replacing `path to output dir` and `path to fasta dir` with absolute paths and changing other parameters as required:

```
docker run -v <path to output dir>:/output -v <path to fasta dir>:/data samhorsfield96/celebrimbor:main snakemake --cores 4 --config genome_fasta=/data output_dir=/output bakta_db=bakta_db/db-light cgt_exe=cgt_bacpop cgt_breaks=0.05,0.95 cgt_error=0.05 clustering_method=panaroo panaroo_stringency=moderate
```

Note: ensure that `clustering_method` and `panaroo_stringency` parameters are not in quotes.

## Quick start:

Update `config.yaml` to specify workflow and directory paths.
Expand Down
6 changes: 3 additions & 3 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ bakta_db: path/to/bakta/db/dir

# cgt executable parameters
cgt_exe: /path/to/cgt/exe
cgt_breaks: 0.1,0.95
cgt_breaks: 0.05,0.95
cgt_error: 0.05

# choice of clustering method, either 'mmseqs2' or 'panaroo'
# choice of clustering method, either "mmseqs2" or "panaroo"
clustering_method: "panaroo"

# must be one of 'strict', 'moderate' or 'sensitive'
# must be one of "strict", "moderate" or "sensitive"
panaroo_stringency: "strict"
3 changes: 3 additions & 0 deletions docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
../test/*
test/*
.git
82 changes: 82 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# From https://github.com/kaust-vislab/python-data-science-project
FROM ubuntu:20.04

LABEL maintainer="Sam Horsfield <[email protected]>"

SHELL [ "/bin/bash", "--login", "-c" ]

RUN apt-get update --fix-missing && \
apt-get install -y wget bzip2 curl git && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Create a non-root user
ARG username=celebrimbor-usr
ARG uid=1000
ARG gid=100
ENV USER $username
ENV UID $uid
ENV GID $gid
ENV HOME /home/$USER

RUN adduser --disabled-password \
--gecos "Non-root user" \
--uid $UID \
--gid $GID \
--home $HOME \
$USER

COPY environment.yml /tmp/
RUN chown $UID:$GID /tmp/environment.yml

COPY docker/entrypoint.sh /usr/local/bin/
RUN chown $UID:$GID /usr/local/bin/entrypoint.sh && \
chmod u+x /usr/local/bin/entrypoint.sh

USER $USER

# install miniconda
ENV MINICONDA_VERSION latest
ENV CONDA_DIR $HOME/miniconda3
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-$MINICONDA_VERSION-Linux-x86_64.sh -O ~/miniconda.sh && \
chmod +x ~/miniconda.sh && \
~/miniconda.sh -b -p $CONDA_DIR && \
rm ~/miniconda.sh

# make non-activate conda commands available
ENV PATH=$CONDA_DIR/bin:$PATH

# make conda activate command available from /bin/bash --login shells
RUN echo ". $CONDA_DIR/etc/profile.d/conda.sh" >> ~/.profile

# make conda activate command available from /bin/bash --interative shells
RUN conda init bash

# create a project directory inside user home
# (this isn't used with a clone running snakemake)
ENV PROJECT_DIR $HOME/app
RUN mkdir $PROJECT_DIR
# copy the code in
COPY . $PROJECT_DIR
WORKDIR $PROJECT_DIR

# build the conda environment
ENV ENV_PREFIX $PROJECT_DIR/env
RUN conda update --name base --channel defaults conda && \
conda env create --prefix $ENV_PREFIX --file /tmp/environment.yml --yes && \
conda clean --all --yes && \
conda activate $ENV_PREFIX && \
cargo install cgt_bacpop && \
mkdir bakta_db && \
bakta_db download --output bakta_db --type light && \
conda deactivate

# add rust binary to path
ENV PATH="$HOME/.cargo/bin:${PATH}"

# use an entrypoint script to insure conda environment is properly activated at runtime
USER root
ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]

# default of running shell is fine
#CMD [ "bash" ]
5 changes: 5 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash --login
set -e

conda activate $HOME/app/env
exec "$@"

0 comments on commit 61849b5

Please sign in to comment.