Skip to content

Commit b0f5bde

Browse files
author
Burgy Benjamin
committed
Initial commit, project is running in Docker.
0 parents  commit b0f5bde

32 files changed

+974
-0
lines changed

.dockerignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This file excludes paths from the Docker build context.
2+
#
3+
# By default, Docker's build context includes all files (and folders) in the
4+
# current directory. Even if a file isn't copied into the container it is still sent to
5+
# the Docker daemon.
6+
#
7+
# There are multiple reasons to exclude files from the build context:
8+
#
9+
# 1. Prevent nested folders from being copied into the container (ex: exclude
10+
# /assets/node_modules when copying /assets)
11+
# 2. Reduce the size of the build context and improve build time (ex. /build, /deps, /doc)
12+
# 3. Avoid sending files containing sensitive information
13+
#
14+
# More information on using .dockerignore is available here:
15+
# https://docs.docker.com/engine/reference/builder/#dockerignore-file
16+
17+
.dockerignore
18+
19+
# Ignore git, but keep git HEAD and refs to access current commit hash if needed:
20+
#
21+
# $ cat .git/HEAD | awk '{print ".git/"$2}' | xargs cat
22+
# d0b8727759e1e0e7aa3d41707d12376e373d5ecc
23+
.git
24+
!.git/HEAD
25+
!.git/refs
26+
27+
# Common development/test artifacts
28+
/cover/
29+
/doc/
30+
/test/
31+
/tmp/
32+
.elixir_ls
33+
34+
# Mix artifacts
35+
/_build/
36+
/deps/
37+
*.ez
38+
39+
# Generated on crash by the VM
40+
erl_crash.dump
41+
42+
# Static artifacts - These should be fetched and built inside the Docker image
43+
/assets/node_modules/
44+
/priv/static/assets/
45+
/priv/static/cache_manifest.json

.formatter.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
line_length: 300,
3+
import_deps: [:phoenix],
4+
inputs: ["*.{ex,exs}", "{config,lib,test}/**/*.{ex,exs}"]
5+
]

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where 3rd-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
17+
erl_crash.dump
18+
19+
# Also ignore archive artifacts (built via "mix archive.build").
20+
*.ez
21+
22+
# Temporary files, for example, from tests.
23+
/tmp/
24+
25+
# Ignore package tarball (built via "mix hex.build").
26+
kdrive_bridge-*.tar
27+

.tool-versions

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
nodejs 18.7.0
2+
elixir 1.15.7-otp-26
3+
erlang 26.1.2

Dockerfile

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian
2+
# instead of Alpine to avoid DNS resolution issues in production.
3+
#
4+
# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu
5+
# https://hub.docker.com/_/ubuntu?tab=tags
6+
#
7+
# This file is based on these images:
8+
#
9+
# - https://hub.docker.com/r/hexpm/elixir/tags - for the build image
10+
# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20231009-slim - for the release image
11+
# - https://pkgs.org/ - resource for finding needed packages
12+
# - Ex: hexpm/elixir:1.15.7-erlang-26.1.2-debian-bullseye-20231009-slim
13+
#
14+
ARG ELIXIR_VERSION=1.15.7
15+
ARG OTP_VERSION=26.1.2
16+
ARG DEBIAN_VERSION=bullseye-20231009-slim
17+
18+
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
19+
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
20+
21+
FROM ${BUILDER_IMAGE} as builder
22+
23+
# install build dependencies
24+
RUN apt-get update -y && apt-get install -y build-essential git \
25+
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
26+
27+
# prepare build dir
28+
WORKDIR /app
29+
30+
# install hex + rebar
31+
RUN mix local.hex --force && \
32+
mix local.rebar --force
33+
34+
# set build ENV
35+
ENV MIX_ENV="prod"
36+
37+
# install mix dependencies
38+
COPY mix.exs mix.lock ./
39+
RUN mix deps.get --only $MIX_ENV
40+
RUN mkdir config
41+
42+
# copy compile-time config files before we compile dependencies
43+
# to ensure any relevant config change will trigger the dependencies
44+
# to be re-compiled.
45+
COPY config/config.exs config/${MIX_ENV}.exs config/
46+
RUN mix deps.compile
47+
48+
COPY priv priv
49+
50+
COPY lib lib
51+
52+
# Compile the release
53+
RUN mix compile
54+
55+
# Changes to config/runtime.exs don't require recompiling the code
56+
COPY config/runtime.exs config/
57+
58+
COPY rel rel
59+
RUN mix release
60+
61+
# start a new build stage so that the final image will only contain
62+
# the compiled release and other runtime necessities
63+
FROM ${RUNNER_IMAGE}
64+
65+
RUN apt-get update -y && \
66+
apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates \
67+
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
68+
69+
# Set the locale
70+
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
71+
72+
ENV LANG en_US.UTF-8
73+
ENV LANGUAGE en_US:en
74+
ENV LC_ALL en_US.UTF-8
75+
76+
WORKDIR "/app"
77+
RUN chown nobody /app
78+
79+
# set runner ENV
80+
ENV MIX_ENV="prod"
81+
82+
# Only copy the final release from the build stage
83+
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/kdrive_bridge ./
84+
85+
USER nobody
86+
87+
# If using an environment that doesn't automatically reap zombie processes, it is
88+
# advised to add an init process such as tini via `apt-get install`
89+
# above and adding an entrypoint. See https://github.com/krallin/tini for details
90+
# ENTRYPOINT ["/tini", "--"]
91+
92+
CMD ["/app/bin/server"]

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# KdriveBridge
2+
3+
The goal of this project is to provide access to the content of your files saved in kDrive. This application doesn't offer any security layers or authentication. I suggest using a [proxy](https://docs.linuxserver.io/general/swag/) for TLS termination and authentication in front of the project.

