Skip to content

Commit d33df2b

Browse files
authored
Merge pull request #286 from davidycliao/0.1.7
2 parents f9798b7 + a47b172 commit d33df2b

File tree

2 files changed

+115
-91
lines changed

2 files changed

+115
-91
lines changed

.github/workflows/docker-publish.yml

Lines changed: 94 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,94 @@
1-
FROM rocker/r-ver:latest
2-
3-
# Install system dependencies
4-
RUN apt-get update && apt-get install -y \
5-
python3-minimal \
6-
python3-pip \
7-
python3-venv \
8-
libssl-dev \
9-
gdebi-core \
10-
wget \
11-
sudo \
12-
curl
13-
14-
# Create rstudio user
15-
ARG USER=rstudio
16-
ARG PASSWORD=rstudio123
17-
RUN useradd -m $USER && \
18-
echo "$USER:$PASSWORD" | chpasswd && \
19-
adduser $USER sudo && \
20-
echo "$USER ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
21-
22-
# Install RStudio Server
23-
RUN wget https://download2.rstudio.org/server/jammy/amd64/rstudio-server-2023.12.1-402-amd64.deb && \
24-
gdebi -n rstudio-server-2023.12.1-402-amd64.deb && \
25-
rm rstudio-server-*.deb
26-
27-
# Create and configure Python virtual environment
28-
RUN python3 -m venv /opt/venv && \
29-
chown -R $USER:$USER /opt/venv
30-
31-
ENV PATH="/opt/venv/bin:$PATH"
32-
ENV RETICULATE_PYTHON="/opt/venv/bin/python"
33-
34-
# Setup R environment config
35-
RUN mkdir -p /usr/local/lib/R/etc && \
36-
echo "RETICULATE_PYTHON=/opt/venv/bin/python" >> /usr/local/lib/R/etc/Renviron.site && \
37-
echo "options(reticulate.prompt = FALSE)" >> /usr/local/lib/R/etc/Rprofile.site
38-
39-
# Install Python packages
40-
RUN /opt/venv/bin/pip install --no-cache-dir \
41-
numpy==1.26.4 \
42-
scipy==1.12.0 \
43-
transformers \
44-
torch \
45-
flair
46-
47-
# Install R packages with proper setup
48-
RUN R -e 'install.packages("reticulate", repos="https://cloud.r-project.org/", dependencies=TRUE)' && \
49-
R -e 'if(require(reticulate)) { \
50-
Sys.setenv(RETICULATE_PYTHON="/opt/venv/bin/python"); \
51-
reticulate::use_python("/opt/venv/bin/python", required=TRUE); \
52-
install.packages("remotes", repos="https://cloud.r-project.org/", dependencies=TRUE); \
53-
remotes::install_github("davidycliao/flaiR", dependencies=TRUE) \
54-
}'
55-
56-
WORKDIR /home/$USER
57-
USER $USER
58-
EXPOSE 8787
59-
60-
CMD ["/usr/lib/rstudio-server/bin/rserver", "--server-daemonize=0"]
1+
name: flaiR-Docker
2+
on:
3+
push:
4+
branches: [main, master]
5+
pull_request:
6+
branches: [main, master]
7+
8+
9+
jobs:
10+
R-CMD-check:
11+
runs-on: ubuntu-latest
12+
name: R-CMD-check
13+
env:
14+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
15+
R_KEEP_PKG_SOURCE: yes
16+
steps:
17+
- uses: actions/checkout@v3
18+
- uses: r-lib/actions/setup-r@v2
19+
with:
20+
use-public-rspm: true
21+
- uses: r-lib/actions/setup-pandoc@v2
22+
23+
- name: Setup Python
24+
uses: actions/setup-python@v2
25+
with:
26+
python-version: '3.9'
27+
28+
- name: Install Python dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install flair
32+
- name: Install R dependencies
33+
run: |
34+
install.packages('remotes')
35+
remotes::install_github("davidycliao/flaiR", force = TRUE)
36+
shell: Rscript {0}
37+
38+
- uses: r-lib/actions/setup-r-dependencies@v2
39+
with:
40+
extra-packages: rcmdcheck
41+
42+
docker:
43+
needs: R-CMD-check
44+
runs-on: ubuntu-latest
45+
permissions:
46+
contents: read
47+
packages: write
48+
49+
steps:
50+
- name: Checkout repository
51+
uses: actions/checkout@v3
52+
53+
- name: Set up QEMU
54+
uses: docker/setup-qemu-action@v2
55+
56+
- name: Log in to GitHub Container Registry
57+
uses: docker/login-action@v2
58+
with:
59+
registry: ghcr.io
60+
username: ${{ github.actor }}
61+
password: ${{ secrets.GITHUB_TOKEN }}
62+
63+
- name: Set up Docker Buildx
64+
uses: docker/setup-buildx-action@v2
65+
with:
66+
buildkitd-flags: --debug
67+
68+
- name: Extract metadata for Docker
69+
id: meta
70+
uses: docker/metadata-action@v4
71+
with:
72+
images: ghcr.io/${{ github.repository_owner }}/flair-rstudio
73+
tags: |
74+
type=ref,event=branch
75+
type=ref,event=pr
76+
type=semver,pattern={{version}}
77+
type=semver,pattern={{major}}.{{minor}}
78+
type=sha
79+
type=raw,value=latest,enable={{is_default_branch}}
80+
- name: Build and push RStudio image
81+
uses: docker/build-push-action@v4
82+
with:
83+
context: .
84+
platforms: linux/amd64
85+
push: ${{ github.event_name != 'pull_request' }}
86+
tags: ${{ steps.meta.outputs.tags }}
87+
labels: ${{ steps.meta.outputs.labels }}
88+
build-args: |
89+
DEFAULT_USER=rstudio
90+
secrets: |
91+
PASSWORD=${{ secrets.RSTUDIO_PASSWORD }}
92+
cache-from: type=gha
93+
cache-to: type=gha,mode=max
94+
provenance: false

