mirror of https://github.com/LemmyNet/lemmy.git
Various build optimizations
parent
1b0212377d
commit
5a6f39dae4
|
@ -21,17 +21,13 @@ COPY server/Cargo.toml server/Cargo.lock ./
|
||||||
RUN sudo chown -R rust:rust .
|
RUN sudo chown -R rust:rust .
|
||||||
RUN mkdir -p ./src/bin \
|
RUN mkdir -p ./src/bin \
|
||||||
&& echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs
|
&& echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs
|
||||||
RUN cargo build --release
|
RUN cargo build
|
||||||
RUN rm -f ./target/x86_64-unknown-linux-musl/release/deps/lemmy_server*
|
RUN rm -f ./target/x86_64-unknown-linux-musl/release/deps/lemmy_server*
|
||||||
COPY server/src ./src/
|
COPY server/src ./src/
|
||||||
COPY server/migrations ./migrations/
|
COPY server/migrations ./migrations/
|
||||||
|
|
||||||
# Build for release
|
# Build for debug
|
||||||
RUN cargo build --frozen --release
|
RUN cargo build
|
||||||
|
|
||||||
# Get diesel-cli on there just in case
|
|
||||||
# RUN cargo install diesel_cli --no-default-features --features postgres
|
|
||||||
|
|
||||||
|
|
||||||
FROM ekidd/rust-musl-builder:1.42.0-openssl11 as docs
|
FROM ekidd/rust-musl-builder:1.42.0-openssl11 as docs
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
@ -47,7 +43,7 @@ RUN apk add libpq
|
||||||
|
|
||||||
# Copy resources
|
# Copy resources
|
||||||
COPY server/config/defaults.hjson /config/defaults.hjson
|
COPY server/config/defaults.hjson /config/defaults.hjson
|
||||||
COPY --from=rust /app/server/target/x86_64-unknown-linux-musl/release/lemmy_server /app/lemmy
|
COPY --from=rust /app/server/target/x86_64-unknown-linux-musl/debug/lemmy_server /app/lemmy
|
||||||
COPY --from=docs /app/docs/book/ /app/dist/documentation/
|
COPY --from=docs /app/docs/book/ /app/dist/documentation/
|
||||||
COPY --from=node /app/ui/dist /app/dist
|
COPY --from=node /app/ui/dist /app/dist
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
FROM node:10-jessie as node
|
||||||
|
|
||||||
|
WORKDIR /app/ui
|
||||||
|
|
||||||
|
# Cache deps
|
||||||
|
COPY ui/package.json ui/yarn.lock ./
|
||||||
|
RUN yarn install --pure-lockfile
|
||||||
|
|
||||||
|
# Build
|
||||||
|
COPY ui /app/ui
|
||||||
|
RUN yarn build
|
||||||
|
|
||||||
|
FROM ekidd/rust-musl-builder:1.42.0-openssl11 as rust
|
||||||
|
|
||||||
|
# Cache deps
|
||||||
|
WORKDIR /app
|
||||||
|
RUN sudo chown -R rust:rust .
|
||||||
|
RUN USER=root cargo new server
|
||||||
|
WORKDIR /app/server
|
||||||
|
COPY server/Cargo.toml server/Cargo.lock ./
|
||||||
|
RUN sudo chown -R rust:rust .
|
||||||
|
RUN mkdir -p ./src/bin \
|
||||||
|
&& echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs
|
||||||
|
RUN cargo build --release
|
||||||
|
RUN rm -f ./target/x86_64-unknown-linux-musl/release/deps/lemmy_server*
|
||||||
|
COPY server/src ./src/
|
||||||
|
COPY server/migrations ./migrations/
|
||||||
|
|
||||||
|
# Build for release
|
||||||
|
RUN cargo build --frozen --release
|
||||||
|
|
||||||
|
# reduce binary size
|
||||||
|
RUN strip /app/server/target/x86_64-unknown-linux-musl/release/lemmy_server
|
||||||
|
|
||||||
|
FROM ekidd/rust-musl-builder:1.42.0-openssl11 as docs
|
||||||
|
WORKDIR /app
|
||||||
|
COPY docs ./docs
|
||||||
|
RUN sudo chown -R rust:rust .
|
||||||
|
RUN mdbook build docs/
|
||||||
|
|
||||||
|
|
||||||
|
FROM alpine:3.10
|
||||||
|
|
||||||
|
# Install libpq for postgres
|
||||||
|
RUN apk add libpq
|
||||||
|
|
||||||
|
# Copy resources
|
||||||
|
COPY server/config/defaults.hjson /config/defaults.hjson
|
||||||
|
COPY --from=rust /app/server/target/x86_64-unknown-linux-musl/release/lemmy_server /app/lemmy
|
||||||
|
COPY --from=docs /app/docs/book/ /app/dist/documentation/
|
||||||
|
COPY --from=node /app/ui/dist /app/dist
|
||||||
|
|
||||||
|
RUN addgroup -g 1000 lemmy
|
||||||
|
RUN adduser -D -s /bin/sh -u 1000 -G lemmy lemmy
|
||||||
|
RUN chown lemmy:lemmy /app/lemmy
|
||||||
|
USER lemmy
|
||||||
|
EXPOSE 8536
|
||||||
|
CMD ["/app/lemmy"]
|
|
@ -40,10 +40,11 @@ COPY server/src ./src/
|
||||||
COPY server/migrations ./migrations/
|
COPY server/migrations ./migrations/
|
||||||
RUN rm -f ./target/release/deps/lemmy_server* ; rm -f ./target/debug/deps/lemmy_server*
|
RUN rm -f ./target/release/deps/lemmy_server* ; rm -f ./target/debug/deps/lemmy_server*
|
||||||
|
|
||||||
|
|
||||||
# build for release
|
# build for release
|
||||||
RUN cargo build --frozen --release
|
RUN cargo build --frozen --release
|
||||||
# RUN cargo build --frozen
|
|
||||||
|
# reduce binary size
|
||||||
|
RUN strip /app/server/target/release/lemmy_server
|
||||||
|
|
||||||
# Get diesel-cli on there just in case
|
# Get diesel-cli on there just in case
|
||||||
# RUN cargo install diesel_cli --no-default-features --features postgres
|
# RUN cargo install diesel_cli --no-default-features --features postgres
|
|
@ -43,8 +43,10 @@ RUN rm -f ./target/release/deps/lemmy_server* ; rm -f ./target/debug/deps/lemmy_
|
||||||
|
|
||||||
|
|
||||||
# build for release
|
# build for release
|
||||||
#RUN cargo build --frozen --release
|
RUN cargo build --frozen --release
|
||||||
RUN cargo build --frozen
|
|
||||||
|
# reduce binary size
|
||||||
|
RUN strip /app/server/target/debug/lemmy_server
|
||||||
|
|
||||||
# Get diesel-cli on there just in case
|
# Get diesel-cli on there just in case
|
||||||
# RUN cargo install diesel_cli --no-default-features --features postgres
|
# RUN cargo install diesel_cli --no-default-features --features postgres
|
|
@ -43,7 +43,9 @@ COPY server/migrations ./migrations/
|
||||||
# workaround for https://github.com/rust-lang/rust/issues/62896
|
# workaround for https://github.com/rust-lang/rust/issues/62896
|
||||||
#RUN RUSTFLAGS='-Ccodegen-units=1' cargo build --release
|
#RUN RUSTFLAGS='-Ccodegen-units=1' cargo build --release
|
||||||
RUN cargo build --release --frozen
|
RUN cargo build --release --frozen
|
||||||
#RUN cargo build --frozen
|
|
||||||
|
# reduce binary size
|
||||||
|
RUN strip /app/server/target/release/lemmy_server
|
||||||
|
|
||||||
# Get diesel-cli on there just in case
|
# Get diesel-cli on there just in case
|
||||||
# RUN cargo install diesel_cli --no-default-features --features postgres
|
# RUN cargo install diesel_cli --no-default-features --features postgres
|
|
@ -20,7 +20,7 @@ git add "server/src/version.rs"
|
||||||
echo $new_tag > "ansible/VERSION"
|
echo $new_tag > "ansible/VERSION"
|
||||||
git add "ansible/VERSION"
|
git add "ansible/VERSION"
|
||||||
|
|
||||||
cd docker/dev || exit
|
cd docker/prod || exit
|
||||||
|
|
||||||
# Changing the docker-compose prod
|
# Changing the docker-compose prod
|
||||||
sed -i "s/dessalines\/lemmy:.*/dessalines\/lemmy:$new_tag/" ../prod/docker-compose.yml
|
sed -i "s/dessalines\/lemmy:.*/dessalines\/lemmy:$new_tag/" ../prod/docker-compose.yml
|
|
@ -3,11 +3,22 @@
|
||||||
## Running
|
## Running
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
sudo apt install git docker-compose
|
||||||
git clone https://github.com/LemmyNet/lemmy
|
git clone https://github.com/LemmyNet/lemmy
|
||||||
cd lemmy/docker/dev
|
cd lemmy/docker/dev
|
||||||
./docker_update.sh # This builds and runs it, updating for your changes
|
sudo docker-compose up --no-deps --build
|
||||||
```
|
```
|
||||||
|
|
||||||
and go to http://localhost:8536.
|
and go to http://localhost:8536.
|
||||||
|
|
||||||
Note that compile times when changing `Cargo.toml` are relatively long with Docker, because builds can't be incrementally cached. If this is a problem for you, you should use [Local Development](contributing_local_development.md).
|
To speed up the Docker compile, add the following to `/etc/docker/daemon.json` and restart Docker.
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"features": {
|
||||||
|
"buildkit": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
If the build is still too slow, you will have to use a
|
||||||
|
[local build](contributing_local_development.md) instead.
|
||||||
|
|
|
@ -56,6 +56,12 @@ Then open [localhost:4444](http://localhost:4444) in your browser. It will auto-
|
||||||
any frontend files. For backend coding, you will have to rerun `cargo run`. You can use
|
any frontend files. For backend coding, you will have to rerun `cargo run`. You can use
|
||||||
`cargo check` as a faster way to find compilation errors.
|
`cargo check` as a faster way to find compilation errors.
|
||||||
|
|
||||||
|
To speed up incremental builds, you can add the following to `~/.cargo/config`:
|
||||||
|
```
|
||||||
|
[target.x86_64-unknown-linux-gnu]
|
||||||
|
rustflags = ["-Clink-arg=-fuse-ld=lld"]
|
||||||
|
```
|
||||||
|
|
||||||
Note that this setup doesn't include image uploads or link previews (provided by pict-rs and
|
Note that this setup doesn't include image uploads or link previews (provided by pict-rs and
|
||||||
iframely respectively). If you want to test those, you should use the
|
iframely respectively). If you want to test those, you should use the
|
||||||
[Docker development](contributing_docker_development.md).
|
[Docker development](contributing_docker_development.md).
|
||||||
|
|
|
@ -413,7 +413,6 @@ name = "attohttpc"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"flate2 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"http 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"http 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rustls 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustls 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -2201,7 +2200,6 @@ name = "serde_json"
|
||||||
version = "1.0.52"
|
version = "1.0.52"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ryu 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ryu 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -4,16 +4,19 @@ version = "0.0.1"
|
||||||
authors = ["Dessalines <tyhou13@gmx.com>"]
|
authors = ["Dessalines <tyhou13@gmx.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
lto = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
diesel = { version = "1.4.2", features = ["postgres","chrono", "r2d2", "64-column-tables"] }
|
diesel = { version = "1.4.2", features = ["postgres","chrono", "r2d2", "64-column-tables"] }
|
||||||
diesel_migrations = "1.4.0"
|
diesel_migrations = "1.4.0"
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
bcrypt = "0.7.0"
|
bcrypt = "0.7.0"
|
||||||
activitypub = "0.2.0"
|
activitypub = "0.2.0"
|
||||||
chrono = { version = "0.4.7", features = ["serde"] }
|
chrono = "0.4.7"
|
||||||
failure = "0.1.8"
|
failure = "0.1.8"
|
||||||
serde_json = { version = "1.0.52", features = ["preserve_order"]}
|
serde_json = "1.0.52"
|
||||||
serde = { version = "1.0.105", features = ["derive"] }
|
serde = "1.0.105"
|
||||||
actix = "0.9.0"
|
actix = "0.9.0"
|
||||||
actix-web = "2.0.0"
|
actix-web = "2.0.0"
|
||||||
actix-files = "0.2.1"
|
actix-files = "0.2.1"
|
||||||
|
@ -34,7 +37,7 @@ rss = "1.9.0"
|
||||||
htmlescape = "0.3.1"
|
htmlescape = "0.3.1"
|
||||||
config = {version = "0.10.1", default-features = false, features = ["hjson"] }
|
config = {version = "0.10.1", default-features = false, features = ["hjson"] }
|
||||||
percent-encoding = "2.1.0"
|
percent-encoding = "2.1.0"
|
||||||
attohttpc = { version = "0.14.0", default-features = false, features = ["tls-rustls", "compress"] }
|
attohttpc = { version = "0.14.0", default-features = false, features = ["tls-rustls"] }
|
||||||
comrak = "0.7"
|
comrak = "0.7"
|
||||||
tokio = "0.2.20"
|
tokio = "0.2.20"
|
||||||
futures = "0.3.4"
|
futures = "0.3.4"
|
||||||
|
|
Loading…
Reference in New Issue