Skip to content

Commit

Permalink
feat: fly.io basic setup (#21)
Browse files Browse the repository at this point in the history
* refactor: Dockerfile for dev and prod

* refactor: basic fly.toml setup - gpu is not available on my account
  • Loading branch information
cs50victor authored Feb 17, 2024
1 parent 94fbf55 commit 7a7c04e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 13 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/**
Expand Down
20 changes: 8 additions & 12 deletions Dockerfile → Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -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

Expand Down
38 changes: 38 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 .)`
19 changes: 19 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 7a7c04e

Please sign in to comment.