Skip to content

Commit

Permalink
Fix Dockerfile not building
Browse files Browse the repository at this point in the history
  • Loading branch information
sean0x42 committed Oct 13, 2024
1 parent abd5627 commit fee5f33
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
8 changes: 0 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
# [package]
# name = "markdown-extract-monorepo"
# description = "Extract sections of a markdown file with a regular expression"
# version = "0.1.0"
# authors = ["Sean Bailey <hello@seanbailey.dev>"]
# license = "MIT"
# readme = "README.md"

[workspace]
members = ["crates/markdown-extract", "crates/markdown-extract-cli"]
resolver = "2"
28 changes: 12 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
# Dockerfile for creating statically-linked Rust applications.
# See: https://www.artificialworlds.net/blog/2020/04/22/creating-a-tiny-docker-image-of-a-rust-project/
# See: https://alexbrand.dev/post/how-to-package-rust-applications-into-minimal-docker-containers/

# 1: Build the exe
FROM rust:1.57 as builder
# Step 0: Initialise builder
FROM rust:1.81 as builder
WORKDIR /usr/src
RUN rustup target add x86_64-unknown-linux-musl
RUN apt-get update
RUN apt-get install -y musl-tools gcc-x86-64-linux-gnu
ENV RUSTFLAGS='-C linker=x86_64-linux-gnu-gcc'

# 1a: Prepare for static linking
RUN apt-get update && \
apt-get dist-upgrade -y && \
apt-get install -y musl-tools && \
rustup target add x86_64-unknown-linux-musl

# 1b: Download and compile Rust dependencies (and store as a separate Docker layer)
RUN USER=root cargo new markdown-extract
# Step 1: Build and install binary
WORKDIR /usr/src/markdown-extract
COPY Cargo.toml Cargo.lock ./
COPY src ./src
RUN cargo install --target x86_64-unknown-linux-musl --path .
COPY crates ./crates
RUN cargo install \
--target x86_64-unknown-linux-musl \
--path ./crates/markdown-extract-cli

# 2: Copy the exe and extra files ("static") to an empty Docker image
# Step 2: Copy bin to an empty Docker image
FROM scratch
COPY --from=builder /usr/local/cargo/bin/markdown-extract .
# COPY static .
USER 1000
ENTRYPOINT ["./markdown-extract"]

0 comments on commit fee5f33

Please sign in to comment.