Skip to content

Commit

Permalink
Docker build now working
Browse files Browse the repository at this point in the history
  • Loading branch information
rozbb committed Jun 17, 2022
1 parent cfddd09 commit 8401497
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
gcp_api.key
Dockerfile
/target
*.mp3
26 changes: 22 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,40 @@ RUN mkdir common/src && echo "fn main(){}" > common/src/main.rs
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/src/app/target \
cargo build --release
# Will install the tools needed to build the webapp
RUN cargo install --locked trunk cargo-watch wasm-bindgen-cli
RUN rustup target add wasm32-unknown-unknown

# Copy the rest
# Copy the rest.
COPY . .
# Build (install) the actual binaries
RUN ./scripts/prodbuild.sh
RUN RUSTFLAGS=--cfg=web_sys_unstable_apis ./scripts/prodbuild.sh

# Runtime image
FROM debian:bullseye-slim

# Need certs for talking to Google Cloud
RUN \
apt-get update && \
apt-get install -y ca-certificates && \
apt-get clean

# Run as "app" user
RUN useradd -ms /bin/bash app

USER app
WORKDIR /app

# Get compiled binaries from builder's cargo install directory
COPY --from=builder /usr/local/cargo/bin/readtomyshoe-server /app/readtomyshoe-server
# The binary and the blobs dir need to be in server/
RUN mkdir server
RUN mkdir server/audio_blobs

# Get compiled binaries and assets from the builder's cargo install directory
COPY --from=builder /usr/src/app/dist /app/dist
COPY --from=builder /usr/local/cargo/bin/readtomyshoe-server /app/server/readtomyshoe-server

# Copy the API key
# NOTE: This is a secret value!
COPY ./server/gcp_api.key ./server/

# No CMD or ENTRYPOINT, see fly.toml with `cmd` override.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ You need to have OpenSSL installed on your machine. For Ubuntu, just `sudo apt i
This requires a custom version of everything related wasm-bindgen because the `MediaSession` API has not yet been merged into `web_sys`. Do the following:

* `cargo install --locked trunk cargo-watch wasm-bindgen-cli`
* `rustup target add wasm32-unknown-unknown`
* Set the following in `~/.cargo/config`. This is because `web_sys` gates unstable features via cfg. I know this is very weird.
```
[build]
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ fn main() {
console_error_panic_hook::set_once();
tracing_wasm::set_as_global_default();

//caching::register_service_worker();
caching::register_service_worker();
yew::start_app::<App>();
}
3 changes: 3 additions & 0 deletions scripts/build_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

DOCKER_BUILDKIT=1 docker build -t readtomyshoe .

0 comments on commit 8401497

Please sign in to comment.