From b49a01ab03bc6ececeb27dd38391f62b54119cea Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 5 Mar 2021 20:40:49 +0100 Subject: [PATCH] Added Docker build files --- .dockerignore | 8 ++++++++ Dockerfile | 15 +++++++++++++++ Makefile | 10 ++++++++++ 3 files changed, 33 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..614c7dd --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +* + +# Source code +!src/ + +# Cargo files +!Cargo.toml +!Cargo.lock diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..52c8ae8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +# syntax=docker/dockerfile:1.2 +FROM rustlang/rust:nightly AS builder + +WORKDIR /usr/src/app + +# Build the app +COPY . . +RUN --mount=type=cache,target=/usr/src/app/target cargo install --path . + + +FROM debian:buster-slim + +COPY --from=builder /usr/local/cargo/bin/rust-api /usr/local/bin/rust-api + +CMD ["rust-api"] diff --git a/Makefile b/Makefile index 2c20587..70d000e 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,8 @@ +IMAGE := rust_api:latest + +shell := /bin/bash + + all: debug .PHONY: all @@ -10,7 +15,12 @@ release: @ cargo build --release .PHONY: release +image: Dockerfile + @ DOCKER_BUILDKIT=1 docker build -t '$(IMAGE)' . +.PHONY: image + # Run run: @ cargo run +