File size: 4,430 Bytes
2e246e5
 
b86959c
2e246e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8a01dfa
2e246e5
 
b86959c
 
2e246e5
 
b86959c
2e246e5
 
b86959c
2e246e5
 
 
 
 
 
 
 
 
 
 
b86959c
 
2e246e5
b86959c
2e246e5
 
 
 
 
 
 
 
 
 
 
 
 
 
5fd5e25
2e246e5
 
 
 
 
 
 
 
b86959c
e40d438
 
 
5fd5e25
 
 
52c90cc
b86959c
 
510f150
b86959c
2e246e5
 
b86959c
2e246e5
 
 
 
 
b86959c
2e246e5
 
 
 
b86959c
2e246e5
 
 
 
 
 
 
 
 
 
 
5fd5e25
2e246e5
 
b86959c
0d66ed8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
FROM nvidia/cuda:12.2.0-devel-ubuntu22.04

# Install necessary packages
RUN apt update && \
    apt install -y --no-install-recommends \
        curl \
        git \
        git-lfs \
        libatomic1 \
        locales \
        man \
        nano \
        net-tools \
        netcat \
        openssh-client \
        python3 \
        python3-pip \
        python3-venv \
        sudo \
        vim \
        wget \
        zsh \
        zip \
        unzip \
        ffmpeg \
        imagemagick \
        software-properties-common \
    && git lfs install \
    && rm -rf /var/lib/apt/lists/*

# Fix ImageMagick policy
RUN sed -i '/<policy domain="path" rights="none" pattern="@\*"/d' /etc/ImageMagick-6/policy.xml

# Set working directory
WORKDIR /home/

# Environment variables
ENV USERNAME=user \
    USER_UID=1000 \
    USER_GID=1000 \
    LANG=C.UTF-8 \
    LC_ALL=C.UTF-8 \
    NVIDIA_VISIBLE_DEVICES=all \
    NVIDIA_DRIVER_CAPABILITIES=all \
    EDITOR=code \
    VISUAL=code \
    GIT_EDITOR="code --wait" \
    OPENVSCODE_SERVER_ROOT=/home/.vscode \
    OPENVSCODE=/home/.vscode/bin/openvscode-server \
    PATH="/home/user/.local/bin:$PATH"

# Download and install OpenVSCode Server
RUN RELEASE_TAG=$(curl -sX GET "https://api.github.com/repos/gitpod-io/openvscode-server/releases/latest" | awk '/tag_name/{print $4;exit}' FS='[""]') && \
    arch=$(uname -m) && \
    if [ "${arch}" = "x86_64" ]; then \
        arch="x64"; \
    elif [ "${arch}" = "aarch64" ]; then \
        arch="arm64"; \
    elif [ "${arch}" = "armv7l" ]; then \
        arch="armhf"; \
    fi && \
    wget https://github.com/gitpod-io/openvscode-server/releases/download/${RELEASE_TAG}/${RELEASE_TAG}-linux-${arch}.tar.gz && \
    tar -xzf ${RELEASE_TAG}-linux-${arch}.tar.gz && \
    mv ${RELEASE_TAG}-linux-${arch} ${OPENVSCODE_SERVER_ROOT} && \
    cp ${OPENVSCODE_SERVER_ROOT}/bin/remote-cli/openvscode-server ${OPENVSCODE_SERVER_ROOT}/bin/remote-cli/code && \
    rm -f ${RELEASE_TAG}-linux-${arch}.tar.gz

# Install Firefox within VS-code
RUN install -d -m 0755 /etc/apt/keyrings && \
    wget -q https://packages.mozilla.org/apt/repo-signing-key.gpg -O- | tee /etc/apt/keyrings/packages.mozilla.org.asc > /dev/null && \
    gpg -n -q --import --import-options import-show /etc/apt/keyrings/packages.mozilla.org.asc | awk '/pub/{getline; gsub(/^ +| +$/,""); if($0 == "35BAA0B33E9EB396F59CA838C0BA5CE6DC6315A3") print "\nThe key fingerprint matches ("$0").\n"; else print "\nVerification failed: the fingerprint ("$0") does not match the expected one.\n"}' && \
    echo "deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main" | tee -a /etc/apt/sources.list.d/mozilla.list > /dev/null && \
    echo 'Package: *\nPin: origin packages.mozilla.org\nPin-Priority: 1000\n' | tee /etc/apt/preferences.d/mozilla && \
    apt-get update && \
    apt-get install -y firefox

# Download and install GeckoDriver for x86_64 architecture
RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.34.0/geckodriver-v0.34.0-linux64.tar.gz && \
    tar -xvzf geckodriver-v0.34.0-linux64.tar.gz && \
    sudo mv geckodriver /usr/local/bin/ && \
    sudo chmod +x /usr/local/bin/geckodriver && \
    geckodriver --version
    
# Install PDM
RUN curl -sSL https://pdm-project.org/install-pdm.py | python3 -

# Set working directory for user
WORKDIR /home/user/

# Create user and usergroup
RUN groupadd --gid ${USER_GID} ${USERNAME} \
    && useradd --uid ${USER_UID} --gid ${USERNAME} -m -s /bin/bash ${USERNAME} \
    && echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} \
    && chmod 0440 /etc/sudoers.d/${USERNAME}

# Set permissions
RUN chmod g+rw /home && \
    chown -R ${USERNAME}:${USERNAME} ${OPENVSCODE_SERVER_ROOT} && \
    chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}

# Switch to user
USER $USERNAME

# Install oh-my-zsh & Init
RUN yes | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# Install VSCode Extensions
RUN ${OPENVSCODE} --install-extension ms-python.python && \
    ${OPENVSCODE} --install-extension monokai.theme-monokai-pro-vscode

# Install python packages
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt && \
    rm -rf requirements.txt

# Entry point
ENTRYPOINT ["/bin/sh", "-c", "exec $OPENVSCODE --host 0.0.0.0 --port 7860 --without-connection-token"]