Browse Source

Bump dev dockerfile to newer rust version, move to cargo-chef, properly deserialize iframely json

fix/youtube-beforeyoucontinue
DashEightMate 2 years ago
parent
commit
3ab0d72c5d
  1. 2
      .dockerignore
  2. 73
      docker/dev/Dockerfile
  3. 4
      docker/dev/docker-compose.yml
  4. 8
      docker/lemmy.hjson
  5. 30
      server/src/lib.rs

2
.dockerignore

@ -4,7 +4,7 @@
# build folders and similar which are not needed for the docker build
ui/node_modules
server/target
# docker/dev/volumes
docker/dev/volumes
# docker/federation/volumes
# docker/federation-test/volumes
#.git # needed to get git sha

73
docker/dev/Dockerfile

@ -1,52 +1,53 @@
FROM node:10-jessie as node
ARG RUST_BUILDER=ekidd/rust-musl-builder:latest
WORKDIR /app/ui
FROM ekidd/rust-musl-builder:nightly-2020-05-07 as rust
FROM $RUST_BUILDER as planner
# Cache deps
WORKDIR /app
#install cargo chef
RUN cargo install cargo-chef
RUN sudo chown -R rust:rust .
RUN USER=root cargo new server
# Install cargo-build-deps
RUN cargo install --git https://github.com/romac/cargo-build-deps.git
WORKDIR /app/server
RUN mkdir -p lemmy_db/src/ \
lemmy_utils/src/ \
lemmy_api_structs/src/ \
lemmy_rate_limit/src/ \
lemmy
# Copy the cargo tomls
COPY server/Cargo.toml server/Cargo.lock server/build.rs ./
COPY server/lemmy_db/Cargo.toml ./lemmy_db/
COPY server/lemmy_utils/Cargo.toml ./lemmy_utils/
COPY server/lemmy_api_structs/Cargo.toml ./lemmy_api_structs/
COPY server/lemmy_rate_limit/Cargo.toml ./lemmy_rate_limit/
# Cache the deps
RUN cargo build-deps
# Copy the src folders
COPY server/src ./src/
COPY server/lemmy_db/src ./lemmy_db/src/
COPY server/lemmy_utils/src/ ./lemmy_utils/src/
COPY server/lemmy_api_structs/src/ ./lemmy_api_structs/src/
COPY server/lemmy_rate_limit/src/ ./lemmy_rate_limit/src/
COPY server/migrations ./migrations/
COPY .git/ ./.git/
# Build for debug
COPY server/ .
# list off needed dependencies
RUN cargo chef prepare --recipe-path recipe.json
FROM ${RUST_BUILDER} as cacher
WORKDIR /app/server
RUN cargo install cargo-chef
COPY --from=planner /app/server/recipe.json recipe.json
RUN sudo chown -R rust:rust .
RUN cargo chef cook --recipe-path recipe.json
FROM ${RUST_BUILDER} as builder
WORKDIR /app/server
COPY server/ .
COPY --from=cacher /app/server/target ./target
COPY --from=cacher /home/rust/.cargo /home/rust/.cargo
RUN sudo chown -R rust:rust .
RUN cargo build
FROM ekidd/rust-musl-builder:nightly-2020-05-07 as docs
FROM ${RUST_BUILDER} as docs
WORKDIR /app
COPY docs ./docs
RUN sudo chown -R rust:rust .
RUN mdbook build docs/
FROM alpine:3.12
# Install libpq for postgres
@ -57,7 +58,7 @@ RUN apk add espeak
# Copy resources
COPY server/config/defaults.hjson /config/defaults.hjson
COPY --from=rust /app/server/target/x86_64-unknown-linux-musl/debug/lemmy_server /app/lemmy
COPY --from=builder /app/server/target/x86_64-unknown-linux-musl/debug/lemmy_server /app/lemmy
COPY --from=docs /app/docs/book/ /app/dist/documentation/
RUN addgroup -g 1000 lemmy

4
docker/dev/docker-compose.yml

@ -3,7 +3,7 @@ version: '3.3'
services:
lemmy:
image: lemmy-dev:latest
image: hexbear-dev:latest
ports:
- 8536:8536
restart: always
@ -39,7 +39,7 @@ services:
restart: always
iframely:
image: jolt/iframely:v1.4.3
image: jolt/iframely:v1.6.1
ports:
- 8061:80
volumes:

8
docker/lemmy.hjson

@ -4,15 +4,15 @@
setup: {
# username for the admin user
admin_username: "lemmy"
admin_username: "hexdev"
# password for the admin user
admin_password: "lemmy"
admin_password: "hexbear"
# name of the site (can be changed later)
site_name: "lemmy-test"
site_name: "hexbear docker dev"
}
# the domain name of your instance (eg "dev.lemmy.ml")
hostname: "my_domain"
hostname: "localhost:4444"
# address where lemmy should listen for incoming requests
bind: "0.0.0.0"
# port where lemmy should listen for incoming requests

30
server/src/lib.rs

@ -102,10 +102,30 @@ impl LemmyContext {
#[derive(Deserialize, Debug)]
pub struct IframelyResponse {
title: Option<String>,
html: Option<String>,
links: Option<IframelyLinks>,
meta: Option<IframelyMeta>
}
#[derive(Deserialize, Debug)]
pub struct IframelyMeta {
description: Option<String>,
thumbnail_url: Option<String>,
title: Option<String>,
site: Option<String>
}
#[derive(Deserialize, Debug)]
pub struct IframelyLink {
href: Option<String>,
html: Option<String>,
#[serde(rename = "type")]
content_type: Option<String>
}
#[derive(Deserialize, Debug)]
pub struct IframelyLinks {
icon: Option<Vec<IframelyLink>>,
thumbnail: Option<Vec<IframelyLink>>,
}
pub async fn fetch_iframely(client: &Client, url: &str) -> Result<IframelyResponse, LemmyError> {
@ -168,7 +188,11 @@ async fn fetch_iframely_and_pictrs_data(
// Fetch iframely data
let (iframely_title, iframely_description, iframely_thumbnail_url, iframely_html) =
match fetch_iframely(client, url).await {
Ok(res) => (res.title, res.description, res.thumbnail_url, res.html),
Ok(res) => {
let meta = res.meta.map(|m| (m.title, m.description)).unwrap_or((None, None));
let thumbnail = res.links.map(|l| l.thumbnail.map(|t| t[0].href.clone()).flatten()).flatten();
(meta.0, meta.1, thumbnail, res.html)
},
Err(e) => {
error!("iframely err: {}", e);
(None, None, None, None)

Loading…
Cancel
Save