From 40120667f71e4ad9bae848dc562b4dfb448c3539 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 21 Dec 2023 20:02:28 -0500 Subject: [PATCH] Add a Dockerfile for building and running natter. --- .dockerignore | 3 +++ Cargo.toml | 6 ++++++ docker/natter/Dockerfile | 13 +++++++++++++ docker/natter/Makefile | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 .dockerignore create mode 100644 docker/natter/Dockerfile create mode 100644 docker/natter/Makefile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0343bec --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +**/.git +target/ +org_test_documents/ diff --git a/Cargo.toml b/Cargo.toml index e7f395a..9b552d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,3 +32,9 @@ serde_json = "1.0.107" tokio = { version = "1.30.0", default-features = false, features = ["rt", "rt-multi-thread", "fs", "io-util"] } toml = "0.8.2" walkdir = "2.4.0" + +# Optimized build for any sort of release. +[profile.release-lto] +inherits = "release" +lto = true +strip = "symbols" diff --git a/docker/natter/Dockerfile b/docker/natter/Dockerfile new file mode 100644 index 0000000..f45caee --- /dev/null +++ b/docker/natter/Dockerfile @@ -0,0 +1,13 @@ +FROM rustlang/rust:nightly-alpine3.17 AS builder + +RUN apk add --no-cache musl-dev + +RUN mkdir /root/natter +WORKDIR /root/natter +COPY . . +# TODO: Add static build, which currently errors due to proc_macro. RUSTFLAGS="-C target-feature=+crt-static" +RUN CARGO_TARGET_DIR=/target cargo build --profile release-lto + +FROM alpine:3.17 AS runner + +COPY --from=builder /target/release-lto/natter /usr/bin/ diff --git a/docker/natter/Makefile b/docker/natter/Makefile new file mode 100644 index 0000000..115f1bd --- /dev/null +++ b/docker/natter/Makefile @@ -0,0 +1,32 @@ +SHELL := bash +.ONESHELL: +.SHELLFLAGS := -eu -o pipefail -c +.DELETE_ON_ERROR: +MAKEFLAGS += --warn-undefined-variables +MAKEFLAGS += --no-builtin-rules +OS:=$(shell uname -s) + +ifeq ($(origin .RECIPEPREFIX), undefined) + $(error This Make does not support .RECIPEPREFIX. Please use GNU Make 4.0 or later) +endif +.RECIPEPREFIX = > + +IMAGE_NAME:=natter +TARGET := + +.PHONY: help +help: +> @grep -h "##" $(MAKEFILE_LIST) | grep -v grep | sed -E 's/^([^:]*): *## */\1: /' + +.PHONY: build +build: ## Build the docker image. +> docker build --tag $(IMAGE_NAME) --target=$(TARGET) --file Dockerfile ../../ + +.PHONY: shell +shell: ## Launch an interactive shell inside the docker image. +shell: build +> docker run --rm -i -t --entrypoint /bin/sh --mount type=tmpfs,destination=/tmp $(IMAGE_NAME) + +.PHONY: clean +clean: +> docker rmi $(IMAGE_NAME)