Dockerfile

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ RUN apt-get update && apt-get install -y \
99
gdebi-core \
1010
wget \
1111
sudo \
12-
curl \
13-
virtualenv # 添加virtualenv
12+
curl
1413

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

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

33-
# 更新环境变量
34-
ENV PATH="$VENV_PATH/bin:$PATH"
35-
ENV RETICULATE_PYTHON="$VENV_PATH/bin/python"
31+
ENV PATH="/opt/venv/bin:$PATH"
32+
ENV RETICULATE_PYTHON="/opt/venv/bin/python"
3633

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

43-
# Install Python packages in the virtual environment
44-
RUN $VENV_PATH/bin/pip install --no-cache-dir \
39+
# Install Python packages
40+
RUN /opt/venv/bin/pip install --no-cache-dir \
4541
numpy==1.26.4 \
4642
scipy==1.12.0 \
4743
transformers \
4844
torch \
4945
flair
5046

51-
# Install R packages
52-
RUN R -e "install.packages('reticulate', repos='https://cloud.r-project.org/', dependencies=TRUE)" && \
53-
R -e "install.packages('remotes', repos='https://cloud.r-project.org/', dependencies=TRUE)" && \
54-
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)"
47+
# Install R packages with proper setup
48+
RUN R -e 'install.packages("reticulate", repos="https://cloud.r-project.org/", dependencies=TRUE)' && \
49+
R -e 'if(require(reticulate)) { \
50+
Sys.setenv(RETICULATE_PYTHON="/opt/venv/bin/python"); \
51+
reticulate::use_python("/opt/venv/bin/python", required=TRUE); \
52+
install.packages("remotes", repos="https://cloud.r-project.org/", dependencies=TRUE); \
53+
remotes::install_github("davidycliao/flaiR", dependencies=TRUE) \
54+
}'
5555

56-
# Set working directory
5756
WORKDIR /home/$USER
58-
RUN chown -R $USER:$USER /home/$USER
59-
60-
# Add healthcheck
61-
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
62-
CMD curl -f http://localhost:8787/ || exit 1
63-
64-
# Expose port
57+
USER $USER
6558
EXPOSE 8787
6659

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

0 commit comments

Comments
 (0)