-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Docker configuration and containerization guidelines (#3)
- Loading branch information
1 parent
a8720e5
commit b274466
Showing
18 changed files
with
4,431 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Build Docker Images For Mono-Repo Structure | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
mono-repo-build-docker: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ${{ matrix.directory }} | ||
strategy: | ||
matrix: | ||
directory: [ | ||
monorepo/services/service_a, | ||
monorepo/services/service_b | ||
] | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Extract service name | ||
id: extract-service-name | ||
run: echo "service_name=$(basename ${{ matrix.directory }})" >> $GITHUB_OUTPUT | ||
|
||
- name: Build Docker | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: ${{ matrix.directory }} | ||
tags: ${{ steps.extract-service-name.outputs.service_name }}:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Build Docker Image For Standard Structure | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
standard-repo-build-docker: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: standard | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Build Docker | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: ./standard | ||
tags: service:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
FROM python:3.12.4-slim AS builder | ||
|
||
RUN pip install --upgrade pip==24.1.1 && \ | ||
pip install poetry==1.8.3 | ||
|
||
WORKDIR /app | ||
|
||
COPY pyproject.toml poetry.toml poetry.lock ./ | ||
|
||
RUN poetry install --only main | ||
|
||
FROM python:3.12.4-slim AS runtime | ||
|
||
WORKDIR /app | ||
|
||
ENV PATH="/app/.venv/bin:$PATH" | ||
|
||
COPY src src | ||
COPY main.py . | ||
|
||
EXPOSE 8080 | ||
|
||
COPY --from=builder /app/.venv .venv | ||
|
||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
FROM python:3.12.4-slim AS builder | ||
|
||
RUN pip install --upgrade pip==24.1.1 && \ | ||
pip install poetry==1.8.3 | ||
|
||
WORKDIR /app | ||
|
||
COPY pyproject.toml poetry.toml poetry.lock ./ | ||
|
||
RUN poetry install --only main | ||
|
||
FROM python:3.12.4-slim AS runtime | ||
|
||
WORKDIR /app | ||
|
||
ENV PATH="/app/.venv/bin:$PATH" | ||
|
||
COPY src src | ||
COPY main.py . | ||
|
||
EXPOSE 8080 | ||
|
||
COPY --from=builder /app/.venv .venv | ||
|
||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
FROM alpine/git AS pytorch-source | ||
|
||
# Carefully select commit hash, as they are not guaranteed to uniformly build successfully. | ||
|
||
RUN git clone https://github.com/pytorch/pytorch.git pytorch && \ | ||
cd pytorch && \ | ||
git checkout 7919f0b && \ | ||
git submodule update --init --recursive && \ | ||
cd .. | ||
|
||
FROM nvidia/cuda:12.5.1-cudnn-devel-ubuntu22.04 | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
# For this Dockerefile we will use pyenv. Installing Python via pyenv creates an isolated environment, separate from | ||
# Ubuntu's system Python. This approach prevents accidental modifications to system-critical components that rely on | ||
# the default Python, ensuring overall system stability and avoiding potential breakage of Ubuntu's built-in tools and | ||
# packages. It also provides us with flexibility to choose any desired Python version. | ||
|
||
# Install essential build packages for Python (built by pyenv) and PyTorch, as they are built from source. | ||
# Additional utility packages (curl, git, wget) are included for common development tasks. | ||
RUN apt-get update && \ | ||
apt-get install -y --no-install-recommends \ | ||
build-essential \ | ||
ca-certificates \ | ||
cmake \ | ||
curl \ | ||
git \ | ||
libbz2-dev \ | ||
libffi-dev \ | ||
liblzma-dev \ | ||
libncurses5-dev \ | ||
libncursesw5-dev \ | ||
libreadline-dev \ | ||
libsqlite3-dev \ | ||
libssl-dev \ | ||
libxml2-dev \ | ||
libxmlsec1-dev \ | ||
llvm \ | ||
ninja-build \ | ||
openssh-client \ | ||
tk-dev \ | ||
wget \ | ||
xz-utils \ | ||
zlib1g-dev && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# pyenv configuration | ||
ENV PYENV_GIT_TAG="v2.4.7" | ||
ENV PYENV_ROOT=/root/.pyenv | ||
ENV PATH="$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH" | ||
|
||
ENV PYTHON_VERSION=3.12.3 | ||
|
||
RUN curl https://pyenv.run | bash && pyenv install $PYTHON_VERSION | ||
|
||
WORKDIR /app | ||
|
||
RUN pyenv local $PYTHON_VERSION | ||
|
||
ENV PIP_INSTALL_VERSION=24.1.2 | ||
ENV POETRY_VERSION=1.8.3 | ||
|
||
RUN pip install --upgrade pip==$PIP_INSTALL_VERSION && \ | ||
pip install --no-cache-dir poetry==$POETRY_VERSION && \ | ||
pip cache purge | ||
|
||
# Set up environment for PyTorch build | ||
ENV USE_CUDA=1 | ||
ENV USE_CUDNN=1 | ||
ENV CMAKE_PREFIX_PATH="$(dirname $(which python))/../" | ||
|
||
COPY --from=pytorch-source git/pytorch pytorch | ||
COPY pyproject.toml poetry.toml poetry.lock ./ | ||
RUN poetry install --no-root && poetry add -e -vvv ./pytorch && rm -rf pytorch | ||
|
||
EXPOSE 8888 | ||
CMD ["poetry", "run", "jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--allow-root"] |
Oops, something went wrong.