Seems a bit unnecessary to have Python as a dependency of for the build workspace script, so I ported it to Rust. The image size is reduced by ~45 MB:
❯ docker image ls | head -3
REPOSITORY TAG IMAGE ID CREATED SIZE
cosmwasm/workspace-optimizer 0.12.2 fd685a78ecf2 48 seconds ago 925MB
cosmwasm/workspace-optimizer 0.12.2_rust_port e914e7830468 2 minutes ago 879MB
Comparison of 0.12.2_rust_port and 0.12.2 output, showing that the same binaries are produced
```
❯ docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/workspace-optimizer:0.12.2_rust_port
1.54.0-aarch64-unknown-linux-musl (default)
cargo 1.54.0 (5ae8d74b3 2021-06-22)
Building artifacts in workspace ...
Found workspace member entries: ["packages/*", "contracts/*"]
Package directories: ["contracts/terraswap_factory", "contracts/terraswap_pair", "contracts/terraswap_router", "contracts/terraswap_token", "packages/terraswap"]
Contracts to be built: ["contracts/terraswap_factory", "contracts/terraswap_pair", "contracts/terraswap_router", "contracts/terraswap_token"]
Building "contracts/terraswap_factory" ...
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_factory/Cargo.toml
workspace: /code/Cargo.toml
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_pair/Cargo.toml
workspace: /code/Cargo.toml
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_router/Cargo.toml
workspace: /code/Cargo.toml
Finished release [optimized] target(s) in 0.91s
Building "contracts/terraswap_pair" ...
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_factory/Cargo.toml
workspace: /code/Cargo.toml
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_pair/Cargo.toml
workspace: /code/Cargo.toml
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_router/Cargo.toml
workspace: /code/Cargo.toml
Compiling terraswap-pair v1.2.0 (/code/contracts/terraswap_pair)
Finished release [optimized] target(s) in 4.19s
Building "contracts/terraswap_router" ...
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_factory/Cargo.toml
workspace: /code/Cargo.toml
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_pair/Cargo.toml
workspace: /code/Cargo.toml
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_router/Cargo.toml
workspace: /code/Cargo.toml
Compiling terraswap-router v1.2.0 (/code/contracts/terraswap_router)
Finished release [optimized] target(s) in 4.57s
Building "contracts/terraswap_token" ...
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_factory/Cargo.toml
workspace: /code/Cargo.toml
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_pair/Cargo.toml
workspace: /code/Cargo.toml
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_router/Cargo.toml
workspace: /code/Cargo.toml
Compiling terraswap-token v1.2.0 (/code/contracts/terraswap_token)
Finished release [optimized] target(s) in 4.21s
Creating intermediate hashes ...
d802f3d64578aefd26242cd2b8e06bb77f064111375056c0ab166ac49e60a1d3 target/wasm32-unknown-unknown/release/terraswap_factory.wasm
6974f36e514ca19cbe07b8b0fe290c982027b613ead4f2b8f9aca69208477624 target/wasm32-unknown-unknown/release/terraswap_pair.wasm
47c347eacd1902dc24a59dae5e74901d6fdfbaae6a981cafe2325e454594baab target/wasm32-unknown-unknown/release/terraswap_router.wasm
9c63a3edc2be8e6dc91ea29e7db0265b13f768575da2caa65ea5b45701290f0f target/wasm32-unknown-unknown/release/terraswap_token.wasm
Optimizing artifacts in workspace ...
Optimizing ../target/wasm32-unknown-unknown/release/terraswap_factory.wasm ...
Optimizing ../target/wasm32-unknown-unknown/release/terraswap_pair.wasm ...
Optimizing ../target/wasm32-unknown-unknown/release/terraswap_router.wasm ...
Optimizing ../target/wasm32-unknown-unknown/release/terraswap_token.wasm ...
Moving wasm files ...
Post-processing artifacts in workspace ...
a25ad28b91754a99cfeadcb8f7f6f0570a118378cbd284938620089b4ada5268 terraswap_factory.wasm
8c1ffa6dae8c769454159fb4ca7aeb218d64473b1ce7cf733a2bcfd917d2c499 terraswap_pair.wasm
d9ab1af0091cc4881ed46f56e5858657d92a17e4ec95af79f97a515871ad8fdd terraswap_router.wasm
9004e977a94804adbc1863217805e4e5c302eca0dcfa6dcfdd0e437a9a7108d2 terraswap_token.wasm
done
❯ docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/workspace-optimizer:0.12.2
1.54.0-aarch64-unknown-linux-musl (default)
cargo 1.54.0 (5ae8d74b3 2021-06-22)
Building artifacts in workspace ...
Found workspace member entries: ['packages/*', 'contracts/*']
Package directories: ['contracts/terraswap_factory', 'contracts/terraswap_pair', 'contracts/terraswap_router', 'contracts/terraswap_token', 'packages/terraswap']
Contracts to be built: ['contracts/terraswap_factory', 'contracts/terraswap_pair', 'contracts/terraswap_router', 'contracts/terraswap_token']
Building contracts/terraswap_factory ...
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_factory/Cargo.toml
workspace: /code/Cargo.toml
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_pair/Cargo.toml
workspace: /code/Cargo.toml
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_router/Cargo.toml
workspace: /code/Cargo.toml
Finished release [optimized] target(s) in 0.15s
Building contracts/terraswap_pair ...
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_factory/Cargo.toml
workspace: /code/Cargo.toml
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_pair/Cargo.toml
workspace: /code/Cargo.toml
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_router/Cargo.toml
workspace: /code/Cargo.toml
Finished release [optimized] target(s) in 0.11s
Building contracts/terraswap_router ...
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_factory/Cargo.toml
workspace: /code/Cargo.toml
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_pair/Cargo.toml
workspace: /code/Cargo.toml
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_router/Cargo.toml
workspace: /code/Cargo.toml
Finished release [optimized] target(s) in 0.12s
Building contracts/terraswap_token ...
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_factory/Cargo.toml
workspace: /code/Cargo.toml
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_pair/Cargo.toml
workspace: /code/Cargo.toml
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /code/contracts/terraswap_router/Cargo.toml
workspace: /code/Cargo.toml
Finished release [optimized] target(s) in 0.10s
Creating intermediate hashes ...
d802f3d64578aefd26242cd2b8e06bb77f064111375056c0ab166ac49e60a1d3 target/wasm32-unknown-unknown/release/terraswap_factory.wasm
6974f36e514ca19cbe07b8b0fe290c982027b613ead4f2b8f9aca69208477624 target/wasm32-unknown-unknown/release/terraswap_pair.wasm
47c347eacd1902dc24a59dae5e74901d6fdfbaae6a981cafe2325e454594baab target/wasm32-unknown-unknown/release/terraswap_router.wasm
9c63a3edc2be8e6dc91ea29e7db0265b13f768575da2caa65ea5b45701290f0f target/wasm32-unknown-unknown/release/terraswap_token.wasm
Optimizing artifacts in workspace ...
Optimizing ../target/wasm32-unknown-unknown/release/terraswap_factory.wasm ...
Optimizing ../target/wasm32-unknown-unknown/release/terraswap_pair.wasm ...
Optimizing ../target/wasm32-unknown-unknown/release/terraswap_router.wasm ...
Optimizing ../target/wasm32-unknown-unknown/release/terraswap_token.wasm ...
Moving wasm files ...
Post-processing artifacts in workspace ...
a25ad28b91754a99cfeadcb8f7f6f0570a118378cbd284938620089b4ada5268 terraswap_factory.wasm
8c1ffa6dae8c769454159fb4ca7aeb218d64473b1ce7cf733a2bcfd917d2c499 terraswap_pair.wasm
d9ab1af0091cc4881ed46f56e5858657d92a17e4ec95af79f97a515871ad8fdd terraswap_router.wasm
9004e977a94804adbc1863217805e4e5c302eca0dcfa6dcfdd0e437a9a7108d2 terraswap_token.wasm
done
```
Seems a bit unnecessary to have Python as a dependency of for the build workspace script, so I ported it to Rust. The image size is reduced by ~45 MB:
Comparison of 0.12.2_rust_port and 0.12.2 output, showing that the same binaries are produced
``` ❯ docker run --rm -v "$(pwd)":/code \ --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ cosmwasm/workspace-optimizer:0.12.2_rust_port 1.54.0-aarch64-unknown-linux-musl (default) cargo 1.54.0 (5ae8d74b3 2021-06-22) Building artifacts in workspace ... Found workspace member entries: ["packages/*", "contracts/*"] Package directories: ["contracts/terraswap_factory", "contracts/terraswap_pair", "contracts/terraswap_router", "contracts/terraswap_token", "packages/terraswap"] Contracts to be built: ["contracts/terraswap_factory", "contracts/terraswap_pair", "contracts/terraswap_router", "contracts/terraswap_token"] Building "contracts/terraswap_factory" ... warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_factory/Cargo.toml workspace: /code/Cargo.toml warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_pair/Cargo.toml workspace: /code/Cargo.toml warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_router/Cargo.toml workspace: /code/Cargo.toml Finished release [optimized] target(s) in 0.91s Building "contracts/terraswap_pair" ... warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_factory/Cargo.toml workspace: /code/Cargo.toml warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_pair/Cargo.toml workspace: /code/Cargo.toml warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_router/Cargo.toml workspace: /code/Cargo.toml Compiling terraswap-pair v1.2.0 (/code/contracts/terraswap_pair) Finished release [optimized] target(s) in 4.19s Building "contracts/terraswap_router" ... warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_factory/Cargo.toml workspace: /code/Cargo.toml warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_pair/Cargo.toml workspace: /code/Cargo.toml warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_router/Cargo.toml workspace: /code/Cargo.toml Compiling terraswap-router v1.2.0 (/code/contracts/terraswap_router) Finished release [optimized] target(s) in 4.57s Building "contracts/terraswap_token" ... warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_factory/Cargo.toml workspace: /code/Cargo.toml warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_pair/Cargo.toml workspace: /code/Cargo.toml warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_router/Cargo.toml workspace: /code/Cargo.toml Compiling terraswap-token v1.2.0 (/code/contracts/terraswap_token) Finished release [optimized] target(s) in 4.21s Creating intermediate hashes ... d802f3d64578aefd26242cd2b8e06bb77f064111375056c0ab166ac49e60a1d3 target/wasm32-unknown-unknown/release/terraswap_factory.wasm 6974f36e514ca19cbe07b8b0fe290c982027b613ead4f2b8f9aca69208477624 target/wasm32-unknown-unknown/release/terraswap_pair.wasm 47c347eacd1902dc24a59dae5e74901d6fdfbaae6a981cafe2325e454594baab target/wasm32-unknown-unknown/release/terraswap_router.wasm 9c63a3edc2be8e6dc91ea29e7db0265b13f768575da2caa65ea5b45701290f0f target/wasm32-unknown-unknown/release/terraswap_token.wasm Optimizing artifacts in workspace ... Optimizing ../target/wasm32-unknown-unknown/release/terraswap_factory.wasm ... Optimizing ../target/wasm32-unknown-unknown/release/terraswap_pair.wasm ... Optimizing ../target/wasm32-unknown-unknown/release/terraswap_router.wasm ... Optimizing ../target/wasm32-unknown-unknown/release/terraswap_token.wasm ... Moving wasm files ... Post-processing artifacts in workspace ... a25ad28b91754a99cfeadcb8f7f6f0570a118378cbd284938620089b4ada5268 terraswap_factory.wasm 8c1ffa6dae8c769454159fb4ca7aeb218d64473b1ce7cf733a2bcfd917d2c499 terraswap_pair.wasm d9ab1af0091cc4881ed46f56e5858657d92a17e4ec95af79f97a515871ad8fdd terraswap_router.wasm 9004e977a94804adbc1863217805e4e5c302eca0dcfa6dcfdd0e437a9a7108d2 terraswap_token.wasm done ❯ docker run --rm -v "$(pwd)":/code \ --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ cosmwasm/workspace-optimizer:0.12.2 1.54.0-aarch64-unknown-linux-musl (default) cargo 1.54.0 (5ae8d74b3 2021-06-22) Building artifacts in workspace ... Found workspace member entries: ['packages/*', 'contracts/*'] Package directories: ['contracts/terraswap_factory', 'contracts/terraswap_pair', 'contracts/terraswap_router', 'contracts/terraswap_token', 'packages/terraswap'] Contracts to be built: ['contracts/terraswap_factory', 'contracts/terraswap_pair', 'contracts/terraswap_router', 'contracts/terraswap_token'] Building contracts/terraswap_factory ... warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_factory/Cargo.toml workspace: /code/Cargo.toml warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_pair/Cargo.toml workspace: /code/Cargo.toml warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_router/Cargo.toml workspace: /code/Cargo.toml Finished release [optimized] target(s) in 0.15s Building contracts/terraswap_pair ... warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_factory/Cargo.toml workspace: /code/Cargo.toml warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_pair/Cargo.toml workspace: /code/Cargo.toml warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_router/Cargo.toml workspace: /code/Cargo.toml Finished release [optimized] target(s) in 0.11s Building contracts/terraswap_router ... warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_factory/Cargo.toml workspace: /code/Cargo.toml warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_pair/Cargo.toml workspace: /code/Cargo.toml warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_router/Cargo.toml workspace: /code/Cargo.toml Finished release [optimized] target(s) in 0.12s Building contracts/terraswap_token ... warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_factory/Cargo.toml workspace: /code/Cargo.toml warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_pair/Cargo.toml workspace: /code/Cargo.toml warning: profiles for the non root package will be ignored, specify profiles at the workspace root: package: /code/contracts/terraswap_router/Cargo.toml workspace: /code/Cargo.toml Finished release [optimized] target(s) in 0.10s Creating intermediate hashes ... d802f3d64578aefd26242cd2b8e06bb77f064111375056c0ab166ac49e60a1d3 target/wasm32-unknown-unknown/release/terraswap_factory.wasm 6974f36e514ca19cbe07b8b0fe290c982027b613ead4f2b8f9aca69208477624 target/wasm32-unknown-unknown/release/terraswap_pair.wasm 47c347eacd1902dc24a59dae5e74901d6fdfbaae6a981cafe2325e454594baab target/wasm32-unknown-unknown/release/terraswap_router.wasm 9c63a3edc2be8e6dc91ea29e7db0265b13f768575da2caa65ea5b45701290f0f target/wasm32-unknown-unknown/release/terraswap_token.wasm Optimizing artifacts in workspace ... Optimizing ../target/wasm32-unknown-unknown/release/terraswap_factory.wasm ... Optimizing ../target/wasm32-unknown-unknown/release/terraswap_pair.wasm ... Optimizing ../target/wasm32-unknown-unknown/release/terraswap_router.wasm ... Optimizing ../target/wasm32-unknown-unknown/release/terraswap_token.wasm ... Moving wasm files ... Post-processing artifacts in workspace ... a25ad28b91754a99cfeadcb8f7f6f0570a118378cbd284938620089b4ada5268 terraswap_factory.wasm 8c1ffa6dae8c769454159fb4ca7aeb218d64473b1ce7cf733a2bcfd917d2c499 terraswap_pair.wasm d9ab1af0091cc4881ed46f56e5858657d92a17e4ec95af79f97a515871ad8fdd terraswap_router.wasm 9004e977a94804adbc1863217805e4e5c302eca0dcfa6dcfdd0e437a9a7108d2 terraswap_token.wasm done ```