-
Notifications
You must be signed in to change notification settings - Fork 210
Improve Dockerfile #455
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
Merged
Merged
Improve Dockerfile #455
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
93f3cf2
add an ignored directory to store non-docker data dirs
pietroalbini a94a6ee
docker: don't store data in the cratesfyi home directory
pietroalbini 28c594c
docker: remove the cratesfyi user
pietroalbini e20572a
docker: move environment variables around
pietroalbini d89338b
docker: remove most of the prefix initialization
pietroalbini 2cd9a9d
docker: clone the index at startup
pietroalbini 7e416f7
docker: switch image to ubuntu bionic
pietroalbini 8f5bb75
docker: use multi-stage builds to shrink the image size
pietroalbini d206d99
docker: ensure the git commit hash is detected inside docker
pietroalbini bcd8c0c
docker: include other essential files
pietroalbini ec69181
docker: retry running migrations if postgresql is not already up
pietroalbini d9c4c66
docker: avoid past creates being scheduled during first start
pietroalbini 7b1eaa8
ci: build the docker image and on master upload it to ecr
pietroalbini db195c8
docker: address review comments
pietroalbini dda2eb3
Update README.md
pietroalbini 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/.rustwide | ||
/ignored | ||
**/target | ||
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,2 @@ | ||
CRATESFYI_GITHUB_USERNAME= | ||
CRATESFYI_GITHUB_ACCESSTOKEN= |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/ignored | ||
/.env | ||
target | ||
*.css | ||
*.css.map | ||
|
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 |
---|---|---|
@@ -1,58 +1,74 @@ | ||
FROM rust:slim | ||
# To produce a smaller image this Dockerfile contains two separate stages: in | ||
# the first one all the build dependencies are installed and docs.rs is built, | ||
# while in the second one just the runtime dependencies are installed, with the | ||
# binary built in the previous stage copied there. | ||
# | ||
# As of 2019-10-29 this reduces the image from 2.8GB to 500 MB. | ||
|
||
### STEP 1: Install dependencies ### | ||
# Install packaged dependencies | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
build-essential git curl cmake gcc g++ pkg-config libmagic-dev \ | ||
libssl-dev zlib1g-dev sudo docker.io | ||
################# | ||
# Build stage # | ||
################# | ||
|
||
### STEP 2: Create user ### | ||
ENV HOME=/home/cratesfyi | ||
RUN adduser --home $HOME --disabled-login --disabled-password --gecos "" cratesfyi | ||
FROM ubuntu:bionic AS build | ||
|
||
### STEP 3: Setup build environment as new user ### | ||
ENV CRATESFYI_PREFIX=/home/cratesfyi/prefix | ||
RUN mkdir $CRATESFYI_PREFIX && chown cratesfyi:cratesfyi "$CRATESFYI_PREFIX" | ||
# Install packaged dependencies | ||
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ | ||
build-essential git curl cmake gcc g++ pkg-config libmagic-dev \ | ||
libssl-dev zlib1g-dev ca-certificates | ||
|
||
USER cratesfyi | ||
RUN mkdir -vp "$CRATESFYI_PREFIX"/documentations "$CRATESFYI_PREFIX"/public_html "$CRATESFYI_PREFIX"/sources | ||
RUN git clone https://github.com/rust-lang/crates.io-index.git "$CRATESFYI_PREFIX"/crates.io-index | ||
RUN git --git-dir="$CRATESFYI_PREFIX"/crates.io-index/.git branch crates-index-diff_last-seen | ||
# Install the stable toolchain with rustup | ||
RUN curl https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init >/tmp/rustup-init && \ | ||
chmod +x /tmp/rustup-init && \ | ||
/tmp/rustup-init -y --no-modify-path --default-toolchain stable --profile minimal | ||
ENV PATH=/root/.cargo/bin:$PATH | ||
|
||
### STEP 4: Build the project ### | ||
# Build the dependencies in a separate step to avoid rebuilding all of them | ||
# every time the source code changes. This takes advantage of Docker's layer | ||
# caching, and it works by copying the Cargo.{toml,lock} with dummy source code | ||
# and doing a full build with it. | ||
RUN mkdir -p ~/docs.rs ~/docs.rs/src/web/badge | ||
WORKDIR $HOME/docs.rs | ||
COPY --chown=cratesfyi Cargo.lock Cargo.toml ./ | ||
COPY --chown=cratesfyi src/web/badge src/web/badge/ | ||
RUN mkdir -p /build/src/web/badge | ||
WORKDIR /build | ||
COPY Cargo.lock Cargo.toml ./ | ||
COPY src/web/badge src/web/badge/ | ||
RUN echo "fn main() {}" > src/main.rs && \ | ||
echo "fn main() {}" > build.rs | ||
|
||
RUN cargo fetch | ||
RUN cargo build --release | ||
|
||
### STEP 5: Build the website ### | ||
# Dependencies are now cached, copy the actual source code and do another full | ||
# build. The touch on all the .rs files is needed, otherwise cargo assumes the | ||
# source code didn't change thanks to mtime weirdness. | ||
RUN rm -rf src build.rs | ||
|
||
COPY --chown=cratesfyi build.rs build.rs | ||
COPY .git .git | ||
pietroalbini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
COPY build.rs build.rs | ||
RUN touch build.rs | ||
COPY --chown=cratesfyi src src/ | ||
COPY src src/ | ||
RUN find src -name "*.rs" -exec touch {} \; | ||
COPY --chown=cratesfyi templates/style.scss templates/ | ||
COPY templates/style.scss templates/ | ||
|
||
RUN cargo build --release | ||
|
||
ADD templates templates/ | ||
ADD css $CRATESFYI_PREFIX/public_html | ||
################## | ||
# Output stage # | ||
################## | ||
|
||
FROM ubuntu:bionic AS output | ||
|
||
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ | ||
git \ | ||
libmagic1 \ | ||
docker.io \ | ||
ca-certificates | ||
|
||
RUN mkdir -p /opt/docsrs/prefix | ||
|
||
COPY --from=build /build/target/release/cratesfyi /usr/local/bin | ||
COPY css /opt/docsrs/prefix/public_html | ||
COPY templates /opt/docsrs/templates | ||
COPY docker-entrypoint.sh /opt/docsrs/entrypoint.sh | ||
|
||
ENV DOCS_RS_DOCKER=true | ||
COPY docker-entrypoint.sh ./ | ||
USER root | ||
ENTRYPOINT ["./docker-entrypoint.sh"] | ||
WORKDIR /opt/docsrs | ||
ENTRYPOINT ["/opt/docsrs/entrypoint.sh"] | ||
CMD ["daemon", "--foreground"] |
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,128 @@ | ||
/** | ||
* Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
* file at the top-level directory of this distribution and at | ||
* http://rust-lang.org/COPYRIGHT. | ||
* | ||
* Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
* http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
* <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
* option. This file may not be copied, modified, or distributed | ||
* except according to those terms. | ||
*/ | ||
|
||
/* General structure and fonts */ | ||
|
||
body { | ||
background-color: white; | ||
color: black; | ||
} | ||
|
||
h1, h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.type):not(.tymethod) { | ||
color: black; | ||
} | ||
h1.fqn { | ||
border-bottom-color: #D5D5D5; | ||
} | ||
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.type):not(.tymethod) { | ||
border-bottom-color: #DDDDDD; | ||
} | ||
.in-band, code { | ||
background-color: white; | ||
} | ||
|
||
.docblock code { | ||
background-color: #F5F5F5; | ||
} | ||
pre { | ||
background-color: #F5F5F5; | ||
} | ||
|
||
.sidebar .location { | ||
background: #e1e1e1; | ||
color: #333; | ||
} | ||
|
||
.block a:hover { | ||
background: #F5F5F5; | ||
} | ||
|
||
.line-numbers span { color: #c67e2d; } | ||
.line-numbers .line-highlighted { | ||
background-color: #f6fdb0 !important; | ||
} | ||
|
||
:target { background: #FDFFD3; } | ||
.content .highlighted { | ||
color: #000 !important; | ||
background-color: #ccc; | ||
} | ||
.content .highlighted a, .content .highlighted span { color: #000 !important; } | ||
.content .highlighted.trait { background-color: #fece7e; } | ||
.content .highlighted.mod { background-color: #afc6e4; } | ||
.content .highlighted.enum { background-color: #b4d1b9; } | ||
.content .highlighted.struct { background-color: #e7b1a0; } | ||
.content .highlighted.fn { background-color: #c6afb3; } | ||
.content .highlighted.method { background-color: #c6afb3; } | ||
.content .highlighted.tymethod { background-color: #c6afb3; } | ||
.content .highlighted.type { background-color: #c6afb3; } | ||
|
||
.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 { | ||
border-bottom-color: #DDD; | ||
} | ||
|
||
.docblock table { | ||
border-color: #ddd; | ||
} | ||
|
||
.docblock table td { | ||
border-top-color: #ddd; | ||
border-bottom-color: #ddd; | ||
} | ||
|
||
.docblock table th { | ||
border-top-color: #ddd; | ||
border-bottom-color: #ddd; | ||
} | ||
|
||
.content a.primitive { color: #39a7bf; } | ||
.content span.externcrate, span.mod, .content a.mod, block a.current.mod { color: #4d76ae; } | ||
.content span.fn, .content a.fn, .block a.current.fn, | ||
.content span.method, .content a.method, .block a.current.method, | ||
.content span.tymethod, .content a.tymethod, .block a.current.tymethod, | ||
.content .fnname { color: #8c6067; } | ||
|
||
pre.rust .comment { color: #8E908C; } | ||
pre.rust .doccomment { color: #4D4D4C; } | ||
|
||
nav { | ||
border-bottom-color: #e0e0e0; | ||
} | ||
nav.main .current { | ||
border-top-color: #000; | ||
border-bottom-color: #000; | ||
} | ||
nav.main .separator { | ||
border-color: 1px solid #000; | ||
} | ||
a { | ||
color: #000; | ||
} | ||
|
||
.docblock a, .stability a { | ||
color: #3873AD; | ||
} | ||
|
||
a.test-arrow { | ||
color: #f5f5f5; | ||
} | ||
|
||
.content span.trait, .content a.trait, .block a.current.trait { color: #7c5af3; } | ||
|
||
.search-input { | ||
color: #555; | ||
box-shadow: 0 0 0 1px #e0e0e0, 0 0 0 2px transparent; | ||
background-color: white; | ||
} | ||
|
||
em.stab.unstable { background: #FFF5D6; border-color: #FFC600; } | ||
em.stab.deprecated { background: #F3DFFF; border-color: #7F0087; } |
Oops, something went wrong.
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.