chore: prepare for prod

Signed-off-by: SphericalKat <amolele@gmail.com>
This commit is contained in:
Amogh Lele 2021-08-14 01:19:00 +05:30
parent d369c75fa8
commit 5d05a87263
No known key found for this signature in database
GPG Key ID: ED5C54FBBB920E51
10 changed files with 10491 additions and 6662 deletions

View File

@ -45,6 +45,10 @@ USER nobody:nobody
COPY --from=build --chown=nobody:nobody /app/_build/prod/rel/ketbin ./ COPY --from=build --chown=nobody:nobody /app/_build/prod/rel/ketbin ./
COPY --chown=nobody:nobody startup.sh startup.sh
RUN chmod +x /app/startup.sh
ENV HOME=/app ENV HOME=/app
CMD ["bin/ketbin", "start"] CMD ["/app/startup.sh"]

10381
assets/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,7 @@ use Mix.Config
# which you should run after static files are built and # which you should run after static files are built and
# before starting your production server. # before starting your production server.
config :ketbin, KetbinWeb.Endpoint, config :ketbin, KetbinWeb.Endpoint,
url: [host: "example.com", port: 80], url: [host: "dev.katb.in", port: 80],
cache_static_manifest: "priv/static/cache_manifest.json" cache_static_manifest: "priv/static/cache_manifest.json"
# Do not print debug messages in production # Do not print debug messages in production

View File

@ -12,9 +12,11 @@ database_url =
""" """
config :ketbin, Ketbin.Repo, config :ketbin, Ketbin.Repo,
# ssl: true, ssl: true,
verify: :verify_peer,
url: database_url, url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10") pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
cacertfile: "priv/cert.pem"
secret_key_base = secret_key_base =
System.get_env("SECRET_KEY_BASE") || System.get_env("SECRET_KEY_BASE") ||
@ -28,14 +30,14 @@ config :ketbin, KetbinWeb.Endpoint,
port: String.to_integer(System.get_env("PORT") || "4000"), port: String.to_integer(System.get_env("PORT") || "4000"),
transport_options: [socket_opts: [:inet6]] transport_options: [socket_opts: [:inet6]]
], ],
secret_key_base: secret_key_base secret_key_base: secret_key_base,
server: true
# ## Using releases (Elixir v1.9+) # ## Using releases (Elixir v1.9+)
# #
# If you are doing OTP releases, you need to instruct Phoenix # If you are doing OTP releases, you need to instruct Phoenix
# to start each relevant endpoint: # to start each relevant endpoint:
# #
config :ketbin, KetbinWeb.Endpoint, server: true
# #
# Then you can assemble a release by calling `mix release`. # Then you can assemble a release by calling `mix release`.
# See `mix help release` for more information. # See `mix help release` for more information.

View File

@ -29,6 +29,8 @@ defmodule KetbinWeb.PageController do
# generate phonetic key # generate phonetic key
id = Utils.generate_key() id = Utils.generate_key()
IO.puts(conn.assigns[:current_user])
# check if content is a url # check if content is a url
is_url = is_url =
Map.get(paste_params, "content") Map.get(paste_params, "content")

32
lib/release.ex Normal file
View File

@ -0,0 +1,32 @@
defmodule Ketbin.Release do
@moduledoc """
This module is used by the entrypoint to migrate the database
"""
@app :ketbin
require Logger
def migrate do
Application.ensure_all_started(@app)
load_app()
for repo <- repos() do
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
end
end
def rollback(repo, version) do
load_app()
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
end
defp repos do
Application.fetch_env!(@app, :ecto_repos)
end
defp load_app do
Application.load(@app)
end
end

View File

@ -20,7 +20,7 @@ defmodule Ketbin.MixProject do
def application do def application do
[ [
mod: {Ketbin.Application, []}, mod: {Ketbin.Application, []},
extra_applications: [:logger, :runtime_tools] extra_applications: [:logger, :runtime_tools, :ssl],
] ]
end end

25
priv/cert.pem Normal file
View File

@ -0,0 +1,25 @@
-----BEGIN CERTIFICATE-----
MIIEQTCCAqmgAwIBAgIUKUbJkc6kHUPlOf0l1xQYzrLjECowDQYJKoZIhvcNAQEM
BQAwOjE4MDYGA1UEAwwvOTM5MDZiYWYtYzcxYi00MTczLTg2YTItZjA2MzFmMjZj
M2VhIFByb2plY3QgQ0EwHhcNMjEwNjI0MDc1NTUyWhcNMzEwNjIyMDc1NTUyWjA6
MTgwNgYDVQQDDC85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9QN
aO05pgq4LNlG9gecX45TzIPV2BsB6TYmvq/mbr5sGRQLgVlqiYC/KEH7cdnjN418
gqBcwUlct0FiKHM1YWd0uXEEJh1yu14wnZmJDnr3Dkj2k7uyrUoMt9bDv5nnyocZ
ub+CsnVPqBBHs4JOAw5atRxpGeEiSVZCJt6xpVHHl3vlW3pwFQ==
-----END CERTIFICATE-----

38
startup.sh Executable file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env sh
log() {
printf "[%s] %s\n" "$1" "$2"
}
info() {
log "INFO" "$1"
}
error() {
log "ERROR" "$1"
}
migrate() {
info 'Performing migrations with "Ketbin.Release.migrate()"'
bin/ketbin eval "Ketbin.Release.migrate()"
LAST_EXIT=$?
if [ $LAST_EXIT = 0 ]; then
info 'Done performing migrations'
else
error "Unable to perform migrations, exit code $LAST_EXIT"
exit $LAST_EXIT
fi
}
start() {
info 'Starting the application'
bin/ketbin start
}
SLEEP_TIME=10
info "Sleeping for $SLEEP_TIME seconds for all services to be up"
sleep $SLEEP_TIME
migrate
start