diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9469ad6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,42 @@ +# Secret files and resources +.secret* +resources/* + +# Python cache files +__pycache__/ +*.py[cod] +.pytest_cache/ + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# IDE or editor files +.vscode/ +.idea/ +*.swp + +# Jupyter Notebook checkpoints +.ipynb_checkpoints/ + +# Log and temporary files +*.log +*.tmp +*.temp + +# Environment files (pip and conda) +.env +.venv/ +env/ +venv/ +*.conda +*.condarc + +# Distribution / packaging files +bin/ +.Python +build/ +dist/ +lib/ +lib64/ +*.egg-info/ \ No newline at end of file diff --git a/.github/workflows/bifrost_sp_cdiff_workflow.yml b/.github/workflows/bifrost_sp_cdiff_workflow.yml new file mode 100644 index 0000000..cb2b018 --- /dev/null +++ b/.github/workflows/bifrost_sp_cdiff_workflow.yml @@ -0,0 +1,62 @@ +name: bifrost sp cdiff workflow + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + repository_dispatch: # webhook event to trigger this action workflow upon push to the submodule cdiff_fbi + types: + - cdiff-fbi-webhook + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: ["ubuntu-latest"] + python-version: ["3.11"] + + steps: + # Step 1: Checkout repository + - name: Checkout repository + uses: actions/checkout@v3 + with: + submodules: 'true' #Initialize and update submodules -> git submodule init && git submodule update + + # Step 2: Update submodule to the latest commit + - name: Update submodule + run: | + cd bifrost_sp_cdiff/cdiff_fbi + git fetch origin + git checkout main # or the specific branch you want to track + git pull origin main # pull the latest changes + + # print the latest commit of cdiff_fbi + LATEST_COMMIT=$(git rev-parse HEAD) + echo "Updated cdiff_fbi to latest commit: $LATEST_COMMIT" + + # Step 3: Set environment variables + - name: Set environment variables + run: | + echo "BIFROST_INSTALL_DIR='${{ github.workspace }}'" >> $GITHUB_ENV + + # Step 4: Extract version from __init__.py and set ENV_NAME + - name: Set ENV_NAME + run: | + VERSION=$(grep "__version__" bifrost_sp_cdiff/__init__.py | cut -d "'" -f 2) + REPO_NAME=$(basename "${{ github.workspace }}") + ENV_NAME="${REPO_NAME}_v${VERSION}" + # Echo the ENV_NAME to the log for debugging + echo "Setting ENV_NAME to: $ENV_NAME" + echo "ENV_NAME=$ENV_NAME" >> $GITHUB_ENV + + # Step 5: Build Docker image + - name: Build Docker image + run: | + docker build --build-arg BIFROST_DB_KEY="${{ secrets.MONGODB_ATLAS_TEST }}" --build-arg CONDA_ENV_NAME="${{ env.ENV_NAME }}" -t bifrost_sp_cdiff_image . + + # Step 6: Run Docker container and execute the command + - name: Run Docker container + run: | + docker run --env BIFROST_DB_KEY="${{ secrets.MONGODB_ATLAS_TEST }}" --env CONDA_ENV_NAME="${{ env.ENV_NAME }}" bifrost_sp_cdiff_image \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9469ad6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +# Secret files and resources +.secret* +resources/* + +# Python cache files +__pycache__/ +*.py[cod] +.pytest_cache/ + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# IDE or editor files +.vscode/ +.idea/ +*.swp + +# Jupyter Notebook checkpoints +.ipynb_checkpoints/ + +# Log and temporary files +*.log +*.tmp +*.temp + +# Environment files (pip and conda) +.env +.venv/ +env/ +venv/ +*.conda +*.condarc + +# Distribution / packaging files +bin/ +.Python +build/ +dist/ +lib/ +lib64/ +*.egg-info/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..eb0652e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +# syntax=docker/dockerfile:1 + +# Use a base image with Miniconda +FROM continuumio/miniconda3:latest + +# Set the working directory as base +WORKDIR /app + +# Install app dependencies and git necessary for submodules when using info from ecoli_fbi github repository +RUN apt-get update && apt-get install -y git + +# Copy the entire repository into the container +COPY . . + +# Copy the install.sh and environment.yml into the container +COPY install.sh . +#COPY environment.yml . + +# Ensure install.sh is executable +RUN chmod +x install.sh + +# Initialize conda for bash shell +RUN /opt/conda/bin/conda init bash + +# Install the tool using the install script +RUN bash install.sh -i LOCAL + +# Set environment variables +ENV BIFROST_INSTALL_DIR='/app' +# Use ARG for database key and set at runtime +ARG BIFROST_DB_KEY='' + +# Set the default command to run the Python module +CMD ["bash", "-c", "BIFROST_DB_KEY=\"$BIFROST_DB_KEY\" conda run -n $CONDA_ENV_NAME python cmd_test.py"] + diff --git a/install.sh b/install.sh index ab7cb22..b3b2d2d 100755 --- a/install.sh +++ b/install.sh @@ -9,6 +9,12 @@ helpFunction() exit 1 # Exit script after printing help } +# Check if the conda command exist in order to setup the conda environment +if ! command -v conda &> /dev/null; then + echo "conda could not be found, please install Anaconda/Miniconda" + exit 1 +fi + while getopts "i:" opt do case "$opt" in @@ -56,6 +62,24 @@ then fi fi +# Update ecoli_fbi submodule +echo "Updating ecoli_fbi submodule to the most current commit" +git submodule update --init --recursive +cd bifrost_sp_ecoli/ecoli_fbi || exit + +# Fetch the latest changes from the remote repository +git fetch origin +git checkout main # or the specific branch you want to track +git pull origin main + +# Optionally, echo the latest commit SHA +LATEST_COMMIT=$(git rev-parse HEAD) +echo "Updated ecoli_fbi to latest commit: $LATEST_COMMIT" + +# Navigate back to the main project directory +cd ../../ +pwd + # Begin script if $(conda config --show channels | grep -q "bioconda") then