diff --git a/.dockerignore b/.dockerignore index f5284ad..919a0e7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,6 +5,7 @@ !/.cargo/ !/Cargo.toml !/crates/bevy_ws_server +!/crates/bevy_remote_asset !/crates/bevy_headless !/new_media/Cargo.toml !/new_media/src/** diff --git a/Dockerfile b/Dockerfile.dev similarity index 68% rename from Dockerfile rename to Dockerfile.dev index 4748d08..9829311 100644 --- a/Dockerfile +++ b/Dockerfile.dev @@ -1,41 +1,37 @@ +# Prepare FROM rust as planner WORKDIR /app RUN cargo install cargo-chef COPY . . RUN cargo chef prepare --recipe-path recipe.json +# Cook FROM rust as cacher WORKDIR /app RUN cargo install cargo-chef COPY --from=planner /app/recipe.json recipe.json -# Build tools RUN apt-get update && apt-get install -y -qq xorg xauth RUN cargo chef cook --release --features docker --recipe-path=recipe.json +# Build FROM rust as builder COPY . /app WORKDIR /app COPY --from=cacher /app/target target COPY --from=cacher /usr/local/cargo /usr/local/cargo -# Build tools RUN apt-get update && apt-get install -y -qq xorg xauth RUN cargo build --release --features docker +# RUN FROM ubuntu:22.04 COPY --from=builder /app/target/release/new_media /app/new_media WORKDIR /app - # Build tools -RUN apt-get update -RUN apt-get install -y -qq build-essential software-properties-common pkg-config xorg openbox xauth -# Bevy dependencies +RUN apt-get update && apt-get install -y -qq xorg xauth +# Bevy dependencies RUN DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -yq libasound2-dev libudev-dev libxkbcommon-x11-0 -RUN apt-get update -y -qq -RUN add-apt-repository ppa:kisak/turtle -y -RUN apt-get update -RUN apt install -y xvfb libegl1-mesa libgl1-mesa-dri libxcb-xfixes0-dev mesa-vulkan-drivers -ENV CARGO_TARGET_DIR="../rust-target" -ENV PATH="/root/.cargo/bin:${PATH}" +# Graphics +RUN apt-get update && apt install -y xvfb libegl1-mesa libgl1-mesa-dri libxcb-xfixes0-dev mesa-vulkan-drivers EXPOSE 8080 diff --git a/Dockerfile.prod b/Dockerfile.prod new file mode 100644 index 0000000..dbe629f --- /dev/null +++ b/Dockerfile.prod @@ -0,0 +1,38 @@ +# Prepare +FROM rust as planner +WORKDIR /app +RUN cargo install cargo-chef +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +# Cook +FROM rust as cacher +WORKDIR /app +RUN cargo install cargo-chef +COPY --from=planner /app/recipe.json recipe.json +RUN apt-get update && apt-get install -y -qq xorg xauth +RUN cargo chef cook --release --features docker --recipe-path=recipe.json + +# Build +FROM rust as builder +COPY . /app +WORKDIR /app +COPY --from=cacher /app/target target +COPY --from=cacher /usr/local/cargo /usr/local/cargo +RUN apt-get update && apt-get install -y -qq xorg xauth +RUN cargo build --release --features docker + +# RUN +FROM ubuntu:22.04 +COPY --from=builder /app/target/release/new_media /app/new_media +WORKDIR /app +# Build tools +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq xorg xauth +# Bevy dependencies +RUN DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -yq libasound2-dev libudev-dev libxkbcommon-x11-0 +# Graphics +RUN apt-get update && apt install -y xvfb libegl1-mesa libgl1-mesa-dri libxcb-xfixes0-dev mesa-vulkan-drivers + +EXPOSE 8080 + +CMD xvfb-run -s "-screen 0 1024x768x24" "./new_media" \ No newline at end of file diff --git a/README.md b/README.md index 98baed6..a58c544 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,4 @@ - run web: `pnpm --dir=demo dev` -- run server: `docker run -it -p 8080:8080 $(docker build -q .)` +- run server: `docker run -it -p 8080:8080 $(docker build -f Dockerfile.dev -q .)` diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..c451701 --- /dev/null +++ b/fly.toml @@ -0,0 +1,19 @@ +app = 'new-media-still-surf-1038' +primary_region = 'sjc' + +[build] + dockerfile = 'Dockerfile.prod' + +[http_service] + internal_port = 8080 + force_https = true + auto_stop_machines = true + auto_start_machines = true + min_machines_running = 0 + processes = ['app'] + +[[vm]] + cpu_kind = 'performance' + memory = '64gb' + cpus = 16 + size = "a100-40gb" \ No newline at end of file