Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update Docker environment configuration #286

Merged
merged 1 commit into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 94 additions & 60 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,94 @@
FROM rocker/r-ver:latest

# Install system dependencies
RUN apt-get update && apt-get install -y \
python3-minimal \
python3-pip \
python3-venv \
libssl-dev \
gdebi-core \
wget \
sudo \
curl

# Create rstudio user
ARG USER=rstudio
ARG PASSWORD=rstudio123
RUN useradd -m $USER && \
echo "$USER:$PASSWORD" | chpasswd && \
adduser $USER sudo && \
echo "$USER ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

# Install RStudio Server
RUN wget https://download2.rstudio.org/server/jammy/amd64/rstudio-server-2023.12.1-402-amd64.deb && \
gdebi -n rstudio-server-2023.12.1-402-amd64.deb && \
rm rstudio-server-*.deb

# Create and configure Python virtual environment
RUN python3 -m venv /opt/venv && \
chown -R $USER:$USER /opt/venv

ENV PATH="/opt/venv/bin:$PATH"
ENV RETICULATE_PYTHON="/opt/venv/bin/python"

# Setup R environment config
RUN mkdir -p /usr/local/lib/R/etc && \
echo "RETICULATE_PYTHON=/opt/venv/bin/python" >> /usr/local/lib/R/etc/Renviron.site && \
echo "options(reticulate.prompt = FALSE)" >> /usr/local/lib/R/etc/Rprofile.site

# Install Python packages
RUN /opt/venv/bin/pip install --no-cache-dir \
numpy==1.26.4 \
scipy==1.12.0 \
transformers \
torch \
flair

# Install R packages with proper setup
RUN R -e 'install.packages("reticulate", repos="https://cloud.r-project.org/", dependencies=TRUE)' && \
R -e 'if(require(reticulate)) { \
Sys.setenv(RETICULATE_PYTHON="/opt/venv/bin/python"); \
reticulate::use_python("/opt/venv/bin/python", required=TRUE); \
install.packages("remotes", repos="https://cloud.r-project.org/", dependencies=TRUE); \
remotes::install_github("davidycliao/flaiR", dependencies=TRUE) \
}'

WORKDIR /home/$USER
USER $USER
EXPOSE 8787

CMD ["/usr/lib/rstudio-server/bin/rserver", "--server-daemonize=0"]
name: flaiR-Docker
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]


jobs:
R-CMD-check:
runs-on: ubuntu-latest
name: R-CMD-check
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
steps:
- uses: actions/checkout@v3
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- uses: r-lib/actions/setup-pandoc@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install flair
- name: Install R dependencies
run: |
install.packages('remotes')
remotes::install_github("davidycliao/flaiR", force = TRUE)
shell: Rscript {0}

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: rcmdcheck

docker:
needs: R-CMD-check
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
buildkitd-flags: --debug

- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository_owner }}/flair-rstudio
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push RStudio image
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
DEFAULT_USER=rstudio
secrets: |
PASSWORD=${{ secrets.RSTUDIO_PASSWORD }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
52 changes: 21 additions & 31 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ RUN apt-get update && apt-get install -y \
gdebi-core \
wget \
sudo \
curl \
virtualenv # 添加virtualenv
curl

# Create rstudio user
ENV USER=rstudio
ENV PASSWORD=rstudio123
ARG USER=rstudio
ARG PASSWORD=rstudio123
RUN useradd -m $USER && \
echo "$USER:$PASSWORD" | chpasswd && \
adduser $USER sudo && \
Expand All @@ -25,46 +24,37 @@ RUN wget https://download2.rstudio.org/server/jammy/amd64/rstudio-server-2023.12
gdebi -n rstudio-server-2023.12.1-402-amd64.deb && \
rm rstudio-server-*.deb

# 修改虚拟环境路径到用户目录
ENV VENV_PATH=/home/$USER/flair_env
RUN python3 -m venv $VENV_PATH && \
chown -R $USER:$USER $VENV_PATH
# Create and configure Python virtual environment
RUN python3 -m venv /opt/venv && \
chown -R $USER:$USER /opt/venv

# 更新环境变量
ENV PATH="$VENV_PATH/bin:$PATH"
ENV RETICULATE_PYTHON="$VENV_PATH/bin/python"
ENV PATH="/opt/venv/bin:$PATH"
ENV RETICULATE_PYTHON="/opt/venv/bin/python"

# Setup R environment config
RUN mkdir -p /usr/local/lib/R/etc && \
echo "RETICULATE_PYTHON=$VENV_PATH/bin/python" >> /usr/local/lib/R/etc/Renviron.site && \
chown -R $USER:$USER /usr/local/lib/R/etc/Renviron.site && \
chmod 644 /usr/local/lib/R/etc/Renviron.site
echo "RETICULATE_PYTHON=/opt/venv/bin/python" >> /usr/local/lib/R/etc/Renviron.site && \
echo "options(reticulate.prompt = FALSE)" >> /usr/local/lib/R/etc/Rprofile.site

# Install Python packages in the virtual environment
RUN $VENV_PATH/bin/pip install --no-cache-dir \
# Install Python packages
RUN /opt/venv/bin/pip install --no-cache-dir \
numpy==1.26.4 \
scipy==1.12.0 \
transformers \
torch \
flair

# Install R packages
RUN R -e "install.packages('reticulate', repos='https://cloud.r-project.org/', dependencies=TRUE)" && \
R -e "install.packages('remotes', repos='https://cloud.r-project.org/', dependencies=TRUE)" && \
R -e "options(timeout=600); Sys.setenv(RETICULATE_PYTHON='$VENV_PATH/bin/python'); library(reticulate); use_virtualenv('$VENV_PATH', required = TRUE); remotes::install_github('davidycliao/flaiR', dependencies=TRUE)"
# Install R packages with proper setup
RUN R -e 'install.packages("reticulate", repos="https://cloud.r-project.org/", dependencies=TRUE)' && \
R -e 'if(require(reticulate)) { \
Sys.setenv(RETICULATE_PYTHON="/opt/venv/bin/python"); \
reticulate::use_python("/opt/venv/bin/python", required=TRUE); \
install.packages("remotes", repos="https://cloud.r-project.org/", dependencies=TRUE); \
remotes::install_github("davidycliao/flaiR", dependencies=TRUE) \
}'

# Set working directory
WORKDIR /home/$USER
RUN chown -R $USER:$USER /home/$USER

# Add healthcheck
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8787/ || exit 1

# Expose port
USER $USER
EXPOSE 8787

# Run service as rstudio user
USER $USER
CMD ["/usr/lib/rstudio-server/bin/rserver", "--server-daemonize=0"]
CMD ["/usr/lib/rstudio-server/bin/rserver", "--server-daemonize=0"]
Loading