Skip to content

Commit 0bb234d

Browse files
committed
fixing docker release
1 parent c51e488 commit 0bb234d

File tree

7 files changed

+250
-23
lines changed

7 files changed

+250
-23
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,5 @@ result
5555
.envrc
5656
.elixir_ls
5757
.elixir-tools
58+
cockroach
59+
caddy

config/config.exs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,6 @@ Code.require_file("config/helpers.exs")
55
Code.ensure_loaded!(Uro.Config.Helpers)
66
alias Uro.Config.Helpers
77

8-
compile_phase? = System.get_env("COMPILE_PHASE") != "false"
9-
10-
get_env = fn key, example ->
11-
case compile_phase? do
12-
true ->
13-
example
14-
15-
false ->
16-
System.get_env(key) ||
17-
raise """
18-
Environment variable "#{key}" is required but not set.
19-
"""
20-
end
21-
end
22-
23-
get_optional_env = fn key ->
24-
System.get_env(key)
25-
end
26-
278
config :uro,
289
compile_phase?: System.get_env("COMPILE_PHASE") != "false"
2910

config/dev.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ config :uro, Uro.Repo,
3535
database: "uro-dev",
3636
stacktrace: true,
3737
show_sensitive_data_on_connection_error: true,
38-
pool_size: 10
38+
pool_size: 10,
39+
migration_lock: false
3940

4041
redis_url = Helpers.get_env("REDIS_URL", nil)
4142
config :uro, Redix, url: if(redis_url, do: redis_url, else: "redis://localhost:6379")

config/runtime.ex

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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/oru 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 :oru, Uro.Endpoint, server: true
21+
end
22+
23+
if config_env() == :prod do
24+
database_url =
25+
System.get_env("DATABASE_URL") ||
26+
raise """
27+
environment variable DATABASE_URL is missing.
28+
For example: ecto://USER:PASS@HOST/DATABASE
29+
"""
30+
31+
maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: []
32+
33+
config :uro, Uro.Repo,
34+
# ssl: true,
35+
url: database_url,
36+
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
37+
socket_options: maybe_ipv6
38+
39+
# The secret key base is used to sign/encrypt cookies and other secrets.
40+
# A default value is used in config/dev.exs and config/test.exs but you
41+
# want to use a different value for prod and you most likely don't want
42+
# to check this value into version control, so we use an environment
43+
# variable instead.
44+
secret_key_base =
45+
System.get_env("SECRET_KEY_BASE") ||
46+
raise """
47+
environment variable SECRET_KEY_BASE is missing.
48+
You can generate one by calling: mix phx.gen.secret
49+
"""
50+
51+
host = System.get_env("PHX_HOST") || "example.com"
52+
port = String.to_integer(System.get_env("PORT") || "4000")
53+
54+
config :oru, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")
55+
56+
config :oru, Uro.Endpoint,
57+
url: [host: host, port: 443, scheme: "https"],
58+
http: [
59+
# Enable IPv6 and bind on all interfaces.
60+
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
61+
# See the documentation on https://hexdocs.pm/bandit/Bandit.html#t:options/0
62+
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
63+
ip: {0, 0, 0, 0, 0, 0, 0, 0},
64+
port: port
65+
],
66+
secret_key_base: secret_key_base
67+
68+
config :uro,
69+
token_signing_secret:
70+
System.get_env("TOKEN_SIGNING_SECRET") ||
71+
raise("Missing environment variable `TOKEN_SIGNING_SECRET`!")
72+
73+
# ## SSL Support
74+
#
75+
# To get SSL working, you will need to add the `https` key
76+
# to your endpoint configuration:
77+
#
78+
# config :oru, OruWeb.Endpoint,
79+
# https: [
80+
# ...,
81+
# port: 443,
82+
# cipher_suite: :strong,
83+
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
84+
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
85+
# ]
86+
#
87+
# The `cipher_suite` is set to `:strong` to support only the
88+
# latest and more secure SSL ciphers. This means old browsers
89+
# and clients may not be supported. You can set it to
90+
# `:compatible` for wider support.
91+
#
92+
# `:keyfile` and `:certfile` expect an absolute path to the key
93+
# and cert in disk or a relative path inside priv, for example
94+
# "priv/ssl/server.key". For all supported SSL configuration
95+
# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
96+
#
97+
# We also recommend setting `force_ssl` in your config/prod.exs,
98+
# ensuring no data is ever sent via http, always redirecting to https:
99+
#
100+
# config :oru, OruWeb.Endpoint,
101+
# force_ssl: [hsts: true]
102+
#
103+
# Check `Plug.SSL` for all available options in `force_ssl`.
104+
105+
# ## Configuring the mailer
106+
#
107+
# In production you need to configure the mailer to use a different adapter.
108+
# Also, you may need to configure the Swoosh API client of your choice if you
109+
# are not using SMTP. Here is an example of the configuration:
110+
#
111+
# config :oru, Oru.Mailer,
112+
# adapter: Swoosh.Adapters.Mailgun,
113+
# api_key: System.get_env("MAILGUN_API_KEY"),
114+
# domain: System.get_env("MAILGUN_DOMAIN")
115+
#
116+
# For this example you need include a HTTP client required by Swoosh API client.
117+
# Swoosh supports Hackney and Finch out of the box:
118+
#
119+
# config :swoosh, :api_client, Swoosh.ApiClient.Hackney
120+
#
121+
# See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details.
122+
end