config/config.exs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This file is responsible for configuring your application
2+
# and its dependencies with the aid of the Config module.
3+
#
4+
# This configuration file is loaded before any dependency and
5+
# is restricted to this project.
6+
7+
# General application configuration
8+
import Config
9+
10+
config :kdrive_bridge,
11+
generators: [timestamp_type: :utc_datetime],
12+
kdrive_id: "",
13+
kdrive_api_token: ""
14+
15+
# Configures the endpoint
16+
config :kdrive_bridge, KdriveBridgeWeb.Endpoint,
17+
url: [host: "localhost"],
18+
adapter: Phoenix.Endpoint.Cowboy2Adapter,
19+
render_errors: [
20+
formats: [json: KdriveBridgeWeb.ErrorJSON],
21+
layout: false
22+
],
23+
pubsub_server: KdriveBridge.PubSub,
24+
live_view: [signing_salt: "7nfCI6sX"]
25+
26+
# Configures Elixir's Logger
27+
config :logger, :console,
28+
format: "$time $metadata[$level] $message\n",
29+
metadata: [:request_id]
30+
31+
# Use Jason for JSON parsing in Phoenix
32+
config :phoenix, :json_library, Jason
33+
34+
# Tesla
35+
config :tesla, adapter: Tesla.Adapter.Hackney
36+
37+
# Import environment specific config. This must remain at the bottom
38+
# of this file so it overrides the configuration defined above.
39+
import_config "#{config_env()}.exs"

config/dev.exs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import Config
2+
3+
# For development, we disable any cache and enable
4+
# debugging and code reloading.
5+
#
6+
# The watchers configuration can be used to run external
7+
# watchers to your application. For example, we can use it
8+
# to bundle .js and .css sources.
9+
config :kdrive_bridge, KdriveBridgeWeb.Endpoint,
10+
# Binding to loopback ipv4 address prevents access from other machines.
11+
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
12+
http: [ip: {0, 0, 0, 0}, port: 4000],
13+
check_origin: false,
14+
code_reloader: true,
15+
debug_errors: true,
16+
secret_key_base: "eRY53a7yJtFRrDYN/W40CBckt60wZusAt85iaDXcFrKxz0LKSm5ijj6H8qs512JG",
17+
watchers: []
18+
19+
# ## SSL Support
20+
#
21+
# In order to use HTTPS in development, a self-signed
22+
# certificate can be generated by running the following
23+
# Mix task:
24+
#
25+
# mix phx.gen.cert
26+
#
27+
# Run `mix help phx.gen.cert` for more information.
28+
#
29+
# The `http:` config above can be replaced with:
30+
#
31+
# https: [
32+
# port: 4001,
33+
# cipher_suite: :strong,
34+
# keyfile: "priv/cert/selfsigned_key.pem",
35+
# certfile: "priv/cert/selfsigned.pem"
36+
# ],
37+
#
38+
# If desired, both `http:` and `https:` keys can be
39+
# configured to run both http and https servers on
40+
# different ports.
41+
42+
# Enable dev routes for dashboard and mailbox
43+
config :kdrive_bridge, dev_routes: true
44+
45+
# Do not include metadata nor timestamps in development logs
46+
config :logger, :console, format: "[$level] $message\n"
47+
48+
# Set a higher stacktrace during development. Avoid configuring such
49+
# in production as building large stacktraces may be expensive.
50+
config :phoenix, :stacktrace_depth, 20
51+
52+
# Initialize plugs at runtime for faster development compilation
53+
config :phoenix, :plug_init_mode, :runtime

