]> Untitled Git - lemmy.git/commitdiff
Docker image now down to 35 MB, using alpine.
authorDessalines <tyhou13@gmx.com>
Tue, 14 May 2019 00:46:29 +0000 (17:46 -0700)
committerDessalines <tyhou13@gmx.com>
Tue, 14 May 2019 00:46:29 +0000 (17:46 -0700)
Dockerfile
docker-compose.yml
docs/goals.md

index f30d57bb73a40ece0574dee6a71dfbe0515edb3d..0eb5f60d142ead344acfbdf9ec770fd3870aa475 100644 (file)
@@ -1,43 +1,50 @@
 FROM node:10-jessie as node
-#If encounter Invalid cross-device error -run on host 'echo N | sudo tee /sys/module/overlay/parameters/metacopy'
 WORKDIR /app/ui
 
+# Cache deps
 COPY ui/package.json ui/yarn.lock ./
-RUN yarn install --pure-lockfile # This caches your deps
+RUN yarn install --pure-lockfile
+
+# Build 
 COPY ui /app/ui
 RUN yarn build
 
-FROM rust:1.33 as rust
+FROM rust:latest as rust
+
+# Install musl
+RUN apt-get update
+RUN apt-get install musl-tools -y
+RUN rustup target add x86_64-unknown-linux-musl
 
-# create a new empty shell project
+# Cache deps
 WORKDIR /app
 RUN USER=root cargo new server
 WORKDIR /app/server
-
-# copy over your manifests
 COPY server/Cargo.toml server/Cargo.lock ./
-
-# this build step will cache your dependencies
 RUN  mkdir -p ./src/bin \
   && echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs 
-RUN cargo build --release
-RUN rm -r ./target/release/.fingerprint/lemmy_server-*
-
-# copy your source tree
-# RUN rm -rf ./src/
+RUN RUSTFLAGS=-Clinker=musl-gcc cargo build --release --target=x86_64-unknown-linux-musl
+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
-RUN mv /app/server/target/release/lemmy_server /app/lemmy
+RUN RUSTFLAGS=-Clinker=musl-gcc cargo build --frozen --release --target=x86_64-unknown-linux-musl
 
 # Get diesel-cli on there just in case
 # RUN cargo install diesel_cli --no-default-features --features postgres
 
-# The output image
-# FROM debian:stable-slim
-# RUN apt-get -y update && apt-get install -y postgresql-client
-# COPY --from=rust /app/server/target/release/lemmy /app/lemmy
+FROM alpine:latest
+
+# Install libpq for postgres
+RUN apk add libpq
+
+# Copy resources
+COPY --from=rust /app/server/target/x86_64-unknown-linux-musl/release/lemmy_server /app/lemmy
 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"]
index 1f86c53122a3e2bb88cc9cf7b262390806c8d77f..2b9f317181bf67c307634be79545d190015d7310 100644 (file)
@@ -16,7 +16,6 @@ services:
   lemmy:
     build: 
       context: .
-    command: /bin/sh -c /app/lemmy
     ports:
       - "8536:8536"
     environment:
index 1c627df8387e81c9e6341e321f8e9d4583b72dbe..0d92ab657643e2d43dfb88fdb8d353cddce317da 100644 (file)
@@ -35,6 +35,7 @@
 - [Classification types.](https://www.reddit.com/r/ModeratorDuck/wiki/subreddit_classification)
 - [RES expando - Possibly make this into a switching react component.](https://github.com/honestbleeps/Reddit-Enhancement-Suite/tree/d21f55c21e734f47d8ed03fe0ebce5b16653b0bd/lib/modules/hosts)
 - [Temp Icon](https://www.flaticon.com/free-icon/mouse_194242)
+- [Rust docker build](https://shaneutt.com/blog/rust-fast-small-docker-image-builds/)
 - Activitypub guides
   - https://blog.joinmastodon.org/2018/06/how-to-implement-a-basic-activitypub-server/
   - https://raw.githubusercontent.com/w3c/activitypub/gh-pages/activitypub-tutorial.txt