Skip to content

Commit 4175d68

Browse files
committed
Dockerfile: set vscode user in both tsffs dev and prod images
1 parent 671dad3 commit 4175d68

File tree

1 file changed

+32
-46
lines changed

1 file changed

+32
-46
lines changed

Dockerfile

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
# SPDX-License-Identifier: Apache-2.0
33
# hadolint global ignore=DL3041,DL3040
44

5-
FROM fedora:42@sha256:f357623dc40edf7803f21b2b954f92417f274a7370f82384ef13c73e08ce1727 AS tsffs-base
5+
FROM fedora:42@sha256:f357623dc40edf7803f21b2b954f92417f274a7370f82384ef13c73e08ce1727 AS tsffs-dev
66

77
# Download links can be obtained from:
88
# https://lemcenter.intel.com/productDownload/?Product=256660e5-a404-4390-b436-f64324d94959
99
ARG PUBLIC_SIMICS_PKGS_URL="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/ead79ef5-28b5-48c7-8d1f-3cde7760798f/simics-6-packages-2024-05-linux64.ispm"
1010
ARG PUBLIC_SIMICS_ISPM_URL="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/ead79ef5-28b5-48c7-8d1f-3cde7760798f/intel-simics-package-manager-1.8.3-linux64.tar.gz"
1111
ARG PUBLIC_SIMICS_PACKAGE_VERSION_1000="6.0.185"
12+
ARG USER_UID=1000
13+
ARG USERNAME=vscode
1214
ENV SIMICS_BASE="/workspace/simics/simics-${PUBLIC_SIMICS_PACKAGE_VERSION_1000}/"
1315
# Add cargo and ispm to the path
14-
ENV PATH="/root/.cargo/bin:/workspace/simics/ispm:${PATH}"
16+
ENV PATH="/home/${USERNAME}/.cargo/bin:/workspace/simics/ispm:${PATH}"
1517

1618
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
1719

@@ -76,9 +78,6 @@ python3 -m pip install --no-cache-dir \
7678
mypy==1.6.1 \
7779
pylint==3.0.2
7880

79-
# Install Rust
80-
curl https://sh.rustup.rs -sSf | bash -s -- --default-toolchain none -y
81-
8281
# Clean up package manager cache
8382
dnf clean all
8483
rm -rf /var/cache/dnf/* /tmp/* /var/tmp/*
@@ -87,14 +86,36 @@ EOF
8786

8887
WORKDIR /workspace
8988

89+
# create user
90+
RUN <<EOF
91+
set -e
92+
# create group for developers
93+
groupadd dev
94+
# Create group and user with a home at /home/vscode
95+
useradd \
96+
--create-home \
97+
--uid $USER_UID \
98+
--user-group \
99+
--groups dev \
100+
--shell /bin/bash \
101+
$USERNAME
102+
echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME
103+
104+
# Install Rust
105+
sudo -E -u $USERNAME bash -c 'curl https://sh.rustup.rs -sSf | bash -s -- -y --default-toolchain none'
106+
EOF
107+
108+
USER vscode
109+
90110
# Download and install public SIMICS. This installs all the public packages as well as the
91111
# ispm SIMICS package and project manager. ISPM will be on the path due to the ENV command
92112
# above
93113
# hadolint ignore=DL3004,SC3009
94114
RUN <<EOF
95115
set -e
96116
# Create directories
97-
mkdir -p /workspace/simics/ispm/
117+
sudo -E -u $USERNAME mkdir -p /workspace/simics/ispm/
118+
sudo -E -u $USERNAME chown -R vscode:dev /workspace/
98119

99120
# Download SIMICS components
100121
curl -L -o /workspace/simics/ispm.tar.gz "${PUBLIC_SIMICS_ISPM_URL}"
@@ -114,7 +135,7 @@ rm -rf /tmp/* /var/tmp/*
114135
EOF
115136

116137
# Copy the local repository into the workspace
117-
COPY . /workspace/tsffs/
138+
COPY --chown=vscode:dev . /workspace/tsffs/
118139

119140
WORKDIR /workspace/tsffs/
120141

@@ -168,42 +189,7 @@ cp /workspace/tsffs/harness/tsffs.h /workspace/projects/example/
168189
ninja
169190
EOF
170191

171-
RUN echo 'echo "To run the demo, run ./simics -no-gui --no-win fuzz.simics"' >> /root/.bashrc
172-
173-
FROM tsffs-base AS tsffs-dev
174-
ARG USER_UID=1000
175-
ARG USERNAME=vscode
176-
177-
# To build and run the dev image:
178-
# docker build --build-arg USER_UID=$(id -u) --target tsffs-dev -t tsffs:dev .
179-
# docker run --rm -ti --user vscode -v .:/workspace/tsffs tsffs:dev
180-
181-
# hadolint ignore=DL3004,SC3009
182-
RUN <<EOF
183-
set -e
184-
# create group for developers
185-
groupadd dev
186-
# Create group and user with a home at /home/vscode
187-
useradd \
188-
--create-home \
189-
--uid $USER_UID \
190-
--user-group \
191-
--groups dev \
192-
--shell /bin/bash \
193-
$USERNAME \
194-
&& echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME
195-
196-
# set /workspace/simics permissions to vscode:dev
197-
chown -R vscode:dev /workspace/{simics,projects,tsffs}
198-
199-
# install Rust nightly for the user
200-
sudo -E -u $USERNAME bash -c 'curl https://sh.rustup.rs -sSf | bash -s -- -y --default-toolchain none'
201-
202-
# copy Simics ISPM config
203-
mkdir -p /home/$USERNAME/.config
204-
cp -r "/root/.config/Intel Simics Package Manager/" "/home/$USERNAME/.config/"
205-
chown -R $USERNAME:$USERNAME "/home/$USERNAME/.config/"
206-
EOF
192+
RUN echo 'echo "To run the demo, run ./simics -no-gui --no-win fuzz.simics"' >> ~/.bashrc
207193

208194
WORKDIR /workspace/tsffs
209195

@@ -233,8 +219,8 @@ dnf clean all
233219
rm -rf /var/cache/dnf/* /tmp/* /var/tmp/*
234220
EOF
235221

236-
COPY --from=tsffs-base /workspace/projects /workspace/projects
237-
COPY --from=tsffs-base /workspace/simics /workspace/simics
238-
COPY --from=tsffs-base /root/.bashrc /root/.bashrc
222+
COPY --from=tsffs-dev /workspace/projects /workspace/projects
223+
COPY --from=tsffs-dev /workspace/simics /workspace/simics
224+
COPY --from=tsffs-dev /root/.bashrc /root/.bashrc
239225

240226
WORKDIR /workspace/projects/example

0 commit comments

Comments
 (0)