Update Dockerfile
Browse files- Dockerfile +64 -112
Dockerfile
CHANGED
@@ -1,123 +1,75 @@
|
|
1 |
-
# ベースイメージ
|
2 |
FROM node:20
|
3 |
|
4 |
-
# bash
|
5 |
-
RUN apt-get update && apt-get install -y
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
# Rustツールチェーンや wasm-bindgen などがインストール済である必要あり
|
8 |
-
# (必要ならここに rustup/cargo/wasm-opt/wasm-snip などのインストールを追加)
|
9 |
-
|
10 |
-
# 作業ディレクトリ
|
11 |
WORKDIR /app
|
12 |
COPY . .
|
13 |
|
14 |
-
#
|
15 |
-
RUN bash -c '
|
16 |
-
set -euo pipefail
|
17 |
-
shopt -s inherit_errexit
|
18 |
-
|
19 |
-
which cargo wasm-bindgen wasm-opt wasm-snip &> /dev/null || {
|
20 |
-
echo "Please install cargo, wasm-bindgen, wasm-opt from https://github.com/WebAssembly/binaryen, and wasm-snip from https://github.com/r58playz/wasm-snip!"
|
21 |
-
exit 1
|
22 |
-
}
|
23 |
-
|
24 |
-
WBG="wasm-bindgen 0.2.100"
|
25 |
-
if ! [[ "$(wasm-bindgen -V)" =~ ^"$WBG" ]]; then
|
26 |
-
echo "Incorrect wasm-bindgen-cli version: '\''$(wasm-bindgen -V)'\'' != '\''$WBG'\''"
|
27 |
-
exit 1
|
28 |
-
fi
|
29 |
-
|
30 |
-
if ! [ "${RELEASE:-0}" = "1" ]; then
|
31 |
-
WASMOPTFLAGS="${WASMOPTFLAGS:-} -g"
|
32 |
-
FEATURES="debug,${FEATURES:-}"
|
33 |
-
else
|
34 |
-
: "${WASMOPTFLAGS:=}"
|
35 |
-
: "${FEATURES:=}"
|
36 |
-
fi
|
37 |
-
|
38 |
-
cd rewriter/wasm
|
39 |
-
export RUSTFLAGS="-Zlocation-detail=none -Zfmt-debug=none"
|
40 |
-
if [ "${OPTIMIZE_FOR_SIZE:-0}" = "1" ]; then
|
41 |
-
export RUSTFLAGS="${RUSTFLAGS} -C opt-level=z"
|
42 |
-
fi
|
43 |
-
|
44 |
-
STD_FEATURES="panic_immediate_abort"
|
45 |
-
if [ "${OPTIMIZE_FOR_SPEED:-0}" = "0" ]; then
|
46 |
-
STD_FEATURES="${STD_FEATURES},optimize_for_size"
|
47 |
-
fi
|
48 |
-
|
49 |
-
cargo build --release --target wasm32-unknown-unknown \
|
50 |
-
-Z build-std=panic_abort,std -Z build-std-features=${STD_FEATURES} \
|
51 |
-
--no-default-features --features "$FEATURES"
|
52 |
-
|
53 |
-
wasm-bindgen --target web --out-dir out/ ../target/wasm32-unknown-unknown/release/wasm.wasm
|
54 |
-
|
55 |
-
if [[ "$OSTYPE" == "darwin"* || "$OSTYPE" == "freebsd"* || "$OSTYPE" == "dragonfly"* ]]; then
|
56 |
-
sed -i "" "s/import.meta.url/\"\"/g" out/wasm.js
|
57 |
-
else
|
58 |
-
sed -i "s/import.meta.url/\"\"/g" out/wasm.js
|
59 |
-
fi
|
60 |
-
|
61 |
-
cd ../../
|
62 |
-
|
63 |
-
wasm-snip rewriter/wasm/out/wasm_bg.wasm -o rewriter/wasm/out/wasm_snipped.wasm \
|
64 |
-
-p '\''oxc_regular_expression::.*'\'' \
|
65 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_non_array_type'\'' \
|
66 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_import_type'\'' \
|
67 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_operator_or_higher'\'' \
|
68 |
-
'\''oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::parse_ts_interface_declaration'\'' \
|
69 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_mapped_type'\'' \
|
70 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_index_signature_declaration'\'' \
|
71 |
-
'\''oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::parse_ts_import_equals_declaration'\'' \
|
72 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_or_type_predicate'\'' \
|
73 |
-
'\''oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::parse_ts_namespace_or_module_declaration_body'\'' \
|
74 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_implements_clause'\'' \
|
75 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_intersection_type_or_higher'\'' \
|
76 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_type_name'\'' \
|
77 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_literal_type_node'\'' \
|
78 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_asserts_type_predicate'\'' \
|
79 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_tuple_element_type'\'' \
|
80 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_arguments_of_type_reference'\'' \
|
81 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_call_signature_member'\'' \
|
82 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::is_start_of_type'\'' \
|
83 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_this_type_predicate'\'' \
|
84 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_query'\'' \
|
85 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_reference'\'' \
|
86 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_operator'\'' \
|
87 |
-
'\''oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_literal'\'' \
|
88 |
-
'\''oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::is_at_enum_declaration'\'' \
|
89 |
-
'\''oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_element'\'' \
|
90 |
-
'\''oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_identifier'\'' \
|
91 |
-
'\''oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_element_name'\'' \
|
92 |
-
'\''oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_children'\'' \
|
93 |
-
'\''oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_fragment'\'' \
|
94 |
-
'\''oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_expression_container'\'' \
|
95 |
-
'\''oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_expression'\''
|
96 |
-
|
97 |
-
if [ "${RELEASE:-0}" = "1" ]; then
|
98 |
-
G="--generate-global-effects"
|
99 |
-
time wasm-opt $WASMOPTFLAGS \
|
100 |
-
rewriter/wasm/out/wasm_snipped.wasm -o rewriter/wasm/out/optimized.wasm \
|
101 |
-
--converge -tnh --vacuum \
|
102 |
-
$G -O4 $G --flatten $G --rereloop $G -O4 $G -O4 $G -O4 \
|
103 |
-
$G -Oz $G --flatten $G --rereloop $G -Oz $G -Oz $G -Oz \
|
104 |
-
$G --code-folding $G --const-hoisting $G --dae $G --flatten $G --merge-locals \
|
105 |
-
$G -O4 $G --flatten $G --rereloop $G -O4 $G -O4 $G -O4 \
|
106 |
-
$G -Oz $G --flatten $G --rereloop $G -Oz $G -Oz $G -Oz
|
107 |
-
else
|
108 |
-
cp rewriter/wasm/out/wasm_snipped.wasm rewriter/wasm/out/optimized.wasm
|
109 |
-
fi
|
110 |
-
|
111 |
-
mkdir -p dist
|
112 |
-
cp rewriter/wasm/out/optimized.wasm dist/scramjet.wasm.wasm
|
113 |
-
|
114 |
-
echo "Rewriter Build Complete!"
|
115 |
-
'
|
116 |
-
|
117 |
RUN npm install -g pnpm
|
|
|
|
|
118 |
RUN pnpm install
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
RUN pnpm build
|
120 |
|
|
|
121 |
EXPOSE 1337
|
122 |
-
|
123 |
-
CMD ["pnpm", "dev"]
|
|
|
|
|
1 |
FROM node:20
|
2 |
|
3 |
+
# bashとビルドツールをインストール
|
4 |
+
RUN apt-get update && apt-get install -y \
|
5 |
+
bash \
|
6 |
+
curl \
|
7 |
+
build-essential \
|
8 |
+
clang \
|
9 |
+
cmake \
|
10 |
+
git \
|
11 |
+
pkg-config \
|
12 |
+
libssl-dev
|
13 |
+
|
14 |
+
# 必要ならここでRustとツールチェーンをインストール
|
15 |
+
# RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
|
16 |
+
# ENV PATH="/root/.cargo/bin:${PATH}"
|
17 |
+
# RUN cargo install wasm-bindgen-cli wasm-opt wasm-snip
|
18 |
|
|
|
|
|
|
|
|
|
19 |
WORKDIR /app
|
20 |
COPY . .
|
21 |
|
22 |
+
# pnpmをグローバルにインストール
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
RUN npm install -g pnpm
|
24 |
+
|
25 |
+
# 依存インストール
|
26 |
RUN pnpm install
|
27 |
+
|
28 |
+
# build.shの内容を直接実行する(RUNは分割して記述)
|
29 |
+
RUN bash -c "\
|
30 |
+
set -euo pipefail && \
|
31 |
+
export WBG='wasm-bindgen 0.2.100' && \
|
32 |
+
if ! command -v cargo wasm-bindgen wasm-opt wasm-snip &>/dev/null; then \
|
33 |
+
echo 'Please install cargo, wasm-bindgen, wasm-opt, and wasm-snip!'; exit 1; \
|
34 |
+
fi && \
|
35 |
+
if ! [[ \"$(wasm-bindgen -V)\" =~ ^\"$WBG\" ]]; then \
|
36 |
+
echo \"Incorrect wasm-bindgen version: $(wasm-bindgen -V) != $WBG\"; exit 1; \
|
37 |
+
fi && \
|
38 |
+
cd rewriter/wasm && \
|
39 |
+
export RUSTFLAGS='-Zlocation-detail=none -Zfmt-debug=none' && \
|
40 |
+
if [ \"${OPTIMIZE_FOR_SIZE:-0}\" = \"1\" ]; then \
|
41 |
+
export RUSTFLAGS=\"${RUSTFLAGS} -C opt-level=z\"; \
|
42 |
+
fi && \
|
43 |
+
STD_FEATURES='panic_immediate_abort' && \
|
44 |
+
if [ \"${OPTIMIZE_FOR_SPEED:-0}\" = \"0\" ]; then \
|
45 |
+
STD_FEATURES=\"${STD_FEATURES},optimize_for_size\"; \
|
46 |
+
fi && \
|
47 |
+
cargo build --release --target wasm32-unknown-unknown \
|
48 |
+
-Z build-std=panic_abort,std -Z build-std-features=${STD_FEATURES} \
|
49 |
+
--no-default-features --features \"debug,${FEATURES:-}\" && \
|
50 |
+
wasm-bindgen --target web --out-dir out/ ../target/wasm32-unknown-unknown/release/wasm.wasm && \
|
51 |
+
sed -i 's/import.meta.url/\"\"/g' out/wasm.js && \
|
52 |
+
cd ../../ && \
|
53 |
+
wasm-snip rewriter/wasm/out/wasm_bg.wasm -o rewriter/wasm/out/wasm_snipped.wasm \
|
54 |
+
-p 'oxc_regular_expression::.*' \
|
55 |
+
'oxc_parser::ts::.*' \
|
56 |
+
'oxc_parser::jsx::.*' && \
|
57 |
+
if [ \"${RELEASE:-0}\" = \"1\" ]; then \
|
58 |
+
G=\"--generate-global-effects\" && \
|
59 |
+
wasm-opt ${WASMOPTFLAGS:-} \
|
60 |
+
rewriter/wasm/out/wasm_snipped.wasm -o rewriter/wasm/out/optimized.wasm \
|
61 |
+
--converge -tnh --vacuum $G -O4 $G --flatten $G --rereloop $G -Oz $G \
|
62 |
+
--code-folding $G --const-hoisting $G --dae $G --merge-locals; \
|
63 |
+
else \
|
64 |
+
cp rewriter/wasm/out/wasm_snipped.wasm rewriter/wasm/out/optimized.wasm; \
|
65 |
+
fi && \
|
66 |
+
mkdir -p dist && \
|
67 |
+
cp rewriter/wasm/out/optimized.wasm dist/scramjet.wasm.wasm && \
|
68 |
+
echo 'Rewriter Build Complete!'"
|
69 |
+
|
70 |
+
# アプリのビルド
|
71 |
RUN pnpm build
|
72 |
|
73 |
+
# ポート開放と起動コマンド
|
74 |
EXPOSE 1337
|
75 |
+
CMD ["pnpm", "dev"]
|
|