]> Untitled Git - lemmy.git/blob - Dockerfile
0eb5f60d142ead344acfbdf9ec770fd3870aa475
[lemmy.git] / Dockerfile
1 FROM node:10-jessie as node
2 WORKDIR /app/ui
3
4 # Cache deps
5 COPY ui/package.json ui/yarn.lock ./
6 RUN yarn install --pure-lockfile
7
8 # Build 
9 COPY ui /app/ui
10 RUN yarn build
11
12 FROM rust:latest as rust
13
14 # Install musl
15 RUN apt-get update
16 RUN apt-get install musl-tools -y
17 RUN rustup target add x86_64-unknown-linux-musl
18
19 # Cache deps
20 WORKDIR /app
21 RUN USER=root cargo new server
22 WORKDIR /app/server
23 COPY server/Cargo.toml server/Cargo.lock ./
24 RUN  mkdir -p ./src/bin \
25   && echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs 
26 RUN RUSTFLAGS=-Clinker=musl-gcc cargo build --release --target=x86_64-unknown-linux-musl
27 RUN rm -f ./target/x86_64-unknown-linux-musl/release/deps/lemmy_server*
28 COPY server/src ./src/
29 COPY server/migrations ./migrations/
30
31 # build for release
32 RUN RUSTFLAGS=-Clinker=musl-gcc cargo build --frozen --release --target=x86_64-unknown-linux-musl
33
34 # Get diesel-cli on there just in case
35 # RUN cargo install diesel_cli --no-default-features --features postgres
36
37 FROM alpine:latest
38
39 # Install libpq for postgres
40 RUN apk add libpq
41
42 # Copy resources
43 COPY --from=rust /app/server/target/x86_64-unknown-linux-musl/release/lemmy_server /app/lemmy
44 COPY --from=node /app/ui/dist /app/dist
45 RUN addgroup -g 1000 lemmy
46 RUN adduser -D -s /bin/sh -u 1000 -G lemmy lemmy
47 RUN chown lemmy:lemmy /app/lemmy
48 USER lemmy
49 EXPOSE 8536
50 CMD ["/app/lemmy"]