config/prod.exs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Config
2+
3+
# Do not print debug messages in production
4+
config :logger, level: :info
5+
6+
# Runtime production configuration, including reading
7+
# of environment variables, is done on config/runtime.exs.

config/runtime.exs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import Config
2+
3+
# config/runtime.exs is executed for all environments, including
4+
# during releases. It is executed after compilation and before the
5+
# system starts, so it is typically used to load production configuration
6+
# and secrets from environment variables or elsewhere. Do not define
7+
# any compile-time configuration in here, as it won't be applied.
8+
# The block below contains prod specific runtime configuration.
9+
10+
# ## Using releases
11+
#
12+
# If you use `mix release`, you need to explicitly enable the server
13+
# by passing the PHX_SERVER=true when you start it:
14+
#
15+
# PHX_SERVER=true bin/kdrive_bridge start
16+
#
17+
# Alternatively, you can use `mix phx.gen.release` to generate a `bin/server`
18+
# script that automatically sets the env var above.
19+
if System.get_env("PHX_SERVER") do
20+
config :kdrive_bridge, KdriveBridgeWeb.Endpoint, server: true
21+
end
22+
23+
if config_env() == :prod do
24+
# The secret key base is used to sign/encrypt cookies and other secrets.
25+
# A default value is used in config/dev.exs and config/test.exs but you
26+
# want to use a different value for prod and you most likely don't want
27+
# to check this value into version control, so we use an environment
28+
# variable instead.
29+
secret_key_base =
30+
System.get_env("SECRET_KEY_BASE") ||
31+
raise """
32+
environment variable SECRET_KEY_BASE is missing.
33+
You can generate one by calling: mix phx.gen.secret
34+
"""
35+
36+
host = System.get_env("PHX_HOST") || "example.com"
37+
port = String.to_integer(System.get_env("PORT") || "4000")
38+
39+
config :kdrive_bridge, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")
40+
41+
config :kdrive_bridge, KdriveBridgeWeb.Endpoint,
42+
url: [host: host, port: 443, scheme: "https"],
43+
http: [
44+
# Enable IPv6 and bind on all interfaces.
45+
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
46+
# See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html
47+
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
48+
ip: {0, 0, 0, 0, 0, 0, 0, 0},
49+
port: port
50+
],
51+
secret_key_base: secret_key_base
52+
53+
# ## SSL Support
54+
#
55+
# To get SSL working, you will need to add the `https` key
56+
# to your endpoint configuration:
57+
#
58+
# config :kdrive_bridge, KdriveBridgeWeb.Endpoint,
59+
# https: [
60+
# ...,
61+
# port: 443,
62+
# cipher_suite: :strong,
63+
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
64+
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
65+
# ]
66+
#
67+
# The `cipher_suite` is set to `:strong` to support only the
68+
# latest and more secure SSL ciphers. This means old browsers
69+
# and clients may not be supported. You can set it to
70+
# `:compatible` for wider support.
71+
#
72+
# `:keyfile` and `:certfile` expect an absolute path to the key
73+
# and cert in disk or a relative path inside priv, for example
74+
# "priv/ssl/server.key". For all supported SSL configuration
75+
# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
76+
#
77+
# We also recommend setting `force_ssl` in your endpoint, ensuring
78+
# no data is ever sent via http, always redirecting to https:
79+
#
80+
# config :kdrive_bridge, KdriveBridgeWeb.Endpoint,
81+
# force_ssl: [hsts: true]
82+
#
83+
# Check `Plug.SSL` for all available options in `force_ssl`.
84+
end

0 commit comments

Comments
 (0)