config/runtime.exs

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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/oru 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 :oru, Uro.Endpoint, server: true
21+
end
22+
23+
if config_env() == :prod do
24+
database_url =
25+
System.get_env("DATABASE_URL") ||
26+
raise """
27+
environment variable DATABASE_URL is missing.
28+
For example: ecto://USER:PASS@HOST/DATABASE
29+
"""
30+
31+
maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: []
32+
33+
config :uro, Uro.Repo,
34+
# ssl: true,
35+
url: database_url,
36+
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
37+
socket_options: maybe_ipv6
38+
39+
# The secret key base is used to sign/encrypt cookies and other secrets.
40+
# A default value is used in config/dev.exs and config/test.exs but you
41+
# want to use a different value for prod and you most likely don't want
42+
# to check this value into version control, so we use an environment
43+
# variable instead.
44+
secret_key_base =
45+
System.get_env("SECRET_KEY_BASE") ||
46+
raise """
47+
environment variable SECRET_KEY_BASE is missing.
48+
You can generate one by calling: mix phx.gen.secret
49+
"""
50+
51+
host = System.get_env("PHX_HOST") || "example.com"
52+
port = String.to_integer(System.get_env("PORT") || "4000")
53+
54+
config :oru, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")
55+
56+
config :oru, Uro.Endpoint,
57+
url: [host: host, port: 443, scheme: "https"],
58+
http: [
59+
# Enable IPv6 and bind on all interfaces.
60+
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
61+
# See the documentation on https://hexdocs.pm/bandit/Bandit.html#t:options/0
62+
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
63+
ip: {0, 0, 0, 0, 0, 0, 0, 0},
64+
port: port
65+
],
66+
secret_key_base: secret_key_base
67+
68+
config :uro,
69+
token_signing_secret:
70+
System.get_env("TOKEN_SIGNING_SECRET") ||
71+
raise("Missing environment variable `TOKEN_SIGNING_SECRET`!")
72+
73+
# ## SSL Support
74+
#
75+
# To get SSL working, you will need to add the `https` key
76+
# to your endpoint configuration:
77+
#
78+
# config :oru, OruWeb.Endpoint,
79+
# https: [
80+
# ...,
81+
# port: 443,
82+
# cipher_suite: :strong,
83+
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
84+
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
85+
# ]
86+
#
87+
# The `cipher_suite` is set to `:strong` to support only the
88+
# latest and more secure SSL ciphers. This means old browsers
89+
# and clients may not be supported. You can set it to
90+
# `:compatible` for wider support.
91+
#
92+
# `:keyfile` and `:certfile` expect an absolute path to the key
93+
# and cert in disk or a relative path inside priv, for example
94+
# "priv/ssl/server.key". For all supported SSL configuration
95+
# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
96+
#
97+
# We also recommend setting `force_ssl` in your config/prod.exs,
98+
# ensuring no data is ever sent via http, always redirecting to https:
99+
#
100+
# config :oru, OruWeb.Endpoint,
101+
# force_ssl: [hsts: true]
102+
#
103+
# Check `Plug.SSL` for all available options in `force_ssl`.
104+
105+
# ## Configuring the mailer
106+
#
107+
# In production you need to configure the mailer to use a different adapter.
108+
# Also, you may need to configure the Swoosh API client of your choice if you
109+
# are not using SMTP. Here is an example of the configuration:
110+
#
111+
# config :oru, Oru.Mailer,
112+
# adapter: Swoosh.Adapters.Mailgun,
113+
# api_key: System.get_env("MAILGUN_API_KEY"),
114+
# domain: System.get_env("MAILGUN_DOMAIN")
115+
#
116+
# For this example you need include a HTTP client required by Swoosh API client.
117+
# Swoosh supports Hackney and Finch out of the box:
118+
#
119+
# config :swoosh, :api_client, Swoosh.ApiClient.Hackney
120+
#
121+
# See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details.
122+
end

docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: "4.0"
21
services:
32
database:
43
image: cockroachdb/cockroach:v25.1.1

lib/uro/release.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ defmodule Uro.Release do
99
load_app()
1010

1111
for repo <- repos() do
12-
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
12+
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true, migration_lock: false))
1313
end
1414
end
1515

1616
def rollback(repo, version) do
1717
load_app()
18-
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
18+
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version, migration_lock: false))
1919
end
2020

2121
defp repos do

0 commit comments

Comments
 (0)