Browse Source

Create docker.exs and docker-entrypoint + round out Dockerfile

At this point, the implementation is completely working and has been
tested running live and federating with other instances.
underscore-world
Ashlynn Anderson 1 month ago
parent
commit
4a418698db
3 changed files with 97 additions and 7 deletions
  1. 16
    7
      Dockerfile
  2. 67
    0
      config/docker.exs
  3. 14
    0
      docker-entrypoint.sh

+ 16
- 7
Dockerfile View File

@@ -2,7 +2,7 @@ FROM rinpatch/elixir:1.9.0-rc.0-alpine as build
2 2
 
3 3
 COPY . .
4 4
 
5
-ENV MIX_ENV prod
5
+ENV MIX_ENV=prod
6 6
 
7 7
 RUN apk add git gcc g++ musl-dev make &&\
8 8
 	echo "import Mix.Config" > config/prod.secret.exs &&\
@@ -15,18 +15,27 @@ RUN mix deps.get --only prod &&\
15 15
 
16 16
 FROM alpine:latest
17 17
 
18
+ARG HOME=/opt/pleroma
19
+ARG DATA=/var/lib/pleroma
20
+
18 21
 RUN echo "http://nl.alpinelinux.org/alpine/latest-stable/community" >> /etc/apk/repositories &&\
19 22
 	apk update &&\
20 23
 	apk add ncurses postgresql-client
21 24
 
22
-RUN adduser --system --shell /bin/false --home /opt/pleroma pleroma &&\
23
-	mkdir -p /var/lib/pleroma/uploads &&\
24
-	chown -R pleroma /var/lib/pleroma &&\
25
-	mkdir -p /var/lib/pleroma/static &&\
26
-	chown -R pleroma /var/lib/pleroma &&\
25
+RUN adduser --system --shell /bin/false --home ${HOME} pleroma &&\
26
+	mkdir -p ${DATA}/uploads &&\
27
+	mkdir -p ${DATA}/static &&\
28
+	chown -R pleroma ${DATA} &&\
27 29
 	mkdir -p /etc/pleroma &&\
28 30
 	chown -R pleroma /etc/pleroma
29 31
 
30 32
 USER pleroma
31 33
 
32
-COPY --from=build --chown=pleroma:0 /release/ /opt/pleroma/
34
+COPY --from=build --chown=pleroma:0 /release ${HOME}
35
+
36
+COPY ./config/docker.exs /etc/pleroma/config.exs
37
+COPY ./docker-entrypoint.sh ${HOME}
38
+
39
+EXPOSE 4000
40
+
41
+ENTRYPOINT ["/opt/pleroma/docker-entrypoint.sh"]

+ 67
- 0
config/docker.exs View File

@@ -0,0 +1,67 @@
1
+import Config
2
+
3
+config :pleroma, Pleroma.Web.Endpoint,
4
+   url: [host: System.get_env("DOMAIN", "localhost"), scheme: "https", port: 443],
5
+   http: [ip: {0, 0, 0, 0}, port: 4000]
6
+
7
+config :pleroma, :instance,
8
+  name: System.get_env("INSTANCE_NAME", "Pleroma"),
9
+  email: System.get_env("ADMIN_EMAIL"),
10
+  notify_email: System.get_env("NOTIFY_EMAIL"),
11
+  limit: 5000,
12
+  registrations_open: false,
13
+  dynamic_configuration: true
14
+
15
+config :pleroma, Pleroma.Repo,
16
+  adapter: Ecto.Adapters.Postgres,
17
+  username: System.get_env("DB_USER", "pleroma"),
18
+  password: System.fetch_env!("DB_PASS"),
19
+  database: System.get_env("DB_NAME", "pleroma"),
20
+  hostname: System.get_env("DB_HOST", "db"),
21
+  pool_size: 10
22
+
23
+# Configure web push notifications
24
+config :web_push_encryption, :vapid_details,
25
+  subject: "mailto:#{System.get_env("NOTIFY_EMAIL")}"
26
+
27
+config :pleroma, :database, rum_enabled: false
28
+config :pleroma, :instance, static_dir: "/var/lib/pleroma/static"
29
+config :pleroma, Pleroma.Uploaders.Local, uploads: "/var/lib/pleroma/uploads"
30
+
31
+# We can't store the secrets in this file, since this is baked into the docker image
32
+if not File.exists?("/var/lib/pleroma/secret.exs") do
33
+  secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64)
34
+  signing_salt = :crypto.strong_rand_bytes(8) |> Base.encode64() |> binary_part(0, 8)
35
+  {web_push_public_key, web_push_private_key} = :crypto.generate_key(:ecdh, :prime256v1)
36
+
37
+  secret_file = EEx.eval_string(
38
+    """
39
+    import Config
40
+    
41
+    config :pleroma, Pleroma.Web.Endpoint,
42
+      secret_key_base: "<%= secret %>",
43
+      signing_salt: "<%= signing_salt %>"
44
+    
45
+    config :web_push_encryption, :vapid_details,
46
+      public_key: "<%= web_push_public_key %>",
47
+      private_key: "<%= web_push_private_key %>"
48
+    """,
49
+    secret: secret,
50
+    signing_salt: signing_salt,
51
+    web_push_public_key: Base.url_encode64(web_push_public_key, padding: false),
52
+    web_push_private_key: Base.url_encode64(web_push_private_key, padding: false)
53
+  )
54
+
55
+  File.write("/var/lib/pleroma/secret.exs", secret_file)
56
+end
57
+
58
+import_config("/var/lib/pleroma/secret.exs")
59
+
60
+# For additional user config
61
+if File.exists?("/var/lib/pleroma/config.exs"),
62
+  do: import_config("/var/lib/pleroma/config.exs"),
63
+  else: File.write("/var/lib/pleroma/config.exs", """
64
+  import Config
65
+  
66
+  # For additional configuration outside of environmental variables
67
+  """)

+ 14
- 0
docker-entrypoint.sh View File

@@ -0,0 +1,14 @@
1
+#!/bin/ash
2
+
3
+set -e
4
+
5
+echo "-- Waiting for database..."
6
+while ! pg_isready -U ${DB_USER:-pleroma} -d postgres://${DB_HOST:-db}:5432/${DB_NAME:-pleroma} -t 1; do
7
+    sleep 1s
8
+done
9
+
10
+echo "-- Running migrations..."
11
+$HOME/bin/pleroma_ctl migrate
12
+
13
+echo "-- Starting!"
14
+exec $HOME/bin/pleroma start

Loading…
Cancel
Save