Skip to content

Commit

Permalink
Refactor Docker image build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziaeemehr committed Feb 4, 2025
1 parent b6c8335 commit 27d7e9d
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: build & push Docker image to ghcr

on:
push:
tags:
- v*

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use the smallest official Python image
FROM python:3.9-slim

# Set environment variables to avoid interactive prompts
ENV DEBIAN_FRONTEND=noninteractive

# Set the working directory inside the container
WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends \
swig \
build-essential \
git \
&& rm -rf /var/lib/apt/lists/*


# Copy only the package files (without installing dependencies)
COPY . .

# Install Python dependencies
RUN pip install --no-cache-dir hatchling setuptools wheel && \
pip install .

# Optional: Support GPU version (comment out if not needed)
ARG GPU_SUPPORT=false
RUN if [ "$GPU_SUPPORT" = "true" ]; then pip install cupy; fi

CMD ["python", "-c", "from vbi.utils import test_imports; test_imports()"]
65 changes: 65 additions & 0 deletions vbi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,68 @@ def set_diag(A: np.ndarray, k: int = 0, value: float = 0.0):
idx = np.where(a1)
A[idx] = value
return A


def test_imports():
"""
Import some of required dependencies and print their versions if available
and warn if not available.
The required dependencies are:
- vbi
- numpy
- scipy
- matplotlib
- sbi
- torch [also check if GPU is available]
- cupy [also check if GPU is available]
"""

try:
import vbi
print(f"vbi: {vbi.__version__}")
except ImportError:
print("vbi not found")

try:
import numpy
print(f"numpy: {numpy.__version__}")
except ImportError:
print("numpy not found")

try:
import scipy
print(f"scipy: {scipy.__version__}")
except ImportError:
print("scipy not found")

try:
import matplotlib
print(f"matplotlib: {matplotlib.__version__}")
except ImportError:
print("matplotlib not found")

try:
import sbi
print(f"sbi: {sbi.__version__}")
except ImportError:
print("sbi not found")

try:
import torch
print(f"torch: {torch.__version__}")
print(f"GPU available: {torch.cuda.is_available()}")
except ImportError:
print("torch not found")

try:
import cupy
print(f"cupy: {cupy.__version__}")
print(f"GPU available: {cupy.cuda.is_available()}")
except ImportError:
print("cupy not found")




0 comments on commit 27d7e9d

Please sign in to comment.