From ec697c401e2d2c6c59c7aab7755ccf6620861ca8 Mon Sep 17 00:00:00 2001 From: Martin Hafskjold Thoresen Date: Sat, 11 Jan 2025 15:23:11 +0100 Subject: Docker and just --- Dockerfile | 39 +++++++++++++++++++++++++++++++++++++++ justfile | 7 +++++++ static/main.js | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 justfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..132af07 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +FROM messense/rust-musl-cross:aarch64-musl AS base +RUN cargo install cargo-chef --locked + +####################### +FROM base AS planner +WORKDIR /app +##### +COPY Cargo.toml Cargo.toml +COPY Cargo.lock Cargo.lock +COPY ./src ./src +##### +RUN cargo chef prepare --recipe-path recipe.json + +####################### +FROM base AS builder +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook --release --recipe-path recipe.json +##### +COPY Cargo.toml Cargo.toml +COPY Cargo.lock Cargo.lock +COPY ./src ./src +COPY ./static ./static +##### +RUN cargo build --release + +####################### +FROM --platform=linux/aarch64 alpine:3.20 + +RUN apk add --no-cache curl ca-certificates +COPY --from=builder /home/rust/src/target/aarch64-unknown-linux-musl/release/musicgame /app/server +COPY ./static /app/static + +ENV PATH="${PATH}:/app" +ENV STATIC_DIR="/app/static/" +ENV STAGE="prod" + +WORKDIR "/app" + +EXPOSE 4800 diff --git a/justfile b/justfile new file mode 100644 index 0000000..6bd8d71 --- /dev/null +++ b/justfile @@ -0,0 +1,7 @@ + +build-image: + docker build . -t musicgame --platform linux/aarch64 + +push-image: + docker save musicgame | bzip2 | ssh mhtwtf docker load + ssh mhtwtf "docker run --entrypoint '/app/server' -p 4001:4800 -dt musicgame" diff --git a/static/main.js b/static/main.js index 183b117..6b092fa 100644 --- a/static/main.js +++ b/static/main.js @@ -8,7 +8,7 @@ function getContext() { async function loadSample(url) { const res = await fetch(url); - const buffer = res.arrayBuffer(); + const buffer = await res.arrayBuffer(); return getContext().decodeAudioData(buffer); } -- cgit v1.2.3