-
-
Notifications
You must be signed in to change notification settings - Fork 884
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
Use official rust image and clean up Dockerfiles #2804
Merged
dessalines
merged 11 commits into
LemmyNet:main
from
6543-forks:use_official_rust_images_for-arm-support
Apr 16, 2023
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5dad418
Add docker/Dockerfile.multiarch
6543 be4f097
Update normal Dockerfile to be similar to multiarch one
6543 1411670
docker build run on x86 and arm64 now
6543 ae3325b
Rename Dockerfile.arm To Dockerfile.debian
6543 13487d3
Emulate builder on arm target too
6543 def5c3d
fix misspell
6543 e8c1af6
Improve Dockerfiles
6543 4e29c78
naming
6543 8bc035a
undo multiarchbuild settings as its blocked by a dependeny, see #2806
6543 0bafc15
Merge branch 'main' into use_official_rust_images_for-arm-support
6543 0b71565
Delete Dockerfile.debian
6543 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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,55 @@ | ||
# FIXME: use "--platform=$BUILDPLATFORM" and solve openssl cross-compile issue | ||
FROM rust:1.67.0-alpine as builder | ||
|
||
# Install build dependencies | ||
RUN apk add --no-cache git openssl-dev libpq-dev musl-dev | ||
|
||
# Set the working directory to /app and copy the source code | ||
WORKDIR /app | ||
COPY . . | ||
|
||
# Set the target architecture (can be set using --build-arg), buildx set it automatically | ||
ARG TARGETARCH | ||
|
||
# This can be set to release using --build-arg | ||
ARG RUST_RELEASE_MODE="debug" | ||
|
||
# Prepare toolchain | ||
# Docker and Rust use different architecture naming schemas, so we have to convert them | ||
RUN case $TARGETARCH in \ | ||
arm64) RUSTARCH=aarch64 ;; \ | ||
amd64) RUSTARCH=x86_64 ;; \ | ||
*) echo "unsupported architecture: $TARGETARCH"; exit 3 ;; \ | ||
esac \ | ||
&& echo "RUSTARCH=$RUSTARCH" >> .buildenv | ||
|
||
# Debug mode build | ||
RUN --mount=type=cache,target=/app/target \ | ||
if [ "$RUST_RELEASE_MODE" = "debug" ]; then \ | ||
source .buildenv \ | ||
&& echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs" \ | ||
&& rustup target add ${RUSTARCH}-unknown-linux-musl \ | ||
&& cargo build --target ${RUSTARCH}-unknown-linux-musl \ | ||
&& cp ./target/${RUSTARCH}-unknown-linux-musl/${RUST_RELEASE_MODE}/lemmy_server /app/lemmy_server; \ | ||
fi | ||
|
||
# Release mode build | ||
RUN \ | ||
if [ "$RUST_RELEASE_MODE" = "release" ]; then \ | ||
source .buildenv \ | ||
&& rustup target add ${RUSTARCH}-unknown-linux-musl \ | ||
&& cargo build --target ${RUSTARCH}-unknown-linux-musl --release \ | ||
&& cp ./target/${RUSTARCH}-unknown-linux-musl/${RUST_RELEASE_MODE}/lemmy_server /app/lemmy_server; \ | ||
fi | ||
|
||
# The Alpine runner | ||
FROM alpine:3 as lemmy | ||
|
||
# Install libpq for Postgres | ||
RUN apk add --no-cache ca-certificates libpq | ||
|
||
# Copy resources | ||
COPY --from=builder /app/lemmy_server /app/lemmy | ||
|
||
EXPOSE 8536 | ||
CMD ["/app/lemmy"] | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably remove this file as cross-compile isnt working. And based on the age of the issue it wont get fixed anytime soon :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull does not address cross compilation!
Its moved in a extra pull
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this was added to the main branch anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the multiarch docker image is just ment to be build with buildx ... and the cross-compiline is just an optional feature ... for now I would recomend to just use it as single source of truth and have different agents that target this dockerfile
the old Dockerfile is just for normal devs who wana build the image but dont have buildx installed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case I would prefer to remove the old dockerfile, and list buildx as a requirements. cc @dessalines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok fine with that ... I have a look in altering the docs/readme
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I'm def fine with removing the old
Dockerfile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well the "old" is the same as the new one ... just without some fancy if statements and args on FROM 😆. so you can make the multiarch to a normal one again at any time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2818
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> #2818 (comment)