-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Feature: support dockerized builds of current source-code #2030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
marcellodesales
wants to merge
10
commits into
rust-lang:master
Choose a base branch
from
marcellodesales:feature/support-dockerized-builds
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4fbf5a7
:sparkles: :whale: Add support for dockerized builds
marcellodesales d988864
:memo: README: add container support for users without rust/cargo
marcellodesales dc007c3
:whale: :recycle: add docker ARG BASE_IMAGE for builder
marcellodesales 268b187
:whale: :recycle: re-order build avoiding rustup reinstalls
marcellodesales d10159a
:whale: :recycle: :pushpin: set [email protected] as runtime image
marcellodesales f68dab9
:memo: :recycle: add docker engine link + fix docker run example
marcellodesales 1fc0153
:whale: :star2: add docker compose for build/run
marcellodesales 52f007e
:memo: :recycle: add docker compose instructions
marcellodesales 35fd99b
:memo: :whale: :recycle: add instructions for docker compose
marcellodesales f67842d
:whale: :recycle: Dockerfile: add / to COPY command to dir
marcellodesales File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
################ | ||
##### Builder | ||
##### docker buildx create --use --name multi-builder --platform linux/arm64,linux/amd64 | ||
# https://github.com/docker/buildx/issues/318#issuecomment-1023226339 | ||
#FROM --platform=$BUILDPLATFORM rustlang/rust:nightly-buster-slim as builder | ||
ARG BASE_IMAGE | ||
FROM ${BASE_IMAGE} AS builder | ||
|
||
# Installing git because of the workaround for the config | ||
# https://github.com/rust-lang/cargo/issues/10781#issuecomment-1441071052 | ||
RUN apt-get update && apt-get install -y git | ||
|
||
WORKDIR /usr/src/github.com/rust-lang | ||
|
||
# Create blank project | ||
RUN USER=root cargo new mdBook | ||
|
||
WORKDIR /usr/src/github.com/rust-lang/mdBook | ||
|
||
## Install target platform (Cross-Compilation) --> Needed for Alpine | ||
# Use stable rather than nightly for the build target | ||
# Got errors while building after 6 months | ||
# https://substrate.stackexchange.com/questions/5379/how-do-i-fix-a-failed-build-error-e0635-unknown-feature-proc-macro-span-shri/9312#9312 | ||
RUN rustup default stable | ||
|
||
# note: the `x86_64-unknown-linux-musl` target may not be installed | ||
RUN rustup target add x86_64-unknown-linux-musl | ||
|
||
# We want dependencies cached, so copy those first. | ||
COPY Cargo.toml Cargo.lock /usr/src/github.com/rust-lang/mdBook | ||
marcellodesales marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# examples is referenced in Cargo.toml | ||
COPY examples /usr/src/github.com/rust-lang/mdBook/examples | ||
|
||
# This is a dummy build to pull dependencies and have them cached | ||
# https://github.com/rust-lang/cargo/issues/8172#issuecomment-659056517 | ||
# Very slow builds: https://github.com/rust-lang/cargo/issues/9167#issuecomment-1219251978 | ||
# Logs verbose: https://github.com/rust-lang/cargo/issues/1106#issuecomment-141555744 | ||
RUN cargo build -vv --config "net.git-fetch-with-cli=true" --target x86_64-unknown-linux-musl --release | ||
|
||
WORKDIR /usr/src/github.com/rust-lang/mdBook | ||
|
||
# Now copy in the rest of the sources | ||
COPY src /usr/src/github.com/rust-lang/mdBook/src | ||
|
||
# This is the actual application build: # ./target/x86_64-unknown-linux-musl/release/mdbook | ||
RUN cargo build --locked --bin mdbook --release --target x86_64-unknown-linux-musl | ||
|
||
################ | ||
##### Runtime | ||
FROM alpine:3.18.4 AS runtime | ||
|
||
# Copy application binary from builder image | ||
COPY --from=builder /usr/src/github.com/rust-lang/mdBook/target/x86_64-unknown-linux-musl/release/mdbook /usr/local/bin/mdbook | ||
|
||
# Just to document which port a container from this image exposes | ||
EXPOSE 3000 | ||
|
||
# The command to serve the books | ||
ENTRYPOINT ["mdbook", "serve", "--hostname", "0.0.0.0"] | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
version: "3.9" | ||
|
||
services: | ||
|
||
#### | ||
#### 1. Place this file in a folder where the **/*.md files exist | ||
#### 2. Adjust the port number to one available locally | ||
#### 3. Adjust the volume path to point to the container's /src dir | ||
#### | ||
mdbook: | ||
image: rust-lang/mdbook | ||
container_name: rustlang-mdbook | ||
platform: linux/amd64 | ||
build: | ||
context: . | ||
args: | ||
BASE_IMAGE: rustlang/rust:nightly-buster-slim | ||
ports: | ||
- 3000:3000 | ||
volumes: | ||
- ./test_book/src:/src | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.