diff --git a/Cargo.lock b/Cargo.lock index c965080..9578af9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -77,7 +77,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -88,7 +88,7 @@ checksum = "a564d521dd56509c4c47480d00b80ee55f7e385ae48db5744c67ad50c92d2ebf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -593,7 +593,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -1262,7 +1262,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -1445,7 +1445,7 @@ checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -1474,9 +1474,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" +checksum = "78803b62cbf1f46fde80d7c0e803111524b9877184cfe7c3033659490ac7a7da" dependencies = [ "unicode-ident", ] @@ -1566,13 +1566,13 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.0" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89089e897c013b3deb627116ae56a6955a72b8bed395c9526af31c9fe528b484" +checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.3.0", + "regex-automata 0.3.2", "regex-syntax 0.7.3", ] @@ -1587,9 +1587,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa250384981ea14565685dea16a9ccc4d1c541a13f82b9c168572264d1df8c56" +checksum = "83d3daa6976cffb758ec878f108ba0e062a45b2d6ca3a2cca965338855476caf" dependencies = [ "aho-corasick", "memchr", @@ -1828,9 +1828,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.166" +version = "1.0.170" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d01b7404f9d441d3ad40e6a636a7782c377d2abdbe4fa2440e2edcc2f4f10db8" +checksum = "a56657f512baabca8f840542f9ca8152aecf182c473c26e46e58d6aab4f6e439" dependencies = [ "serde_derive", ] @@ -1846,13 +1846,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.166" +version = "1.0.170" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dd83d6dde2b6b2d466e14d9d1acce8816dedee94f735eac6395808b3483c6d6" +checksum = "77d477848e6b23adba0db397777d5aad864555bc17fd9c89abb3b8009788b7b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -1973,9 +1973,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" [[package]] name = "socket2" @@ -2038,9 +2038,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.23" +version = "2.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59fb7d6d8281a51045d62b8eb3a7d1ce347b76f312af50cd3dc0af39c87c1737" +checksum = "15e3fc8c0c74267e2df136e5e5fb656a464158aa57624053375eb9c8c6e25ae2" dependencies = [ "proc-macro2", "quote", @@ -2081,22 +2081,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.41" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c16a64ba9387ef3fdae4f9c1a7f07a0997fce91985c0336f1ddc1822b3b37802" +checksum = "a35fc5b8971143ca348fa6df4f024d4d55264f3468c71ad1c2f365b0a4d58c42" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.41" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d14928354b01c4d6a4f0e549069adef399a284e7995c7ccca94e8a07a5346c59" +checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -2111,9 +2111,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.22" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea9e1b3cf1243ae005d9e74085d4d542f3125458f3a81af210d901dcd7411efd" +checksum = "59e399c068f43a5d116fedaf73b203fa4f9c519f17e2b34f63221d3792f81446" dependencies = [ "itoa", "serde", @@ -2129,9 +2129,9 @@ checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" [[package]] name = "time-macros" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "372950940a5f07bf38dbe211d7283c9e6d7327df53794992d293e534c733d09b" +checksum = "96ba15a897f3c86766b757e5ac7221554c6750054d74d5b28844fce5fb36a6c4" dependencies = [ "time-core", ] @@ -2189,7 +2189,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -2343,7 +2343,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -2648,7 +2648,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", "wasm-bindgen-shared", ] @@ -2682,7 +2682,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/front-end/Dockerfile b/front-end/Dockerfile index 9e1cc0a..a7b2645 100644 --- a/front-end/Dockerfile +++ b/front-end/Dockerfile @@ -4,20 +4,30 @@ ARG VERSION=latest ARG BUILD_PROFILE=release ARG HIGHSCORE_API_BASE_URL="" ENV HIGHSCORE_API_BASE_URL=$HIGHSCORE_API_BASE_URL -WORKDIR /usr/src RUN curl --fail https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -COPY . . -WORKDIR /usr/src/front-end -# Build -RUN --mount=type=cache,target=/usr/local/cargo/registry \ - --mount=type=cache,target=/usr/src/target \ - wasm-pack build --${BUILD_PROFILE} --target web --out-name wasm-${VERSION} --out-dir ./out -# Copy over static files -RUN cp ./static/favicon.ico ./out/ -RUN cp ./static/style.css ./out/style-${VERSION}.css -RUN sed 's/$VERSION/'"$VERSION"'/g' static/index.html > ./out/index.html +WORKDIR /app +# Build the app +# - Uses bind mounts so that it is not needed to copy the source code into the container +# (note that due to using a Cargo workspace the source files for all members members are needed) +# - Uses cache mounts to speed up subsequent builds +RUN --mount=type=bind,source=Cargo.toml,target=Cargo.toml \ + --mount=type=bind,source=Cargo.lock,target=Cargo.lock \ + --mount=type=bind,source=front-end/src,target=front-end/src \ + --mount=type=bind,source=front-end/Cargo.toml,target=front-end/Cargo.toml \ + --mount=type=bind,source=highscore-api/src,target=highscore-api/src \ + --mount=type=bind,source=highscore-api/Cargo.toml,target=highscore-api/Cargo.toml \ + --mount=type=bind,source=highscore-types/src,target=highscore-types/src \ + --mount=type=bind,source=highscore-types/Cargo.toml,target=highscore-types/Cargo.toml \ + --mount=type=cache,target=/app/target/ \ + --mount=type=cache,target=/usr/local/cargo/registry/ \ + cd front-end \ + && wasm-pack build --${BUILD_PROFILE} --target web --out-name wasm-${VERSION} --out-dir ./out +WORKDIR /app/front-end +# Copy over static files and add VERSION where useful +COPY front-end/static out/ +RUN mv out/style.css out/style-${VERSION}.css && sed -i 's/$VERSION/'"$VERSION"'/g' out/index.html FROM nginx AS final COPY ./front-end/nginx.conf.template /etc/nginx/templates/default.conf.template -COPY --from=builder /usr/src/front-end/out /usr/share/nginx/html +COPY --from=builder /app/front-end/out /usr/share/nginx/html EXPOSE 80 diff --git a/highscore-api/Dockerfile b/highscore-api/Dockerfile index aed0742..a9dd5f9 100644 --- a/highscore-api/Dockerfile +++ b/highscore-api/Dockerfile @@ -1,14 +1,33 @@ FROM rust:1.70 AS builder ARG CARGO_INSTALL_OPTIONS='' -WORKDIR /usr/src -COPY . . -WORKDIR /usr/src/highscore-api -RUN --mount=type=cache,target=/usr/local/cargo/registry \ - --mount=type=cache,target=/usr/src/target \ - cargo install ${CARGO_INSTALL_OPTIONS} --path . +WORKDIR /app +# Build the service +# - Uses bind mounts so that it is not needed to copy the source code into the container +# (note that due to using a Cargo workspace the source files for all members members are needed) +# - Uses cache mounts to speed up subsequent builds +RUN --mount=type=bind,source=Cargo.toml,target=Cargo.toml \ + --mount=type=bind,source=Cargo.lock,target=Cargo.lock \ + --mount=type=bind,source=front-end/src,target=front-end/src \ + --mount=type=bind,source=front-end/Cargo.toml,target=front-end/Cargo.toml \ + --mount=type=bind,source=highscore-api/src,target=highscore-api/src \ + --mount=type=bind,source=highscore-api/Cargo.toml,target=highscore-api/Cargo.toml \ + --mount=type=bind,source=highscore-types/src,target=highscore-types/src \ + --mount=type=bind,source=highscore-types/Cargo.toml,target=highscore-types/Cargo.toml \ + --mount=type=cache,target=/app/target/ \ + --mount=type=cache,target=/usr/local/cargo/registry/ \ + cd highscore-api && cargo install ${CARGO_INSTALL_OPTIONS} --locked --path . FROM debian:12-slim AS final RUN apt-get update && apt-get install -y ca-certificates tzdata && rm -rf /var/lib/apt/lists/* +ARG UID=10001 +RUN adduser \ + --disabled-password \ + --home "/nonexistent" \ + --shell "/sbin/nologin" \ + --no-create-home \ + --uid "${UID}" \ + appuser +USER appuser COPY --from=builder /usr/local/cargo/bin/visnake-highscore-api /usr/local/bin/ EXPOSE 3000 CMD ["visnake-highscore-api"]