Merge pull request #1889 from LemmyNet/update_docker_images

Updating rust musl images
This commit is contained in:
Nutomic 2021-11-10 13:45:49 +00:00 committed by GitHub
commit 2ed58aeda6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 56 deletions

View file

@ -9,7 +9,7 @@ platform:
steps: steps:
- name: prepare repo - name: prepare repo
image: ekidd/rust-musl-builder:1.51.0 image: clux/muslrust:1.56.0
user: root user: root
commands: commands:
- chown 1000:1000 . -R - chown 1000:1000 . -R
@ -21,31 +21,32 @@ steps:
- /root/.cargo/bin/cargo fmt -- --check - /root/.cargo/bin/cargo fmt -- --check
- name: cargo clippy - name: cargo clippy
image: ekidd/rust-musl-builder:1.51.0 image: clux/muslrust:1.56.0
commands: commands:
- rustup component add clippy
- cargo clippy --workspace --tests --all-targets --all-features -- -D warnings -D deprecated -D clippy::perf -D clippy::complexity -D clippy::dbg_macro - cargo clippy --workspace --tests --all-targets --all-features -- -D warnings -D deprecated -D clippy::perf -D clippy::complexity -D clippy::dbg_macro
- cargo clippy --workspace -- -D clippy::unwrap_used - cargo clippy --workspace -- -D clippy::unwrap_used
- name: cargo test - name: cargo test
image: ekidd/rust-musl-builder:1.51.0 image: clux/muslrust:1.56.0
environment: environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
LEMMY_CONFIG_LOCATION: ../../config/config.hjson LEMMY_CONFIG_LOCATION: ../../config/config.hjson
RUST_BACKTRACE: 1 RUST_BACKTRACE: 1
RUST_TEST_THREADS: 1 RUST_TEST_THREADS: 1
commands: commands:
- sudo apt-get update - apt-get update
- sudo apt-get -y install --no-install-recommends postgresql-client - apt-get -y install --no-install-recommends postgresql-client
- cargo test --workspace --no-fail-fast - cargo test --workspace --no-fail-fast
- name: check defaults.hjson updated - name: check defaults.hjson updated
image: ekidd/rust-musl-builder:1.51.0 image: clux/muslrust:1.56.0
commands: commands:
- ./scripts/update_config_defaults.sh config/defaults_current.hjson - ./scripts/update_config_defaults.sh config/defaults_current.hjson
- diff config/defaults.hjson config/defaults_current.hjson - diff config/defaults.hjson config/defaults_current.hjson
- name: cargo build - name: cargo build
image: ekidd/rust-musl-builder:1.51.0 image: clux/muslrust:1.56.0
commands: commands:
- cargo build - cargo build
- mv target/x86_64-unknown-linux-musl/debug/lemmy_server target/lemmy_server - mv target/x86_64-unknown-linux-musl/debug/lemmy_server target/lemmy_server
@ -129,7 +130,7 @@ steps:
- name: prepare repo - name: prepare repo
# Not sure why, but rust ARM64 builds are failing on drone for rust:1.54 and later: # Not sure why, but rust ARM64 builds are failing on drone for rust:1.54 and later:
# https://discourse.drone.io/t/arm-build-stalls-out-on-cloud-drone-io-ram-issue/9701 # https://discourse.drone.io/t/arm-build-stalls-out-on-cloud-drone-io-ram-issue/9701
image: rust:1.51-slim image: rust:1.56-slim
user: root user: root
commands: commands:
- chown 1000:1000 . -R - chown 1000:1000 . -R
@ -138,7 +139,7 @@ steps:
- git fetch --tags - git fetch --tags
- name: cargo test - name: cargo test
image: rust:1.51-slim image: rust:1.56-slim
environment: environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
LEMMY_CONFIG_LOCATION: ../../config/config.hjson LEMMY_CONFIG_LOCATION: ../../config/config.hjson
@ -152,7 +153,7 @@ steps:
# Using Debian here because there seems to be no official Alpine-based Rust docker image for ARM. # Using Debian here because there seems to be no official Alpine-based Rust docker image for ARM.
- name: cargo build - name: cargo build
image: rust:1.51-slim image: rust:1.56-slim
commands: commands:
- apt-get update - apt-get update
- apt-get -y install --no-install-recommends libssl-dev pkg-config libpq-dev - apt-get -y install --no-install-recommends libssl-dev pkg-config libpq-dev

View file

@ -25,7 +25,7 @@ lazy_static! {
static ref CLIENT: Client = Client::builder() static ref CLIENT: Client = Client::builder()
.user_agent(build_user_agent(&Settings::get())) .user_agent(build_user_agent(&Settings::get()))
.build() .build()
.unwrap(); .expect("Couldn't build client");
} }
/// We store Url on the heap because it is quite large (88 bytes). /// We store Url on the heap because it is quite large (88 bytes).

View file

@ -56,7 +56,7 @@ pub fn derive_activity_handler(input: proc_macro::TokenStream) -> proc_macro::To
.collect(); .collect();
let attrs: &Vec<TokenStream> = &attrs let attrs: &Vec<TokenStream> = &attrs
.first() .first()
.unwrap() .expect("Could not decode first attribute from token stream")
.tokens .tokens
.clone() .clone()
.into_iter() .into_iter()

View file

