diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bd7ffa5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +################################################################################ +## BUILDER +################################################################################ +FROM rust:slim as builder + +# para compilación estática sin libc +ENV TARGET x86_64-unknown-linux-musl +RUN rustup target add "$TARGET" + +# xeneracion do executable +RUN USER=root mkdir ./itkg +WORKDIR ./itkg +ADD . ./ +RUN cargo build --release --locked --target "$TARGET" \ + && mv "target/$TARGET/release/itkg" . \ + && strip itkg + +# usuario para execucion +RUN groupadd app && useradd -g app app + +################################################################################ +## RUNER +################################################################################ +FROM scratch +ARG APP=/app + +EXPOSE 3007 + +COPY --from=builder /etc/passwd /etc/passwd +COPY --from=builder /etc/group /etc/group + +COPY --from=builder --chown=app:app /itkg/itkg ${APP}/itkg +COPY --from=builder --chown=app:app /itkg/templates/ ${APP}/templates/ + +USER app +WORKDIR ${APP} + +CMD ["./itkg"] diff --git a/README.md b/README.md index b942af7..200af3a 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,17 @@ La idea es tener en una web los generadores de personajes, naves, monstruos, etc ``` TEMPLATES="templates" PORT="3007" cargo run ``` + +### Docker +Para executar en docker hai que cambiar a app para que escoite en 0.0.0.0 en vez +de en 127.0.0.1 + +``` +docker build -t generadores-itk -f Dockerfile . +docker run \ + --rm \ + -e TEMPLATES="templates" \ + -e PORT="3007" \ + -p 3007:3007 \ + generadores-itk +``` diff --git a/src/main.rs b/src/main.rs index 63ba8ac..1f268e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,7 @@ async fn main() { // executase con hyper a través de axum::Server let addr = SocketAddr::from(([127, 0, 0, 1], itkg_lib::env_listen_port())); + // let addr = SocketAddr::from(([0, 0, 0, 0], itkg_lib::env_listen_port())); tracing::debug!("listening on {}", addr); axum::Server::bind(&addr) .serve(app.into_make_service())