From d961d6151f7b236b06ddc10ecd091fa32074e97d Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sun, 6 Feb 2022 13:27:01 -0500 Subject: [PATCH] Docker setup --- .gitignore | 1 + config/runtime.exs | 6 ++++++ docker-compose.yml | 13 +++++++++++++ docker/app/run-development | 8 ++++++++ docker/files/Dockerfile | 2 ++ docker/files/run-docker-container.sh | 28 ++++++++++++++++++++++++++++ mix.exs | 3 +++ mix.lock | 3 +++ 8 files changed, 64 insertions(+) create mode 100644 docker/files/Dockerfile create mode 100644 docker/files/run-docker-container.sh diff --git a/.gitignore b/.gitignore index 6b5b12c6..354e8069 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ npm-debug.log # we ignore priv/static. You may want to comment # this depending on your deployment strategy. /priv/static/ +/priv/s3 # Intellij IDEA .idea diff --git a/config/runtime.exs b/config/runtime.exs index d8719a8e..bece7870 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -67,6 +67,12 @@ if is_nil(System.get_env("START_WORKER")) do config :exq, queues: [] end +# S3 config +config :ex_aws, :s3, + scheme: System.fetch_env!("S3_SCHEME"), + host: System.fetch_env!("S3_HOST"), + port: System.fetch_env!("S3_PORT") + if config_env() != :test do # Database config config :philomena, Philomena.Repo, diff --git a/docker-compose.yml b/docker-compose.yml index d71b0c03..84c6d7c9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -35,6 +35,12 @@ services: - MAILER_ADDRESS=noreply@philomena.local - START_ENDPOINT=true - SITE_DOMAINS=localhost + - S3_SCHEME=http + - S3_HOST=files + - S3_PORT=80 + - S3_BUCKET=philomena + - AWS_ACCESS_KEY_ID=local-identity + - AWS_SECRET_ACCESS_KEY=local-credential working_dir: /srv/philomena tty: true volumes: @@ -71,6 +77,13 @@ services: logging: driver: "none" + files: + build: + context: . + dockerfile: ./docker/app/Dockerfile + volumes: + - .:/srv/philomena + web: build: context: . diff --git a/docker/app/run-development b/docker/app/run-development index dc3e7009..5e171745 100755 --- a/docker/app/run-development +++ b/docker/app/run-development @@ -1,5 +1,13 @@ #!/usr/bin/env sh +# Create S3 dirs +mkdir -p /srv/philomena/priv/s3/philomena +ln -s /srv/philomena/priv/system/images/thumbs /srv/philomena/priv/s3/philomena/images +ln -s /srv/philomena/priv/system/images /srv/philomena/priv/s3/philomena/adverts +ln -s /srv/philomena/priv/system/images /srv/philomena/priv/s3/philomena/avatars +ln -s /srv/philomena/priv/system/images /srv/philomena/priv/s3/philomena/badges +ln -s /srv/philomena/priv/system/images /srv/philomena/priv/s3/philomena/tags + # For compatibility with musl libc export CARGO_FEATURE_DISABLE_INITIAL_EXEC_TLS=1 export CARGO_HOME=/srv/philomena/.cargo diff --git a/docker/files/Dockerfile b/docker/files/Dockerfile new file mode 100644 index 00000000..9316f2c1 --- /dev/null +++ b/docker/files/Dockerfile @@ -0,0 +1,2 @@ +FROM andrewgaul/s3proxy:sha-2e61c38 +COPY docker/files/run-docker-container.sh /opt/s3proxy/run-docker-container.sh diff --git a/docker/files/run-docker-container.sh b/docker/files/run-docker-container.sh new file mode 100644 index 00000000..171cbd55 --- /dev/null +++ b/docker/files/run-docker-container.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# forked because it doesn't let me configure the filesystem basedir via env +mkdir -p /srv/philomena/priv/s3 + +exec java \ + -DLOG_LEVEL="${LOG_LEVEL}" \ + -Ds3proxy.endpoint="${S3PROXY_ENDPOINT}" \ + -Ds3proxy.virtual-host="${S3PROXY_VIRTUALHOST}" \ + -Ds3proxy.authorization="${S3PROXY_AUTHORIZATION}" \ + -Ds3proxy.identity="${S3PROXY_IDENTITY}" \ + -Ds3proxy.credential="${S3PROXY_CREDENTIAL}" \ + -Ds3proxy.cors-allow-all="${S3PROXY_CORS_ALLOW_ALL}" \ + -Ds3proxy.cors-allow-origins="${S3PROXY_CORS_ALLOW_ORIGINS}" \ + -Ds3proxy.cors-allow-methods="${S3PROXY_CORS_ALLOW_METHODS}" \ + -Ds3proxy.cors-allow-headers="${S3PROXY_CORS_ALLOW_HEADERS}" \ + -Ds3proxy.ignore-unknown-headers="${S3PROXY_IGNORE_UNKNOWN_HEADERS}" \ + -Djclouds.provider="${JCLOUDS_PROVIDER}" \ + -Djclouds.identity="${JCLOUDS_IDENTITY}" \ + -Djclouds.credential="${JCLOUDS_CREDENTIAL}" \ + -Djclouds.endpoint="${JCLOUDS_ENDPOINT}" \ + -Djclouds.region="${JCLOUDS_REGION}" \ + -Djclouds.regions="${JCLOUDS_REGIONS}" \ + -Djclouds.keystone.version="${JCLOUDS_KEYSTONE_VERSION}" \ + -Djclouds.keystone.scope="${JCLOUDS_KEYSTONE_SCOPE}" \ + -Djclouds.keystone.project-domain-name="${JCLOUDS_KEYSTONE_PROJECT_DOMAIN_NAME}" \ + -Djclouds.filesystem.basedir="/srv/philomena/priv/s3" \ + -jar /opt/s3proxy/s3proxy \ + --properties /dev/null diff --git a/mix.exs b/mix.exs index fb40561f..aa3ce11e 100644 --- a/mix.exs +++ b/mix.exs @@ -69,6 +69,9 @@ defmodule Philomena.MixProject do {:castore, "~> 0.1"}, {:mint, "~> 1.2"}, {:exq, "~> 0.14"}, + {:ex_aws, "~> 2.0"}, + {:ex_aws_s3, "~> 2.0"}, + {:sweet_xml, "~> 0.7"}, # Markdown {:rustler, "~> 0.22"}, diff --git a/mix.lock b/mix.lock index 0b5359b3..8e0f530e 100644 --- a/mix.lock +++ b/mix.lock @@ -27,6 +27,8 @@ "elixir_make": {:hex, :elixir_make, "0.6.3", "bc07d53221216838d79e03a8019d0839786703129599e9619f4ab74c8c096eac", [:mix], [], "hexpm", "f5cbd651c5678bcaabdbb7857658ee106b12509cd976c2c2fca99688e1daf716"}, "elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, + "ex_aws": {:hex, :ex_aws, "2.2.10", "064139724335b00b6665af7277189afc9ed507791b1ccf2698dadc7c8ad892e8", [:mix], [{:configparser_ex, "~> 4.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8 or ~> 3.0", [hex: :jsx, repo: "hexpm", optional: true]}, {:mime, "~> 1.2 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:sweet_xml, "~> 0.7", [hex: :sweet_xml, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "98acb63f74b2f0822be219c5c2f0e8d243c2390f5325ad0557b014d3360da47e"}, + "ex_aws_s3": {:hex, :ex_aws_s3, "2.3.2", "92a63b72d763b488510626d528775b26831f5c82b066a63a3128054b7a09de28", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:sweet_xml, ">= 0.0.0", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm", "b235b27131409bcc293c343bf39f1fbdd32892aa237b3f13752e914dc2979960"}, "exq": {:hex, :exq, "0.16.1", "140d78e95a538d265d23a1e7a090f501c40c799f269b8b503f4cbd962447e708", [:mix], [{:elixir_uuid, ">= 1.2.0", [hex: :elixir_uuid, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, ">= 1.2.0 and < 5.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:redix, ">= 0.9.0", [hex: :redix, repo: "hexpm", optional: false]}], "hexpm", "ce70231e2892130b0f80d1bbc8d6ddd22d89d1157b32e783a933eaadb31bc821"}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, "gen_smtp": {:hex, :gen_smtp, "1.1.1", "bf9303c31735100631b1d708d629e4c65944319d1143b5c9952054f4a1311d85", [:rebar3], [{:hut, "1.3.0", [hex: :hut, repo: "hexpm", optional: false]}, {:ranch, ">= 1.7.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "51bc50cc017efd4a4248cbc39ea30fb60efa7d4a49688986fafad84434ff9ab7"}, @@ -73,6 +75,7 @@ "slime": {:hex, :slime, "1.3.0", "153cebb4a837efaf55fb09dff0d79374ad74af835a0288feccbfd9cf606446f9", [:mix], [{:neotoma, "~> 1.7", [hex: :neotoma, repo: "hexpm", optional: false]}], "hexpm", "303b58f05d740a5fe45165bcadfe01da174f1d294069d09ebd7374cd36990a27"}, "sobelow": {:hex, :sobelow, "0.11.1", "23438964486f8112b41e743bbfd402da3e5b296fdc9eacab29914b79c48916dd", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "9897363a7eff96f4809304a90aad819e2ad5e5d24db547af502885146746a53c"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, + "sweet_xml": {:hex, :sweet_xml, "0.7.2", "4729f997286811fabdd8288f8474e0840a76573051062f066c4b597e76f14f9f", [:mix], [], "hexpm", "6894e68a120f454534d99045ea3325f7740ea71260bc315f82e29731d570a6e8"}, "telemetry": {:hex, :telemetry, "0.4.3", "a06428a514bdbc63293cd9a6263aad00ddeb66f608163bdec7c8995784080818", [:rebar3], [], "hexpm", "eb72b8365ffda5bed68a620d1da88525e326cb82a75ee61354fc24b844768041"}, "tesla": {:hex, :tesla, "1.4.4", "bb89aa0c9745190930366f6a2ac612cdf2d0e4d7fff449861baa7875afd797b2", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:finch, "~> 0.3", [hex: :finch, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "d5503a49f9dec1b287567ea8712d085947e247cb11b06bc54adb05bfde466457"}, "toml": {:hex, :toml, "0.5.2", "e471388a8726d1ce51a6b32f864b8228a1eb8edc907a0edf2bb50eab9321b526", [:mix], [], "hexpm", "f1e3dabef71fb510d015fad18c0e05e7c57281001141504c6b69d94e99750a07"},