|
| 1 | +# We need to grab "psql" from the Postgres image for database setup |
| 2 | +FROM postgres:17.7-alpine AS pg |
| 3 | + |
| 4 | +# |
| 5 | +# Step 1: Build Philomena release |
| 6 | +# |
| 7 | + |
| 8 | +FROM elixir:1.18.4-alpine AS builder |
| 9 | + |
| 10 | +WORKDIR /tmp/philomena |
| 11 | + |
| 12 | +ENV MIX_ENV=prod |
| 13 | +ENV NODE_ENV=production |
| 14 | +ENV PATH=$PATH:/root/.cargo/bin |
| 15 | + |
| 16 | +ADD https://api.github.com/repos/philomena-dev/fiberglass-wrapper/git/refs/heads/master /tmp/fiberglass_wrapper_version.json |
| 17 | + |
| 18 | +# Install dependencies and build tools |
| 19 | +RUN apk update --allow-untrusted \ |
| 20 | + && apk add build-base git npm nodejs wget rust cargo --allow-untrusted \ |
| 21 | + && mix local.hex --force \ |
| 22 | + && mix local.rebar --force |
| 23 | + |
| 24 | +# Build fiberglass-wrapper from source |
| 25 | +RUN git clone --depth 1 https://github.com/philomena-dev/fiberglass-wrapper /tmp/fiberglass_wrapper \ |
| 26 | + && cd /tmp/fiberglass_wrapper \ |
| 27 | + && cargo build --release |
| 28 | + |
| 29 | +# Copy repo files into the image |
| 30 | +COPY . /tmp/philomena |
| 31 | + |
| 32 | +# Install and compile assets |
| 33 | +RUN cd /tmp/philomena/assets \ |
| 34 | + && NODE_ENV=development npm install \ |
| 35 | + && npm run deploy |
| 36 | + |
| 37 | +# Build the application and create symlinks for easier access |
| 38 | +RUN cd /tmp/philomena \ |
| 39 | + && mix deps.get \ |
| 40 | + && mix release --overwrite |
| 41 | + |
| 42 | +# Digest and copy static assets |
| 43 | +RUN mix phx.digest -o /tmp/philomena/_build/prod/rel/philomena/lib/philomena-*/priv/static |
| 44 | + |
| 45 | +# |
| 46 | +# Step 2: Copy only the final release into a minimal image |
| 47 | +# Also copy psql from the Postgres image |
| 48 | +# |
| 49 | + |
| 50 | +FROM alpine:3.23 |
| 51 | + |
| 52 | +LABEL org.opencontainers.image.authors="liamwhite <liamwhite@users.noreply.github.com>, Nighty <luna@nighty.cloud>, and contributors" |
| 53 | +LABEL org.opencontainers.image.description="The official Philomena Docker image intended for production use." |
| 54 | +LABEL org.opencontainers.image.source="https://github.com/philomena-dev/philomena" |
| 55 | +LABEL org.opencontainers.image.licenses="AGPL-3.0-only" |
| 56 | + |
| 57 | +# Install runtime dependencies |
| 58 | +# Required by Erlang/Elixir: libncursesw libstdc++ libgcc |
| 59 | +# Required by psql: libedit krb5-libs libldap |
| 60 | +RUN apk update \ |
| 61 | + && apk add --no-cache libncursesw libstdc++ libgcc libedit krb5-libs libldap |
| 62 | + |
| 63 | +# Set up a non-root user to run the application |
| 64 | +RUN addgroup -g 1000 -S philomena \ |
| 65 | + && adduser -u 1000 -S philomena -G philomena |
| 66 | + |
| 67 | +# Copy the finished release and the config (because of .json files) from the builder stage... |
| 68 | +COPY --from=builder --chown=1000:1000 /tmp/philomena/_build/prod/rel/philomena /srv/philomena |
| 69 | +COPY --from=builder --chown=1000:1000 /tmp/philomena/config /srv/philomena/config |
| 70 | + |
| 71 | +# Copy fiberglass-wrapper executable too |
| 72 | +COPY --from=builder /tmp/fiberglass_wrapper/target/release/fiberglass-wrapper /usr/local/bin/fiberglass-wrapper |
| 73 | + |
| 74 | +# ...and the production scripts from the repository |
| 75 | +COPY --chown=1000:1000 docker/production/purge-cache /usr/local/bin/purge-cache |
| 76 | +COPY --chown=1000:1000 docker/production/run-cron /usr/local/bin/run-cron |
| 77 | +COPY --chown=1000:1000 docker/production/run-cron-daily /usr/local/bin/run-cron-daily |
| 78 | +COPY --chown=1000:1000 docker/production/run-production /usr/local/bin/run-production |
| 79 | +COPY --chown=1000:1000 docker/production/setup-production /usr/local/bin/setup-production |
| 80 | +COPY --chown=1000:1000 docker/production/programs/* /usr/local/bin/ |
| 81 | + |
| 82 | +# Copy postgres client. |
| 83 | +COPY --from=pg /usr/local/bin/psql /usr/local/bin/psql |
| 84 | +COPY --from=pg /usr/local/bin/pg_isready /usr/local/bin/pg_isready |
| 85 | +COPY --from=pg /usr/local/lib/libpq.so /usr/local/lib/libpq.so |
| 86 | +COPY --from=pg /usr/local/lib/libpq.so.5 /usr/local/lib/libpq.so.5 |
| 87 | +COPY --from=pg /usr/local/lib/libpq.so.5.17 /usr/local/lib/libpq.so.5.17 |
| 88 | + |
| 89 | +# A "philomena" symlink for easier access |
| 90 | +RUN ln -sf /srv/philomena/bin/philomena /usr/local/bin/philomena |
| 91 | + |
| 92 | +USER philomena |
| 93 | + |
| 94 | +# Create the static assets symlink as the philomena user |
| 95 | +RUN ln -sf /srv/philomena/lib/philomena-*/priv /srv/philomena/priv |
| 96 | + |
| 97 | +WORKDIR /srv/philomena |
| 98 | + |
| 99 | +EXPOSE 4000-4002 |
| 100 | + |
| 101 | +CMD ["/usr/local/bin/run-production"] |
0 commit comments