Skip to content

Commit ff0a617

Browse files
Merge pull request RustPython#1155 from RustPython/coolreader18/better-dockerfile
Update Dockerfiles
2 parents b7e085e + 97c9b23 commit ff0a617

File tree

8 files changed

+315
-291
lines changed

8 files changed

+315
-291
lines changed

.dockerignore

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
1-
target
2-
**/node_modules
1+
**/target/
2+
**/*.rs.bk
3+
**/*.bytecode
4+
**/__pycache__/*
5+
**/*.pytest_cache
6+
.*sw*
7+
.repl_history.txt
8+
.vscode
9+
wasm-pack.log
10+
.idea/
11+
tests/snippets/resources
12+
13+
flame-graph.html
14+
flame.txt
15+
flamescope.json
16+
17+
**/node_modules/
18+
wasm/**/dist/
19+
wasm/lib/pkg/

Cargo.lock

Lines changed: 193 additions & 227 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile.bin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM rust:1.31-slim
1+
FROM rust:1.36-slim
22

33
WORKDIR /rustpython
44

Dockerfile.wasm

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,45 @@
1-
FROM rust:1.31-slim
2-
3-
RUN apt-get update && apt-get install curl gnupg -y && \
4-
curl -o- https://deb.nodesource.com/setup_10.x | bash && \
5-
apt-get install nodejs -y && \
6-
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh && \
7-
npm i -g serve
1+
FROM rust:1.36-slim AS rust
82

93
WORKDIR /rustpython
104

11-
COPY . .
5+
USER root
6+
ENV USER=root
7+
8+
9+
RUN apt-get update && apt-get install curl libssl-dev pkg-config -y && \
10+
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
11+
12+
COPY Cargo.toml Cargo.lock ./
13+
COPY src src
14+
COPY vm vm
15+
COPY derive derive
16+
COPY parser parser
17+
COPY bytecode bytecode
18+
COPY compiler compiler
19+
COPY wasm/lib wasm/lib
20+
21+
RUN cd wasm/lib/ && wasm-pack build --release
22+
23+
24+
FROM node:alpine AS node
25+
26+
WORKDIR /rustpython-demo
27+
28+
COPY --from=rust /rustpython/wasm/lib/pkg rustpython_wasm
29+
30+
COPY wasm/demo .
31+
32+
RUN npm install && npm run dist -- --env.noWasmPack --env.rustpythonPkg=rustpython_wasm
33+
34+
35+
FROM node:slim
36+
37+
WORKDIR /rustpython-demo
38+
39+
RUN npm i -g serve
40+
41+
COPY --from=node /rustpython-demo/dist .
1242

13-
RUN cd ./wasm/lib/ && \
14-
cargo build --release && \
15-
cd ../demo && \
16-
npm install && \
17-
npm run dist
43+
CMD [ "serve", "-l", "80", "/rustpython-demo" ]
1844

19-
CMD [ "serve", "/rustpython/wasm/demo/dist" ]
45+
EXPOSE 80

wasm/.prettierrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"singleQuote": true,
3-
"tabWidth": 4
2+
"singleQuote": true,
3+
"tabWidth": 4
44
}

wasm/demo/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"main": "index.js",
66
"dependencies": {
77
"codemirror": "^5.42.0",
8-
"serve": "^11.0.2",
98
"xterm": "^3.8.0"
109
},
1110
"devDependencies": {
@@ -18,7 +17,8 @@
1817
"webpack": "^4.16.3",
1918
"webpack-cli": "^3.1.0",
2019
"webpack-dev-server": "^3.1.5",
21-
"start-server-and-test": "^1.7.11"
20+
"start-server-and-test": "^1.7.11",
21+
"serve": "^11.0.2"
2222
},
2323
"scripts": {
2424
"dev": "webpack-dev-server -d",

wasm/demo/src/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as rp from '../../lib/pkg';
1+
import * as rp from 'rustpython';
22
import CodeMirror from 'codemirror';
33
import 'codemirror/mode/python/python';
44
import 'codemirror/addon/comment/comment';

wasm/demo/webpack.config.js

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,64 @@ const fs = require('fs');
66

77
const interval = setInterval(() => console.log('keepalive'), 1000 * 60 * 5);
88

9-
module.exports = {
10-
entry: './src/index.js',
11-
output: {
12-
path: path.join(__dirname, 'dist'),
13-
filename: 'index.js'
14-
},
15-
mode: 'development',
16-
module: {
17-
rules: [
18-
{
19-
test: /\.css$/,
20-
use: [MiniCssExtractPlugin.loader, 'css-loader']
21-
}
22-
]
23-
},
24-
plugins: [
25-
new HtmlWebpackPlugin({
26-
filename: 'index.html',
27-
template: 'src/index.ejs',
28-
templateParameters: {
29-
snippets: fs
30-
.readdirSync(path.join(__dirname, 'snippets'))
31-
.map(filename =>
32-
path.basename(filename, path.extname(filename))
33-
),
34-
defaultSnippetName: 'fibonacci',
35-
defaultSnippet: fs.readFileSync(
36-
path.join(__dirname, 'snippets/fibonacci.py')
9+
module.exports = (env = {}) => {
10+
const config = {
11+
entry: './src/index.js',
12+
output: {
13+
path: path.join(__dirname, 'dist'),
14+
filename: 'index.js'
15+
},
16+
mode: 'development',
17+
resolve: {
18+
alias: {
19+
rustpython: path.resolve(
20+
__dirname,
21+
env.rustpythonPkg || '../lib/pkg'
3722
)
3823
}
39-
}),
40-
new MiniCssExtractPlugin({
41-
filename: 'styles.css'
42-
}),
43-
new WasmPackPlugin({
44-
crateDirectory: path.join(__dirname, '../lib')
45-
}),
46-
{
47-
apply(compiler) {
48-
compiler.hooks.done.tap('clearInterval', () => {
49-
clearInterval(interval);
50-
});
24+
},
25+
module: {
26+
rules: [
27+
{
28+
test: /\.css$/,
29+
use: [MiniCssExtractPlugin.loader, 'css-loader']
30+
}
31+
]
32+
},
33+
plugins: [
34+
new HtmlWebpackPlugin({
35+
filename: 'index.html',
36+
template: 'src/index.ejs',
37+
templateParameters: {
38+
snippets: fs
39+
.readdirSync(path.join(__dirname, 'snippets'))
40+
.map(filename =>
41+
path.basename(filename, path.extname(filename))
42+
),
43+
defaultSnippetName: 'fibonacci',
44+
defaultSnippet: fs.readFileSync(
45+
path.join(__dirname, 'snippets/fibonacci.py')
46+
)
47+
}
48+
}),
49+
new MiniCssExtractPlugin({
50+
filename: 'styles.css'
51+
}),
52+
{
53+
apply(compiler) {
54+
compiler.hooks.done.tap('clearInterval', () => {
55+
clearInterval(interval);
56+
});
57+
}
5158
}
52-
}
53-
]
59+
]
60+
};
61+
if (!env.noWasmPack) {
62+
config.plugins.push(
63+
new WasmPackPlugin({
64+
crateDirectory: path.join(__dirname, '../lib')
65+
})
66+
);
67+
}
68+
return config;
5469
};

0 commit comments

Comments
 (0)