diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..6d2ed5c --- /dev/null +++ b/Containerfile @@ -0,0 +1,3 @@ +FROM alpine +COPY build/server / +ENTRYPOINT ["/server"] \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..42863c3 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,34 @@ +version: '3.9' +networks: + maps-service-network: + driver: bridge + +services: + nats: + image: docker.io/nats:latest + container_name: nats + networks: + - maps-service-network + + maps-service: + build: + context: . + dockerfile: Containerfile + container_name: maps-service + networks: + - maps-service-network + + web: + build: + context: web + dockerfile: Containerfile + networks: + - maps-service-network + + validation: + build: + context: validation + dockerfile: Containerfile + container_name: validation + networks: + - maps-service-network diff --git a/validation/Containerfile b/validation/Containerfile new file mode 100644 index 0000000..a0639cc --- /dev/null +++ b/validation/Containerfile @@ -0,0 +1,23 @@ +# Using the `rust-musl-builder` as base image, instead of +# the official Rust toolchain +FROM docker.io/clux/muslrust:stable AS chef +USER root +RUN cargo install cargo-chef +WORKDIR /app + +FROM chef AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef AS builder +COPY --from=planner /app/recipe.json recipe.json +# Notice that we are specifying the --target flag! +RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json +COPY . . +RUN cargo build --release --target x86_64-unknown-linux-musl --bin maps-validation + +FROM docker.io/alpine:latest AS runtime +RUN addgroup -S myuser && adduser -S myuser -G myuser +COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/maps-validation /usr/local/bin/ +USER myuser +ENTRYPOINT ["/usr/local/bin/maps-validation"] diff --git a/web/Containerfile b/web/Containerfile new file mode 100644 index 0000000..dd423ac --- /dev/null +++ b/web/Containerfile @@ -0,0 +1,38 @@ +# use the official Bun image +# see all versions at https://hub.docker.com/r/oven/bun/tags +FROM oven/bun:1 AS base +WORKDIR /usr/src/app + +# install dependencies into temp directory +# this will cache them and speed up future builds +FROM base AS install +RUN mkdir -p /temp/dev +COPY package.json bun.lockb /temp/dev/ +RUN cd /temp/dev && bun install --frozen-lockfile + +# install with --production (exclude devDependencies) +RUN mkdir -p /temp/prod +COPY package.json bun.lockb /temp/prod/ +RUN cd /temp/prod && bun install --frozen-lockfile --production + +# copy node_modules from temp directory +# then copy all (non-ignored) project files into the image +FROM base AS prerelease +COPY --from=install /temp/dev/node_modules node_modules +COPY . . + +# [optional] tests & build +ENV NODE_ENV=production +RUN bun test +RUN bun run build + +# copy production dependencies and source code into final image +FROM base AS release +COPY --from=install /temp/prod/node_modules node_modules +COPY --from=prerelease /usr/src/app/index.ts . +COPY --from=prerelease /usr/src/app/package.json . + +# run the app +USER bun +EXPOSE 3000/tcp +ENTRYPOINT [ "bun", "run", "index.ts" ]