mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-10 06:54:12 +00:00
Various build optimizations
This commit is contained in:
parent
1b0212377d
commit
4ea6c4ad5d
12 changed files with 111 additions and 22 deletions
12
docker/dev/Dockerfile
vendored
12
docker/dev/Dockerfile
vendored
|
@ -21,17 +21,13 @@ 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 cargo build
|
||||
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
|
||||
|
||||
# Get diesel-cli on there just in case
|
||||
# RUN cargo install diesel_cli --no-default-features --features postgres
|
||||
|
||||
# Build for debug
|
||||
RUN cargo build
|
||||
|
||||
FROM ekidd/rust-musl-builder:1.42.0-openssl11 as docs
|
||||
WORKDIR /app
|
||||
|
@ -47,7 +43,7 @@ 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=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=node /app/ui/dist /app/dist
|
||||
|
||||
|
|
4
docker/dev/docker_update.sh
vendored
4
docker/dev/docker_update.sh
vendored
|
@ -1,2 +1,6 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
export COMPOSE_DOCKER_CLI_BUILD=1
|
||||
export DOCKER_BUILDKIT=1
|
||||
docker-compose up -d --no-deps --build
|
||||
|
|
4
docker/dev/test_deploy.sh
vendored
4
docker/dev/test_deploy.sh
vendored
|
@ -1,4 +1,8 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
export COMPOSE_DOCKER_CLI_BUILD=1
|
||||
export DOCKER_BUILDKIT=1
|
||||
|
||||
# Rebuilding dev docker
|
||||
docker-compose build
|
||||
|
|
58
docker/prod/Dockerfile
vendored
Normal file
58
docker/prod/Dockerfile
vendored
Normal file
|
@ -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/
|
||||
RUN rm -f ./target/release/deps/lemmy_server* ; rm -f ./target/debug/deps/lemmy_server*
|
||||
|
||||
|
||||
# build for 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
|
||||
# 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
|
||||
#RUN cargo build --frozen --release
|
||||
RUN cargo build --frozen
|
||||
RUN cargo build --frozen --release
|
||||
|
||||
# reduce binary size
|
||||
RUN strip /app/server/target/debug/lemmy_server
|
||||
|
||||
# Get diesel-cli on there just in case
|
||||
# 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
|
||||
#RUN RUSTFLAGS='-Ccodegen-units=1' cargo build --release
|
||||
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
|
||||
# RUN cargo install diesel_cli --no-default-features --features postgres
|
6
docker/dev/deploy.sh → docker/prod/deploy.sh
vendored
6
docker/dev/deploy.sh → docker/prod/deploy.sh
vendored
|
@ -1,4 +1,5 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
git checkout master
|
||||
|
||||
# Import translations
|
||||
|
@ -20,7 +21,7 @@ git add "server/src/version.rs"
|
|||
echo $new_tag > "ansible/VERSION"
|
||||
git add "ansible/VERSION"
|
||||
|
||||
cd docker/dev || exit
|
||||
cd docker/prod || exit
|
||||
|
||||
# Changing the docker-compose prod
|
||||
sed -i "s/dessalines\/lemmy:.*/dessalines\/lemmy:$new_tag/" ../prod/docker-compose.yml
|
||||
|
@ -32,6 +33,9 @@ git add ../../ansible/templates/docker-compose.yml
|
|||
git commit -m"Version $new_tag"
|
||||
git tag $new_tag
|
||||
|
||||
export COMPOSE_DOCKER_CLI_BUILD=1
|
||||
export DOCKER_BUILDKIT=1
|
||||
|
||||
# Rebuilding docker
|
||||
docker-compose build
|
||||
docker tag dev_lemmy:latest dessalines/lemmy:x64-$new_tag
|
15
docs/src/contributing_docker_development.md
vendored
15
docs/src/contributing_docker_development.md
vendored
|
@ -3,11 +3,22 @@
|
|||
## Running
|
||||
|
||||
```bash
|
||||
sudo apt install git docker-compose
|
||||
git clone https://github.com/LemmyNet/lemmy
|
||||
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.
|
||||
|
||||
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.
|
||||
|
|
6
docs/src/contributing_local_development.md
vendored
6
docs/src/contributing_local_development.md
vendored
|
@ -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
|
||||
`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
|
||||
iframely respectively). If you want to test those, you should use the
|
||||
[Docker development](contributing_docker_development.md).
|
||||
|
|
2
server/Cargo.lock
generated
vendored
2
server/Cargo.lock
generated
vendored
|
@ -413,7 +413,6 @@ name = "attohttpc"
|
|||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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)",
|
||||
"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)",
|
||||
|
@ -2201,7 +2200,6 @@ name = "serde_json"
|
|||
version = "1.0.52"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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)",
|
||||
"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)",
|
||||
|
|
11
server/Cargo.toml
vendored
11
server/Cargo.toml
vendored
|
@ -4,16 +4,19 @@ version = "0.0.1"
|
|||
authors = ["Dessalines <tyhou13@gmx.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
||||
[dependencies]
|
||||
diesel = { version = "1.4.2", features = ["postgres","chrono", "r2d2", "64-column-tables"] }
|
||||
diesel_migrations = "1.4.0"
|
||||
dotenv = "0.15.0"
|
||||
bcrypt = "0.7.0"
|
||||
activitypub = "0.2.0"
|
||||
chrono = { version = "0.4.7", features = ["serde"] }
|
||||
chrono = "0.4.7"
|
||||
failure = "0.1.8"
|
||||
serde_json = { version = "1.0.52", features = ["preserve_order"]}
|
||||
serde = { version = "1.0.105", features = ["derive"] }
|
||||
serde_json = "1.0.52"
|
||||
serde = "1.0.105"
|
||||
actix = "0.9.0"
|
||||
actix-web = "2.0.0"
|
||||
actix-files = "0.2.1"
|
||||
|
@ -34,7 +37,7 @@ rss = "1.9.0"
|
|||
htmlescape = "0.3.1"
|
||||
config = {version = "0.10.1", default-features = false, features = ["hjson"] }
|
||||
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"
|
||||
tokio = "0.2.20"
|
||||
futures = "0.3.4"
|
||||
|
|
Loading…
Reference in a new issue