Skip to content

Commit cbee0b7

Browse files
authored
feat: install Python and Node packages in container (#1220)
Python, Node, and Ruby packages were all installed in the local workspace at runtime. This slows down initial runs and creates the potential for people to use different versions of packages (the Node lock file was not actually being used). It also creates permissions issues when switching between different container runtimes (I've been switching between Podman and the Devcontainer lately). This installs the Python and Node packages in the container and updates the `npm` installation process to actually use `package-lock.json`. ~~I haven't tested with Singularity~~ (I'm a Podman/Docker user), but everything is passing with Podman locally. I'll follow up with another PR later to migrate some of the Ruby packages to the container as well, but that one is trickier because some of the Ruby packages are local to the UDB project.
1 parent 246914d commit cbee0b7

File tree

21 files changed

+67
-62
lines changed

21 files changed

+67
-62
lines changed

.devcontainer/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,19 @@ RUN apt-get clean autoclean
4242
RUN apt-get autoremove -y
4343
RUN rm -rf /var/lib/{apt,dpkg,cache,log}/*
4444

45+
# Create Python virtual environment and install packages
46+
COPY requirements.txt /tmp/requirements.txt
47+
RUN /usr/bin/python3 -m venv /opt/venv && \
48+
/opt/venv/bin/pip install -r /tmp/requirements.txt && \
49+
rm /tmp/requirements.txt
50+
ENV PATH="/opt/venv/bin:$PATH"
51+
52+
# Install npm packages globally in the container
53+
COPY package.json package-lock.json /opt/node/
54+
RUN cd /opt/node && \
55+
/usr/bin/npm ci && \
56+
rm /opt/node/package.json /opt/node/package-lock.json
57+
ENV NODE_PATH="/opt/node/node_modules"
58+
ENV PATH="/opt/node/node_modules/.bin:$PATH"
59+
4560
WORKDIR /workspace

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "RISC-V UnifiedDB Dev",
3-
"build": { "dockerfile": "Dockerfile" },
3+
"build": { "dockerfile": "Dockerfile", "context": ".." },
44
"updateContentCommand": "${containerWorkspaceFolder}/.devcontainer/updateContentCommand.sh",
55
"onCreateCommand": "${containerWorkspaceFolder}/.devcontainer/onCreateCommand.sh",
66
"remoteEnv": {

.devcontainer/onCreateCommand.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
#!/bin/bash
22

3-
npm i
43
bundle install

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ namespace :test do
119119
# "Run the cross-validation against LLVM"
120120
task :llvm do
121121
begin
122-
sh "#{$root}/.home/.venv/bin/python3 -m pytest ext/auto-inst/test_parsing.py -v"
122+
sh "/opt/venv/bin/python3 -m pytest ext/auto-inst/test_parsing.py -v"
123123
rescue => e
124124
raise unless e.message.include?("status (5)") # don't fail on skipped tests
125125
end

backends/cfg_html_doc/html_gen.rake

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ rule %r{#{$root}/gen/cfg_html_doc/.*/antora/playbook.yaml} => proc { |tname|
119119
snapshot: true
120120
supplemental_files:
121121
- path: css/vendor/tabs.css
122-
contents: #{$root}/node_modules/@asciidoctor/tabs/dist/css/tabs.css
122+
contents: /opt/node/node_modules/@asciidoctor/tabs/dist/css/tabs.css
123123
- path: js/vendor/tabs.js
124-
contents: #{$root}/node_modules/@asciidoctor/tabs/dist/js/tabs.js
124+
contents: /opt/node/node_modules/@asciidoctor/tabs/dist/js/tabs.js
125125
- path: partials/footer-scripts.hbs
126126
contents: |
127127
<script id="site-script" src="{{{uiRootPath}}}/js/site.js" data-ui-root-path="{{{uiRootPath}}}"></script>
@@ -234,10 +234,9 @@ rule %r{#{$root}/\.stamps/html-gen-.*\.stamp} => proc { |tname|
234234
playbook_path = $root / "gen" / "cfg_html_doc" / config_name / "antora" / "playbook.yaml"
235235
Rake::Task[playbook_path].invoke
236236

237-
$logger.info "Running Antora under npm to create #{config_name}"
238-
237+
$logger.info "Running Antora to create #{config_name}"
239238
sh [
240-
"npm exec -- antora",
239+
"/opt/node/node_modules/.bin/antora",
241240
"--stacktrace",
242241
"generate",
243242
"--cache-dir=#{$root}/.home/.antora",
@@ -247,7 +246,7 @@ rule %r{#{$root}/\.stamps/html-gen-.*\.stamp} => proc { |tname|
247246
playbook_path
248247
].join(" ")
249248

250-
$logger.info "Done running Antora under npm to create #{config_name}"
249+
$logger.info "Done running Antora to create #{config_name}"
251250

252251
FileUtils.touch t.name
253252
end

backends/ext_pdf_doc/tasks.rake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ rule %r{#{$resolver.gen_path}/ext_pdf_doc/.*/pdf/.*_extension\.pdf} => proc { |t
3434
"-a pdf-theme=#{ENV['THEME']}",
3535
"-a pdf-fontsdir=#{$root}/ext/docs-resources/fonts",
3636
"-a imagesdir=#{$root}/ext/docs-resources/images",
37-
"-a wavedrom=#{$root}/node_modules/.bin/wavedrom-cli",
37+
"-a wavedrom=/opt/node/node_modules/.bin/wavedrom-cli",
3838
"-r asciidoctor-diagram",
3939
"-r idl_highlighter",
4040
"-o #{t.name}",
@@ -63,7 +63,7 @@ rule %r{#{$resolver.gen_path}/ext_pdf_doc/.*/html/.*_extension\.html} => proc {
6363
"-v",
6464
"-a toc",
6565
"-r asciidoctor-diagram",
66-
"-a wavedrom=#{$root}/node_modules/.bin/wavedrom-cli",
66+
"-a wavedrom=/opt/node/node_modules/.bin/wavedrom-cli",
6767
"-o #{t.name}",
6868
adoc_file
6969
].join(" ")

backends/generators/tasks.rake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ namespace :gen do
2828
inst_dir = cfg_arch.path / "inst"
2929
csr_dir = cfg_arch.path / "csr"
3030

31-
# Run the Go generator script using the same Python environment
31+
# Run the Go generator script
3232
# Note: The script uses --output not --output-dir
33-
sh "#{$root}/.home/.venv/bin/python3 #{$root}/backends/generators/Go/go_generator.py --inst-dir=#{inst_dir} --csr-dir=#{csr_dir} --output=#{output_dir}inst.go"
33+
sh "/opt/venv/bin/python3 #{$root}/backends/generators/Go/go_generator.py --inst-dir=#{inst_dir} --csr-dir=#{csr_dir} --output=#{output_dir}inst.go"
3434
end
3535

3636
desc <<~DESC
@@ -79,9 +79,9 @@ namespace :gen do
7979
resolved_codes_file.flush
8080

8181
begin
82-
# Run the C header generator script using the same Python environment
82+
# Run the C header generator script
8383
# The script generates encoding.h for inclusion in C programs
84-
sh "#{$root}/.home/.venv/bin/python3 #{$root}/backends/generators/c_header/generate_encoding.py --inst-dir=#{inst_dir} --csr-dir=#{csr_dir} --ext-dir=#{ext_dir} --resolved-codes=#{resolved_codes_file.path} --output=#{output_dir}encoding.out.h --include-all"
84+
sh "/opt/venv/bin/python3 #{$root}/backends/generators/c_header/generate_encoding.py --inst-dir=#{inst_dir} --csr-dir=#{csr_dir} --ext-dir=#{ext_dir} --resolved-codes=#{resolved_codes_file.path} --output=#{output_dir}encoding.out.h --include-all"
8585
ensure
8686
resolved_codes_file.close
8787
resolved_codes_file.unlink

backends/instructions_appendix/all_instructions.golden.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
= Instruction Appendix
22
:doctype: book
3-
:wavedrom: /workspaces/riscv-unified-db/node_modules/.bin/wavedrom-cli
3+
:wavedrom: /opt/node/node_modules/.bin/wavedrom-cli
44
// Now the document header is complete and the wavedrom attribute is active.
55

66

backends/instructions_appendix/templates/instructions.adoc.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
= Instruction Appendix
22
:doctype: book
3-
:wavedrom: <%= $root %>/node_modules/.bin/wavedrom-cli
3+
:wavedrom: /opt/node/node_modules/.bin/wavedrom-cli
44
// Now the document header is complete and the wavedrom attribute is active.
55

66
<% instructions.sort_by(&:name).each do |inst| %>

backends/manual/tasks.rake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,10 @@ namespace :gen do
434434
playbook_path = MANUAL_GEN_DIR / ENV["MANUAL_NAME"] / "top" / output_hash / "antora" / "playbook" / "playbook.yml"
435435
Rake::Task[playbook_path].invoke
436436

437-
$logger.info "Running Antora under npm for HTML site to create '#{MANUAL_GEN_DIR / ENV['MANUAL_NAME'] / output_hash / 'html'}'"
437+
$logger.info "Running Antora for HTML site to create '#{MANUAL_GEN_DIR / ENV['MANUAL_NAME'] / output_hash / 'html'}'"
438438

439439
sh [
440-
"npm exec -- antora",
440+
"/opt/node/node_modules/.bin/antora",
441441
"--stacktrace",
442442
"generate",
443443
"--cache-dir=#{$root}/.home/.antora",
@@ -447,7 +447,7 @@ namespace :gen do
447447
playbook_path.to_s
448448
].join(" ")
449449

450-
$logger.info "Done running Antora under npm for HTML site to create '#{MANUAL_GEN_DIR / ENV['MANUAL_NAME'] / output_hash / 'html'}'"
450+
$logger.info "Done running Antora for HTML site to create '#{MANUAL_GEN_DIR / ENV['MANUAL_NAME'] / output_hash / 'html'}'"
451451
end
452452
end
453453

0 commit comments

Comments
 (0)