-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deterministic builds using Docker (#69)
- Loading branch information
Showing
5 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,6 @@ dist/ | |
|
||
# environment variables | ||
.env | ||
|
||
# canister wasms | ||
wasms/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# To build run 'docker build . -t openchat' | ||
FROM ubuntu:22.04 as builder | ||
SHELL ["bash", "-c"] | ||
|
||
ARG git_commit_id | ||
ARG rust_version=1.76.0 | ||
|
||
ENV GIT_COMMIT_ID=$git_commit_id | ||
ENV TZ=UTC | ||
|
||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \ | ||
apt -yq update && \ | ||
apt -yqq install --no-install-recommends curl ca-certificates build-essential | ||
|
||
# Install Rust and Cargo in /opt | ||
ENV RUSTUP_HOME=/opt/rustup \ | ||
CARGO_HOME=/opt/cargo \ | ||
PATH=/cargo/bin:/opt/cargo/bin:$PATH | ||
|
||
RUN curl --fail https://sh.rustup.rs -sSf \ | ||
| sh -s -- -y --default-toolchain ${rust_version}-x86_64-unknown-linux-gnu --no-modify-path && \ | ||
rustup default ${rust_version}-x86_64-unknown-linux-gnu && \ | ||
rustup target add wasm32-unknown-unknown | ||
|
||
# Install IC Wasm | ||
RUN cargo install --version 0.7.1 ic-wasm | ||
|
||
COPY . /build | ||
WORKDIR /build | ||
|
||
RUN sh ./scripts/build-wasm.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
SCRIPT=$(readlink -f "$0") | ||
SCRIPT_DIR=$(dirname "$SCRIPT") | ||
cd $SCRIPT_DIR/.. | ||
|
||
CANISTER_NAME="event_store" | ||
PACKAGE="${CANISTER_NAME}_canister_impl" | ||
|
||
if [ -z "${CARGO_HOME}" ] | ||
then | ||
export CARGO_HOME="${HOME}/.cargo" | ||
fi | ||
|
||
if [ -z "${GIT_COMMIT_ID}" ] | ||
then | ||
export GIT_COMMIT_ID=$(git rev-parse HEAD) | ||
fi | ||
|
||
echo Building package $PACKAGE | ||
export RUSTFLAGS="--remap-path-prefix $(readlink -f ${SCRIPT_DIR}/..)=/build --remap-path-prefix ${CARGO_HOME}/bin=/cargo/bin --remap-path-prefix ${CARGO_HOME}/git=/cargo/git" | ||
for l in $(ls ${CARGO_HOME}/registry/src/) | ||
do | ||
export RUSTFLAGS="--remap-path-prefix ${CARGO_HOME}/registry/src/${l}=/cargo/registry/src/github ${RUSTFLAGS}" | ||
done | ||
cargo build --locked --target wasm32-unknown-unknown --release --package $PACKAGE | ||
|
||
echo Optimising wasm | ||
if ! cargo install --list | grep -Fxq "ic-wasm v0.7.1:" | ||
then | ||
cargo install --version 0.7.1 ic-wasm | ||
fi | ||
ic-wasm ./target/wasm32-unknown-unknown/release/$PACKAGE.wasm -o ./target/wasm32-unknown-unknown/release/$PACKAGE-opt.wasm shrink | ||
|
||
echo Compressing wasm | ||
mkdir -p wasms | ||
gzip -fckn target/wasm32-unknown-unknown/release/$PACKAGE-opt.wasm > ./wasms/$CANISTER_NAME.wasm.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
SCRIPT=$(readlink -f "$0") | ||
SCRIPT_DIR=$(dirname "$SCRIPT") | ||
cd $SCRIPT_DIR/.. | ||
|
||
GIT_COMMIT_ID=$(git rev-parse HEAD) | ||
|
||
echo "CommitId: $GIT_COMMIT_ID" | ||
|
||
docker build -t event_store --build-arg git_commit_id=$GIT_COMMIT_ID . | ||
|
||
container_id=$(docker create event_store) | ||
rm -rf wasms | ||
docker cp $container_id:/build/wasms wasms | ||
docker rm --volumes $container_id | ||
|
||
cd wasms | ||
for wasm in *; do | ||
shasum -a 256 "$wasm" | ||
done | ||
cd .. |