-
-
Notifications
You must be signed in to change notification settings - Fork 177
[build] add new dockerfiles for building from source #244
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f5d9914
add new dockerfiles
master-hax b3e2d1f
update default ubuntu base images
master-hax 29c2111
updates
master-hax 37aa633
update comment
master-hax 8d3afc7
update cargo command
master-hax 25b527e
update cargo command
master-hax 10e3bf2
specify binary
master-hax 282df11
use label instead of maintainer
master-hax 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,45 @@ | ||
# supported versions here: https://hub.docker.com/_/rust | ||
ARG ALPINE_VERSION=3.20 | ||
|
||
######################## | ||
## builder image | ||
######################## | ||
FROM rust:alpine${ALPINE_VERSION} AS builder | ||
|
||
RUN apk add --no-cache musl-dev | ||
|
||
WORKDIR /redlib | ||
|
||
# download (most) dependencies in their own layer | ||
COPY Cargo.lock Cargo.toml ./ | ||
RUN mkdir src && echo "fn main() { panic!(\"why am i running?\") }" > src/main.rs | ||
RUN cargo build --release --locked --bin redlib | ||
RUN rm ./src/main.rs && rmdir ./src | ||
|
||
# copy the source and build the redlib binary | ||
COPY . ./ | ||
RUN cargo build --release --locked --bin redlib | ||
RUN echo "finished building redlib!" | ||
|
||
######################## | ||
## release image | ||
######################## | ||
FROM alpine:${ALPINE_VERSION} AS release | ||
|
||
# Import redlib binary from builder | ||
COPY --from=builder /redlib/target/release/redlib /usr/local/bin/redlib | ||
|
||
# Add non-root user for running redlib | ||
RUN adduser --home /nonexistent --no-create-home --disabled-password redlib | ||
USER redlib | ||
|
||
# Document that we intend to expose port 8080 to whoever runs the container | ||
EXPOSE 8080 | ||
|
||
# Run a healthcheck every minute to make sure redlib is functional | ||
HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider --q http://localhost:8080/settings || exit 1 | ||
|
||
# Add container metadata | ||
LABEL org.opencontainers.image.authors="sigaloid" | ||
|
||
CMD ["redlib"] |
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,51 @@ | ||
# supported versions here: https://hub.docker.com/_/rust | ||
ARG RUST_BUILDER_VERSION=slim-bookworm | ||
ARG UBUNTU_RELEASE_VERSION=noble | ||
|
||
######################## | ||
## builder image | ||
######################## | ||
FROM rust:${RUST_BUILDER_VERSION} AS builder | ||
|
||
WORKDIR /redlib | ||
|
||
# download (most) dependencies in their own layer | ||
COPY Cargo.lock Cargo.toml ./ | ||
RUN mkdir src && echo "fn main() { panic!(\"why am i running?\") }" > src/main.rs | ||
master-hax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
RUN cargo build --release --locked --bin redlib | ||
master-hax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
RUN rm ./src/main.rs && rmdir ./src | ||
|
||
# copy the source and build the redlib binary | ||
COPY . ./ | ||
RUN cargo build --release --locked --bin redlib | ||
RUN echo "finished building redlib!" | ||
|
||
######################## | ||
## release image | ||
######################## | ||
FROM ubuntu:${UBUNTU_RELEASE_VERSION} AS release | ||
|
||
# Install ca-certificates | ||
RUN apt-get update && apt-get install -y ca-certificates | ||
|
||
# Import redlib binary from builder | ||
COPY --from=builder /redlib/target/release/redlib /usr/local/bin/redlib | ||
|
||
# Add non-root user for running redlib | ||
RUN useradd \ | ||
--no-create-home \ | ||
--password "!" \ | ||
--comment "user for running redlib" \ | ||
redlib | ||
USER redlib | ||
|
||
# Document that we intend to expose port 8080 to whoever runs the container | ||
EXPOSE 8080 | ||
|
||
# Run a healthcheck every minute to make sure redlib is functional | ||
HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider --q http://localhost:8080/settings || exit 1 | ||
|
||
# Add container metadata | ||
LABEL org.opencontainers.image.authors="sigaloid" | ||
|
||
CMD ["redlib"] |
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.