Skip to content

Commit

Permalink
add docker
Browse files Browse the repository at this point in the history
  • Loading branch information
mskasal committed Feb 17, 2024
1 parent b408cd5 commit ab43426
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 5 deletions.
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM rust:slim as builder
WORKDIR /app
COPY . .
RUN \
--mount=type=cache,target=/app/target/ \
--mount=type=cache,target=/usr/local/cargo/registry/ \
cargo build --release && \
cp ./target/release/mskasal /

WORKDIR /app/ocr
RUN wasm-pack build --target web;cp -r ./pkg/* ../assets
WORKDIR /app/led_matrix
RUN wasm-pack build --target web;cp -r ./pkg/* ../assets
WORKDIR /app/pong
RUN wasm-pack build --target web;cp -r ./pkg/* ../assets

WORKDIR /app
FROM debian:bookworm-slim AS final
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "10001" \
mskasal

COPY --from=builder /mskasal /usr/local/bin
COPY --from=builder /app/assets /usr/local/bin/assets
RUN chown mskasal /usr/local/bin/mskasal
COPY --from=builder /app/assets /opt/mskasal/assets
RUN chown -R mskasal /opt/mskasal
USER mskasal
ENV RUST_LOG="mskasal=debug,info"
WORKDIR /opt/mskasal
ENTRYPOINT ["mskasal"]
EXPOSE 8080/tcp
2 changes: 1 addition & 1 deletion assets/ocr.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface InitOutput {
readonly __wbindgen_malloc: (a: number, b: number) => number;
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_export_2: WebAssembly.Table;
readonly wasm_bindgen__convert__closures__invoke1_mut__hb2ab4e3fd03c79a7: (a: number, b: number, c: number) => void;
readonly wasm_bindgen__convert__closures__invoke1_mut__hb02b932c68e60fca: (a: number, b: number, c: number) => void;
readonly __wbindgen_exn_store: (a: number) => void;
readonly __wbindgen_start: () => void;
}
Expand Down
4 changes: 2 additions & 2 deletions assets/ocr.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ function makeMutClosure(arg0, arg1, dtor, f) {
return real;
}
function __wbg_adapter_16(arg0, arg1, arg2) {
wasm.wasm_bindgen__convert__closures__invoke1_mut__hb2ab4e3fd03c79a7(arg0, arg1, addHeapObject(arg2));
wasm.wasm_bindgen__convert__closures__invoke1_mut__hb02b932c68e60fca(arg0, arg1, addHeapObject(arg2));
}

/**
Expand Down Expand Up @@ -419,7 +419,7 @@ function __wbg_get_imports() {
imports.wbg.__wbindgen_rethrow = function(arg0) {
throw takeObject(arg0);
};
imports.wbg.__wbindgen_closure_wrapper41 = function(arg0, arg1, arg2) {
imports.wbg.__wbindgen_closure_wrapper43 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 3, __wbg_adapter_16);
return addHeapObject(ret);
};
Expand Down
Binary file modified assets/ocr_bg.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion assets/ocr_bg.wasm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export function ocr(): void;
export function __wbindgen_malloc(a: number, b: number): number;
export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number;
export const __wbindgen_export_2: WebAssembly.Table;
export function wasm_bindgen__convert__closures__invoke1_mut__hb2ab4e3fd03c79a7(a: number, b: number, c: number): void;
export function wasm_bindgen__convert__closures__invoke1_mut__hb02b932c68e60fca(a: number, b: number, c: number): void;
export function __wbindgen_exn_store(a: number): void;
export function __wbindgen_start(): void;
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "3.9"

services:
mskasal:
build: .
ports:
- "8080:8080"
volumes:
- .:/app # Mount current directory for easy code updates
environment:
- RUST_TARGET=wasm32-unknown-unknown # Optional customization
- WASM_PACK_TARGET=web # Optional customization
restart: unless-stopped # Restart automatically on failures

2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ async fn main() {
.nest_service("/assets", ServeDir::new("assets"))
.layer(comression_layer);

let listener = tokio::net::TcpListener::bind("0.0.0.0:3300").await.unwrap();
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await.unwrap();
axum::serve(listener, app).await.unwrap();
}

0 comments on commit ab43426

Please sign in to comment.