Skip to content

Commit

Permalink
Use pixi for dep management (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber authored Nov 17, 2024
1 parent 2a0b2a2 commit bf78836
Show file tree
Hide file tree
Showing 22 changed files with 6,994 additions and 1,314 deletions.
4 changes: 1 addition & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

# except
!wort/
!Pipfile.lock
!Pipfile
!requirements.txt
!pixi.lock
!config/
!wortapp.py
!pyproject.toml
4 changes: 4 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
load_prefix ~/.pixi

watch_file pixi.lock
eval "$(pixi shell-hook)"
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# GitHub syntax highlighting
pixi.lock linguist-language=YAML
4 changes: 2 additions & 2 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check docker-compose can build containers
name: Check docker compose can build containers
on: push
jobs:
test:
Expand All @@ -11,7 +11,7 @@ jobs:
mkdir -p iam
touch iam/wort_s3.env
- name: Build the stack
run: docker-compose build
run: docker compose build
# TODO: check containers can start
#- name: Bring up containers
# run: docker-compose up -d web worker
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ target/
fabfile.py
*.wasm
**/node_modules/*
dist/

.config/
.envrc
Expand All @@ -27,3 +28,8 @@ machine/*
nix/*
nocolors_600k
package-lock.json

# pixi environments
.pixi

.direnv
119 changes: 51 additions & 68 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,89 +1,72 @@
# Build decoct
FROM rust:1-slim-bullseye as builder
RUN cargo install --git https://github.com/luizirber/decoct --rev 630f5a773e6df22a33dafc3d744e39735c055328

# Build worker image
FROM python:3.10.9-slim-bullseye as base

RUN groupadd user && \
useradd --create-home --home-dir /home/user -g user -s /bin/bash user

WORKDIR /home/user

#--------------------

FROM base as python-deps

RUN apt-get update
RUN apt-get install -y --no-install-recommends build-essential libcurl4-openssl-dev libssl-dev curl

RUN python3 -m venv /home/user/.venv

COPY requirements.txt ./

RUN . /home/user/.venv/bin/activate && pip install --require-hashes -r requirements.txt

RUN curl --output sratoolkit.tar.gz https://ftp-trace.ncbi.nlm.nih.gov/sra/sdk/3.0.2/sratoolkit.3.0.2-ubuntu64.tar.gz
RUN tar xf sratoolkit.tar.gz
FROM ghcr.io/prefix-dev/pixi:0.36.0 AS build

COPY . /app
WORKDIR /app
RUN pixi run build-wheel
RUN pixi run -e web postinstall-prod
RUN pixi shell-hook -e web > /shell-hook-web
RUN echo 'exec "$@"' >> /shell-hook-web
RUN pixi run -e worker postinstall-prod
RUN pixi shell-hook -e worker > /shell-hook-worker
RUN echo 'exec "$@"' >> /shell-hook-worker

#--------------------

FROM base as web

COPY --from=python-deps /home/user/.venv /home/user/.venv
FROM ubuntu:24.04 AS web

WORKDIR /app/wort
# only copy the production environment into prod container
COPY --from=build /app/.pixi/envs/web /app/.pixi/envs/web
COPY --from=build /shell-hook-web /shell-hook

ADD wortapp.py pyproject.toml ./
RUN groupadd user && \
useradd --create-home --home-dir /home/user -g user -s /bin/bash user

COPY wort wort
COPY config config
COPY wortapp.py /app
COPY config/ /app/config

RUN . /home/user/.venv/bin/activate && pip install flit && FLIT_ROOT_INSTALL=1 flit install --symlink
WORKDIR /app

USER user
#USER user

ENV PATH "/home/user/.venv/bin:$PATH"
CMD . /home/user/.venv/bin/activate && gunicorn -b 0.0.0.0:5000 --access-logfile - "wort.app:create_app()"
ENTRYPOINT ["/bin/bash", "/shell-hook"]
CMD ["gunicorn", "-b", "0.0.0.0:5000", "--access-logfile", "-", "'wortapp:create_app()'"]

#--------------------

FROM base as worker
FROM ubuntu:24.04 AS worker

COPY --from=builder /usr/local/cargo/bin/decoct /usr/local/bin/sourmash
COPY --from=python-deps /home/user/sratoolkit.3.0.2-ubuntu64/bin /home/user/sratoolkit.3.0.2-ubuntu64/bin
COPY --from=python-deps /home/user/.venv /home/user/.venv
# only copy the production environment into prod container
COPY --from=build /app/.pixi/envs/worker /app/.pixi/envs/worker
COPY --from=build /shell-hook-worker /shell-hook

ENV PATH "/home/user/.venv/bin:$PATH"
RUN groupadd user && \
useradd --create-home --home-dir /home/user -g user -s /bin/bash user

ENV PATH "$PATH:/home/user/sratoolkit.3.0.2-ubuntu64/bin"
COPY wortapp.py /app
COPY config/ /app/config

# needed for celery[sqs]
RUN apt-get update
RUN apt-get install -y --no-install-recommends libcurl4-openssl-dev libssl-dev
WORKDIR /app

USER user
USER user

# Configure sra-toolkit to disable cache
RUN mkdir .ncbi

RUN echo '## auto-generated configuration file - DO NOT EDIT ##''' >> .ncbi/user-settings.mkfg
RUN echo '' >> .ncbi/user-settings.mkfg
RUN echo '/LIBS/GUID = "7737545d-30d4-4d05-875a-2c562df521d5"' >> .ncbi/user-settings.mkfg
RUN echo '/config/default = "false"' >> .ncbi/user-settings.mkfg
RUN echo '/libs/cloud/accept_aws_charges = "false"' >> .ncbi/user-settings.mkfg
RUN echo '/libs/cloud/report_instance_identity = "true"' >> .ncbi/user-settings.mkfg
RUN echo '/repository/user/ad/public/apps/file/volumes/flatAd = "."' >> .ncbi/user-settings.mkfg
RUN echo '/repository/user/ad/public/apps/refseq/volumes/refseqAd = "."' >> .ncbi/user-settings.mkfg
RUN echo '/repository/user/ad/public/apps/sra/volumes/sraAd = "."' >> .ncbi/user-settings.mkfg
RUN echo '/repository/user/ad/public/apps/sraPileup/volumes/ad = "."' >> .ncbi/user-settings.mkfg
RUN echo '/repository/user/ad/public/apps/sraRealign/volumes/ad = "."' >> .ncbi/user-settings.mkfg
RUN echo '/repository/user/ad/public/root = "."' >> .ncbi/user-settings.mkfg
RUN echo '/repository/user/default-path = "/root/ncbi"' >> .ncbi/user-settings.mkfg
RUN echo '/repository/user/main/public/cache-disabled = "true"' >> .ncbi/user-settings.mkfg

COPY wort wort
COPY config config
RUN mkdir ~/.ncbi

RUN echo '## auto-generated configuration file - DO NOT EDIT ##''' >> ~/.ncbi/user-settings.mkfg
RUN echo '' >> ~/.ncbi/user-settings.mkfg
RUN echo '/LIBS/GUID = "7737545d-30d4-4d05-875a-2c562df521d5"' >> ~/.ncbi/user-settings.mkfg
RUN echo '/config/default = "false"' >> ~/.ncbi/user-settings.mkfg
RUN echo '/libs/cloud/accept_aws_charges = "false"' >> ~/.ncbi/user-settings.mkfg
RUN echo '/libs/cloud/report_instance_identity = "true"' >> ~/.ncbi/user-settings.mkfg
RUN echo '/repository/user/ad/public/apps/file/volumes/flatAd = "."' >> ~/.ncbi/user-settings.mkfg
RUN echo '/repository/user/ad/public/apps/refseq/volumes/refseqAd = "."' >> ~/.ncbi/user-settings.mkfg
RUN echo '/repository/user/ad/public/apps/sra/volumes/sraAd = "."' >> ~/.ncbi/user-settings.mkfg
RUN echo '/repository/user/ad/public/apps/sraPileup/volumes/ad = "."' >> ~/.ncbi/user-settings.mkfg
RUN echo '/repository/user/ad/public/apps/sraRealign/volumes/ad = "."' >> ~/.ncbi/user-settings.mkfg
RUN echo '/repository/user/ad/public/root = "."' >> ~/.ncbi/user-settings.mkfg
RUN echo '/repository/user/default-path = "/root/ncbi"' >> ~/.ncbi/user-settings.mkfg
RUN echo '/repository/user/main/public/cache-disabled = "true"' >> ~/.ncbi/user-settings.mkfg

ENV RAYON_NUM_THREADS 3
CMD celery -A wort.blueprints.compute.tasks worker -Q compute_small,compute_medium,genomes --without-gossip --without-mingle --without-heartbeat -l INFO -c 1
ENTRYPOINT ["/bin/bash", "/shell-hook"]
CMD ["celery", "-A", "wort.blueprints.compute.tasks", "worker", "-Q", "compute_small,compute_medium,genomes", "--without-gossip", "--without-mingle", "--without-heartbeat", "-l", "INFO", "-c", "1"]
10 changes: 0 additions & 10 deletions default.nix

This file was deleted.

5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ services:
command: >
gunicorn -b 0.0.0.0:5000
--access-logfile -
--reload
"wort.app:create_app()"
environment:
PYTHONUNBUFFERED: 'true'
Expand All @@ -48,8 +47,8 @@ services:
- redis
env_file:
- env.production
volumes:
- .:/app/wort
# volumes:
# - .:/app/wort

redis:
restart: always
Expand Down
3 changes: 0 additions & 3 deletions nginx/Dockerfile

This file was deleted.

31 changes: 0 additions & 31 deletions nginx/nginx.conf

This file was deleted.

35 changes: 0 additions & 35 deletions nginx/wort.conf

This file was deleted.

3 changes: 0 additions & 3 deletions nix/overlay.nix

This file was deleted.

42 changes: 0 additions & 42 deletions nix/pkgs/wort.nix

This file was deleted.

14 changes: 0 additions & 14 deletions nix/rust.nix

This file was deleted.

38 changes: 0 additions & 38 deletions nix/sources.json

This file was deleted.

Loading

0 comments on commit bf78836

Please sign in to comment.