Skip to content

Commit 5dddfd4

Browse files
authored
Dockerfile: set vscode user in both tsffs dev and prod images (#225)
1 parent 0a6ce17 commit 5dddfd4

File tree

2 files changed

+99
-55
lines changed

2 files changed

+99
-55
lines changed

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,38 @@ jobs:
633633
name: Build for Distribution
634634
runs-on: ubuntu-22.04
635635
steps:
636+
- name: Aggressive cleanup
637+
run: |
638+
# Remove Java (JDKs)
639+
sudo rm -rf /usr/lib/jvm
640+
641+
# Remove .NET SDKs
642+
sudo rm -rf /usr/share/dotnet
643+
644+
# Remove Swift toolchain
645+
sudo rm -rf /usr/share/swift
646+
647+
# Remove Haskell (GHC)
648+
sudo rm -rf /usr/local/.ghcup
649+
650+
# Remove Julia
651+
sudo rm -rf /usr/local/julia*
652+
653+
# Remove Android SDKs
654+
sudo rm -rf /usr/local/lib/android
655+
656+
# Remove Chromium (optional if not using for browser tests)
657+
sudo rm -rf /usr/local/share/chromium
658+
659+
# Remove Microsoft/Edge and Google Chrome builds
660+
sudo rm -rf /opt/microsoft /opt/google
661+
662+
# Remove Azure CLI
663+
sudo rm -rf /opt/az
664+
665+
# Remove PowerShell
666+
sudo rm -rf /usr/local/share/powershell
667+
636668
- name: Harden Runner
637669
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
638670
with:

Dockerfile

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

5-
FROM fedora:42@sha256:f357623dc40edf7803f21b2b954f92417f274a7370f82384ef13c73e08ce1727 AS tsffs-base
6-
75
# Download links can be obtained from:
86
# https://lemcenter.intel.com/productDownload/?Product=256660e5-a404-4390-b436-f64324d94959
97
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"
108
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"
119
ARG PUBLIC_SIMICS_PACKAGE_VERSION_1000="6.0.185"
10+
ARG USER_UID=1000
11+
ARG USERNAME=vscode
12+
13+
FROM fedora:42@sha256:f357623dc40edf7803f21b2b954f92417f274a7370f82384ef13c73e08ce1727 AS create-user
14+
# redeclare ARGs
15+
ARG USER_UID
16+
ARG USERNAME
17+
18+
# hadolint ignore=DL3004,SC3009
19+
RUN <<EOF
20+
set -e
21+
# Update system packages
22+
dnf -y update
23+
24+
# create group for developers
25+
groupadd dev
26+
# Create group and user with a home at /home/vscode
27+
useradd \
28+
--create-home \
29+
--uid $USER_UID \
30+
--user-group \
31+
--groups dev \
32+
--shell /bin/bash \
33+
$USERNAME
34+
echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME
35+
sudo -E -u $USERNAME bash -c 'curl https://sh.rustup.rs -sSf | bash -s -- -y --default-toolchain none'
36+
EOF
37+
38+
FROM create-user AS tsffs-dev
39+
# redeclare ARGs
40+
ARG PUBLIC_SIMICS_PKGS_URL
41+
ARG PUBLIC_SIMICS_ISPM_URL
42+
ARG PUBLIC_SIMICS_PACKAGE_VERSION_1000
43+
ARG USER_UID
44+
ARG USERNAME
1245
ENV SIMICS_BASE="/workspace/simics/simics-${PUBLIC_SIMICS_PACKAGE_VERSION_1000}/"
1346
# Add cargo and ispm to the path
14-
ENV PATH="/root/.cargo/bin:/workspace/simics/ispm:${PATH}"
47+
ENV PATH="/home/${USERNAME}/.cargo/bin:/workspace/simics/ispm:${PATH}"
1548

1649
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
1750

@@ -24,8 +57,6 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"]
2457
# hadolint ignore=DL3004,SC3009
2558
RUN <<EOF
2659
set -e
27-
# Update system packages
28-
dnf -y update
2960

3061
# Install system dependencies
3162
dnf -y install \
@@ -76,9 +107,6 @@ python3 -m pip install --no-cache-dir \
76107
mypy==1.6.1 \
77108
pylint==3.0.2
78109

79-
# Install Rust
80-
curl https://sh.rustup.rs -sSf | bash -s -- --default-toolchain none -y
81-
82110
# Clean up package manager cache
83111
dnf clean all
84112
rm -rf /var/cache/dnf/* /tmp/* /var/tmp/*
@@ -87,13 +115,19 @@ EOF
87115

88116
WORKDIR /workspace
89117

118+
# install Rust
119+
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y --default-toolchain none
120+
90121
# Download and install public SIMICS. This installs all the public packages as well as the
91122
# ispm SIMICS package and project manager. ISPM will be on the path due to the ENV command
92123
# above
93124
# hadolint ignore=DL3004,SC3009
94125
RUN <<EOF
95126
set -e
96-
# Create directories
127+
# set setgid on /workspace to inherit dev group
128+
chown root:dev /workspace
129+
chmod g+ws /workspace
130+
umask 002
97131
mkdir -p /workspace/simics/ispm/
98132

99133
# Download SIMICS components
@@ -114,7 +148,7 @@ rm -rf /tmp/* /var/tmp/*
114148
EOF
115149

116150
# Copy the local repository into the workspace
117-
COPY . /workspace/tsffs/
151+
COPY --chown=vscode:dev . /workspace/tsffs/
118152

119153
WORKDIR /workspace/tsffs/
120154

@@ -129,6 +163,7 @@ cargo install cargo-simics-build
129163
# Build the project
130164
cargo simics-build -r
131165

166+
umask 002
132167
# Install the built package
133168
ispm packages -i target/release/*-linux64.ispm --non-interactive --trust-insecure-packages
134169

@@ -150,12 +185,13 @@ WORKDIR /workspace/projects/example/
150185
# hadolint ignore=DL3004,SC3009
151186
RUN <<EOF
152187
set -e
188+
umask 002
153189
# Create the example project
154190
ispm projects /workspace/projects/example/ --create \
155191
1000-${PUBLIC_SIMICS_PACKAGE_VERSION_1000} \
156-
2096-latest \
157-
8112-latest \
158-
1030-latest \
192+
2096-6.0.73 \
193+
8112-6.0.21 \
194+
1030-6.0.7 \
159195
31337-latest --ignore-existing-files --non-interactive
160196

161197
# Copy required files
@@ -168,53 +204,24 @@ cp /workspace/tsffs/harness/tsffs.h /workspace/projects/example/
168204
ninja
169205
EOF
170206

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
207+
USER vscode
208+
RUN echo 'echo "To run the demo, run ./simics -no-gui --no-win fuzz.simics"' >> ~/.bashrc
207209

208210
WORKDIR /workspace/tsffs
209211

210-
FROM fedora:42@sha256:f357623dc40edf7803f21b2b954f92417f274a7370f82384ef13c73e08ce1727 AS tsffs-prod
212+
FROM create-user AS tsffs-prod
213+
# redeclare ARGs
214+
ARG PUBLIC_SIMICS_PKGS_URL
215+
ARG PUBLIC_SIMICS_ISPM_URL
216+
ARG PUBLIC_SIMICS_PACKAGE_VERSION_1000
217+
ENV SIMICS_BASE="/workspace/simics/simics-${PUBLIC_SIMICS_PACKAGE_VERSION_1000}/"
218+
# Add cargo and ispm to the path
219+
ENV PATH="/home/${USERNAME}/.cargo/bin:/workspace/simics/ispm:${PATH}"
211220

212221
# Install minimal runtime dependencies only
213222
# hadolint ignore=DL3004,SC3009
214223
RUN <<EOF
215224
set -e
216-
# Update system packages
217-
dnf -y update
218225

219226
# Install minimal runtime dependencies
220227
dnf -y install \
@@ -233,8 +240,13 @@ dnf clean all
233240
rm -rf /var/cache/dnf/* /tmp/* /var/tmp/*
234241
EOF
235242

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
243+
COPY --from=tsffs-dev /home/vscode/.bashrc /home/vscode/.bashrc
244+
COPY --from=tsffs-dev --chown=root:dev --chmod=775 /workspace /workspace
245+
COPY --from=tsffs-dev --chown=vscode:vscode ["/root/.config/Intel Simics Package Manager/", "/home/vscode/.config/Intel Simics Package Manager/"]
246+
# remove tsffs
247+
RUN rm -r /workspace/tsffs
248+
# fix perms
249+
RUN chmod 775 /workspace
239250

251+
USER vscode
240252
WORKDIR /workspace/projects/example

0 commit comments

Comments
 (0)