@ -1,43 +1,31 @@
ARG RUST_BUILDER_IMAGE=ekidd/rust-musl-builder:1.51.0 ARG RUST_BUILDER_IMAGE=clux/muslrust:1.56.0
FROM $RUST_BUILDER_IMAGE as chef
USER root
RUN cargo install cargo-chef
WORKDIR /app
# Cargo chef plan # Cargo chef plan
FROM $RUST_BUILDER_IMAGE as planner FROM chef as planner
WORKDIR /app
RUN cargo install cargo-chef
# Copy dirs # Copy dirs
COPY ./ ./ COPY . .
RUN sudo chown -R rust:rust .
RUN cargo chef prepare --recipe-path recipe.json RUN cargo chef prepare --recipe-path recipe.json
# Cargo chef cache dependencies FROM chef as builder
FROM $RUST_BUILDER_IMAGE as cacher
ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
WORKDIR /app
RUN cargo install cargo-chef
COPY --from=planner /app/recipe.json ./recipe.json
RUN sudo chown -R rust:rust .
RUN cargo chef cook --target ${CARGO_BUILD_TARGET} --recipe-path recipe.json
# Build the project
FROM $RUST_BUILDER_IMAGE as builder
ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
ARG RUSTRELEASEDIR="debug" ARG RUSTRELEASEDIR="debug"
WORKDIR /app COPY --from=planner /app/recipe.json ./recipe.json
RUN cargo chef cook --recipe-path recipe.json --target ${CARGO_BUILD_TARGET}
# Copy over the cached dependencies
COPY --from=cacher /app/target target
COPY --from=cacher /home/rust/.cargo /home/rust/.cargo
# Copy the rest of the dirs # Copy the rest of the dirs
COPY ./ ./ COPY . .
RUN sudo chown -R rust:rust . # Build the project
RUN echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs" RUN echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs"
RUN cargo build RUN cargo build --target ${CARGO_BUILD_TARGET}
# reduce binary size # reduce binary size
RUN strip ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server RUN strip ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server
@ -50,13 +38,8 @@ FROM alpine:3 as lemmy
# Install libpq for postgres # Install libpq for postgres
RUN apk add libpq RUN apk add libpq
RUN addgroup -g 1000 lemmy
RUN adduser -D -s /bin/sh -u 1000 -G lemmy lemmy
# Copy resources # Copy resources
COPY --chown=lemmy:lemmy --from=builder /app/lemmy_server /app/lemmy COPY --from=builder /app/lemmy_server /app/lemmy
RUN chown lemmy:lemmy /app/lemmy
USER lemmy
EXPOSE 8536 EXPOSE 8536
CMD ["/app/lemmy"] CMD ["/app/lemmy"]

View file

@ -1,5 +1,5 @@
# Build the project # Build the project
FROM ekidd/rust-musl-builder:1.51.0 as builder FROM clux/muslrust:1.56.0 as builder
ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
ARG RUSTRELEASEDIR="release" ARG RUSTRELEASEDIR="release"
@ -8,7 +8,6 @@ WORKDIR /app
COPY ./ ./ COPY ./ ./
RUN sudo chown -R rust:rust .
RUN echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs" RUN echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs"
RUN cargo build --release RUN cargo build --release
@ -23,13 +22,8 @@ FROM alpine:3 as lemmy
# Install libpq for postgres # Install libpq for postgres
RUN apk add libpq RUN apk add libpq
RUN addgroup -g 1000 lemmy
RUN adduser -D -s /bin/sh -u 1000 -G lemmy lemmy
# Copy resources # Copy resources
COPY --chown=lemmy:lemmy --from=builder /app/lemmy_server /app/lemmy COPY --from=builder /app/lemmy_server /app/lemmy
RUN chown lemmy:lemmy /app/lemmy
USER lemmy
EXPOSE 8536 EXPOSE 8536
CMD ["/app/lemmy"] CMD ["/app/lemmy"]

View file

@ -65,7 +65,7 @@ async fn main() -> Result<(), LemmyError> {
let pool2 = pool.clone(); let pool2 = pool.clone();
thread::spawn(move || { thread::spawn(move || {
scheduled_tasks::setup(pool2); scheduled_tasks::setup(pool2).expect("Couldn't set up scheduled_tasks");
}); });
// Set up the rate limiter // Set up the rate limiter

View file

@ -3,14 +3,15 @@ use clokwerk::{Scheduler, TimeUnits};
// Import week days and WeekDay // Import week days and WeekDay
use diesel::{sql_query, PgConnection, RunQueryDsl}; use diesel::{sql_query, PgConnection, RunQueryDsl};
use lemmy_db_schema::{source::activity::Activity, DbPool}; use lemmy_db_schema::{source::activity::Activity, DbPool};
use lemmy_utils::LemmyError;
use log::info; use log::info;
use std::{thread, time::Duration}; use std::{thread, time::Duration};
/// Schedules various cleanup tasks for lemmy in a background thread /// Schedules various cleanup tasks for lemmy in a background thread
pub fn setup(pool: DbPool) { pub fn setup(pool: DbPool) -> Result<(), LemmyError> {
let mut scheduler = Scheduler::new(); let mut scheduler = Scheduler::new();
let conn = pool.get().unwrap(); let conn = pool.get()?;
active_counts(&conn); active_counts(&conn);
// On startup, reindex the tables non-concurrently // On startup, reindex the tables non-concurrently
@ -21,7 +22,7 @@ pub fn setup(pool: DbPool) {
reindex_aggregates_tables(&conn, true); reindex_aggregates_tables(&conn, true);
}); });
let conn = pool.get().unwrap(); let conn = pool.get()?;
clear_old_activities(&conn); clear_old_activities(&conn);
scheduler.every(1.weeks()).run(move || { scheduler.every(1.weeks()).run(move || {
clear_old_activities(&conn); clear_old_activities(&conn);