From 1e82bbe318b451413738e51ba9fc7af85446c6fa Mon Sep 17 00:00:00 2001 From: d-roak Date: Tue, 11 Jul 2023 14:50:20 +0100 Subject: [PATCH 1/8] initial Dockerfile; volume change on docker-compose --- Dockerfile | 18 ++++++++++++++++++ docker-compose.yml | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..3cc4eefc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM hexpm/elixir:1.14.5-erlang-24.3.4.13-debian-bullseye-20230612-slim as builder + +# should be overwritten inline/docker-compose +ENV RPC_API_HOST="http://localhost:4000" + +RUN apt-get update -y && apt-get install -y build-essential git curl \ + && apt-get clean && rm -f /var/lib/apt/lists/*_* + +COPY . . + +RUN mix local.hex --force +RUN mix deps.get + +RUN mix ecto.create +RUN mix ecto.migrate + +CMD make run + diff --git a/docker-compose.yml b/docker-compose.yml index 8a8490bc..3a0cba90 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,7 @@ services: - POSTGRES_DB=starknet_explorer_dev - PGDATA=/var/lib/postgresql/data/pgdata volumes: - - ./.volumes/postgres/data:/var/lib/postgresql/data/ + - pg_data:/var/lib/postgresql/data/ networks: default: aliases: @@ -39,5 +39,6 @@ networks: driver: bridge volumes: + pg_data: pgadmin_data: From acdbbbbc0d9af62077fd95766217fba99a1b3601 Mon Sep 17 00:00:00 2001 From: d-roak Date: Tue, 11 Jul 2023 15:40:49 +0100 Subject: [PATCH 2/8] add database url --- Dockerfile | 8 +++----- config/dev.exs | 18 +++++++++++++----- docker-compose.yml | 20 +++++++++++++++++--- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3cc4eefc..1fb9549c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ -FROM hexpm/elixir:1.14.5-erlang-24.3.4.13-debian-bullseye-20230612-slim as builder +FROM hexpm/elixir:1.15.2-erlang-26.0.2-debian-bullseye-20230612-slim # should be overwritten inline/docker-compose ENV RPC_API_HOST="http://localhost:4000" +ENV DATABASE_URL="ecto://postgres:postgres@localhost:5432/starknet_explorer_dev" RUN apt-get update -y && apt-get install -y build-essential git curl \ && apt-get clean && rm -f /var/lib/apt/lists/*_* @@ -11,8 +12,5 @@ COPY . . RUN mix local.hex --force RUN mix deps.get -RUN mix ecto.create -RUN mix ecto.migrate - -CMD make run +CMD mix phx.server diff --git a/config/dev.exs b/config/dev.exs index 270de05c..1e61d1c6 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -1,11 +1,19 @@ import Config +database_url = + System.get_env("DATABASE_URL") || + raise """ + environment variable DATABASE_URL is missing. + For example: ecto://USER:PASS@HOST/DATABASE + """ + # Configure your database config :starknet_explorer, StarknetExplorer.Repo, - username: "postgres", - password: "postgres", - hostname: "localhost", - database: "starknet_explorer_dev", + #username: "postgres", + #password: "postgres", + #hostname: "localhost", + #database: "starknet_explorer_dev", + database_url: database_url, stacktrace: true, show_sensitive_data_on_connection_error: true, pool_size: 10 @@ -19,7 +27,7 @@ config :starknet_explorer, StarknetExplorer.Repo, config :starknet_explorer, StarknetExplorerWeb.Endpoint, # Binding to loopback ipv4 address prevents access from other machines. # Change to `ip: {0, 0, 0, 0}` to allow access from other machines. - http: [ip: {127, 0, 0, 1}, port: 4000], + http: [ip: {0, 0, 0, 0}, port: 4000], check_origin: false, code_reloader: true, debug_errors: true, diff --git a/docker-compose.yml b/docker-compose.yml index 3a0cba90..b163d141 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,25 @@ version: '3.8' services: + starknet-explorer: + build: . + ports: + - "4000:4000" + environment: + - RPC_API_HOST=http://host.docker.internal:9944 + - DATABASE_URL=ecto://postgres:postgres@host.docker.internal:5432/starknet_explorer_dev + depends_on: + - postgres + networks: + default: + aliases: + - explorer + postgres: container_name: starknet_explorer_dev_db image: postgres:15.3 ports: - - 127.0.0.1:5432:5432 + - 5432:5432 environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres @@ -25,9 +39,9 @@ services: - PGADMIN_DEFAULT_EMAIL=lambda@email.com - PGADMIN_DEFAULT_PASSWORD=pgadmin ports: - - 127.0.0.1:5050:80 + - 5050:80 volumes: - - 'pgadmin_data:/var/lib/pgadmin' + - pgadmin_data:/var/lib/pgadmin networks: default: aliases: From 5421b914a084be2e4ada55049ab9b4a1a31547e5 Mon Sep 17 00:00:00 2001 From: d-roak Date: Tue, 11 Jul 2023 16:04:25 +0100 Subject: [PATCH 3/8] bugfixes and adjustments --- Dockerfile | 13 ++++++++++--- config/dev.exs | 2 +- docker-compose.yml | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1fb9549c..4c137978 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,13 +4,20 @@ FROM hexpm/elixir:1.15.2-erlang-26.0.2-debian-bullseye-20230612-slim ENV RPC_API_HOST="http://localhost:4000" ENV DATABASE_URL="ecto://postgres:postgres@localhost:5432/starknet_explorer_dev" -RUN apt-get update -y && apt-get install -y build-essential git curl \ - && apt-get clean && rm -f /var/lib/apt/lists/*_* +RUN mix local.hex --force \ + && mix archive.install --force hex phx_new \ + && apt-get update \ + && curl -sL https://deb.nodesource.com/setup_lts.x | bash \ + && apt-get install -y apt-utils \ + && apt-get install -y nodejs \ + && apt-get install -y build-essential \ + && apt-get install -y inotify-tools \ + && mix local.rebar --force COPY . . RUN mix local.hex --force RUN mix deps.get -CMD mix phx.server +CMD mix ecto.create && mix ecto.migrate && mix phx.server diff --git a/config/dev.exs b/config/dev.exs index 1e61d1c6..4092e511 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -13,7 +13,7 @@ config :starknet_explorer, StarknetExplorer.Repo, #password: "postgres", #hostname: "localhost", #database: "starknet_explorer_dev", - database_url: database_url, + url: database_url, stacktrace: true, show_sensitive_data_on_connection_error: true, pool_size: 10 diff --git a/docker-compose.yml b/docker-compose.yml index b163d141..da40fc92 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: - "4000:4000" environment: - RPC_API_HOST=http://host.docker.internal:9944 - - DATABASE_URL=ecto://postgres:postgres@host.docker.internal:5432/starknet_explorer_dev + - DATABASE_URL=ecto://postgres:postgres@postgres:5432/starknet_explorer_dev depends_on: - postgres networks: From 42a8d9bde574a6fb0c2fad037306d8018ac68ad3 Mon Sep 17 00:00:00 2001 From: d-roak Date: Tue, 11 Jul 2023 16:23:18 +0100 Subject: [PATCH 4/8] adjust Makefile --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c0018d5b..5be15e7c 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,8 @@ run: setup: deps-get db db: - docker-compose up -d + export DATABASE_URL="ecto://postgres:postgres@localhost:5432/starknet_explorer_dev" + docker-compose up -d postgres pgadmin mix ecto.create mix ecto.migrate From 30b15f84f26bbe46da332b1b2880a078a982ba36 Mon Sep 17 00:00:00 2001 From: d-roak Date: Tue, 11 Jul 2023 16:27:14 +0100 Subject: [PATCH 5/8] run mix formatter --- config/dev.exs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/dev.exs b/config/dev.exs index 4092e511..aa3c9f6c 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -9,10 +9,10 @@ database_url = # Configure your database config :starknet_explorer, StarknetExplorer.Repo, - #username: "postgres", - #password: "postgres", - #hostname: "localhost", - #database: "starknet_explorer_dev", + # username: "postgres", + # password: "postgres", + # hostname: "localhost", + # database: "starknet_explorer_dev", url: database_url, stacktrace: true, show_sensitive_data_on_connection_error: true, From 2cd7a367d8429ed419e42ad057f3198709c3e0ba Mon Sep 17 00:00:00 2001 From: d-roak Date: Mon, 17 Jul 2023 04:01:32 +0100 Subject: [PATCH 6/8] revert docker-compose changes --- Makefile | 3 +-- docker-compose.yml | 17 +---------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 4fe11407..8f219c73 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,7 @@ run: setup: deps-get db db: - export DATABASE_URL="ecto://postgres:postgres@localhost:5432/starknet_explorer_dev" - docker-compose up -d postgres pgadmin + docker-compose up -d mix ecto.create mix ecto.migrate diff --git a/docker-compose.yml b/docker-compose.yml index da40fc92..4a85102f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,20 +1,6 @@ version: '3.8' services: - starknet-explorer: - build: . - ports: - - "4000:4000" - environment: - - RPC_API_HOST=http://host.docker.internal:9944 - - DATABASE_URL=ecto://postgres:postgres@postgres:5432/starknet_explorer_dev - depends_on: - - postgres - networks: - default: - aliases: - - explorer - postgres: container_name: starknet_explorer_dev_db image: postgres:15.3 @@ -26,7 +12,7 @@ services: - POSTGRES_DB=starknet_explorer_dev - PGDATA=/var/lib/postgresql/data/pgdata volumes: - - pg_data:/var/lib/postgresql/data/ + - ./.volumes/postgres/data:/var/lib/postgresql/data/ networks: default: aliases: @@ -53,6 +39,5 @@ networks: driver: bridge volumes: - pg_data: pgadmin_data: From 92f3b063e01c26a04151d0228d917eb1b606f063 Mon Sep 17 00:00:00 2001 From: d-roak Date: Mon, 17 Jul 2023 04:50:37 +0100 Subject: [PATCH 7/8] change Dockerfile to prod build --- Dockerfile | 35 ++++++++++++++++++++--------------- config/dev.exs | 2 +- config/runtime.exs | 5 +++-- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4c137978..7775b46e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,28 @@ -FROM hexpm/elixir:1.15.2-erlang-26.0.2-debian-bullseye-20230612-slim +FROM elixir:1.14.5-otp-25 as builder -# should be overwritten inline/docker-compose -ENV RPC_API_HOST="http://localhost:4000" -ENV DATABASE_URL="ecto://postgres:postgres@localhost:5432/starknet_explorer_dev" +ENV MIX_ENV=prod + +WORKDIR /explorer +COPY . . RUN mix local.hex --force \ + && mix local.rebar --force \ && mix archive.install --force hex phx_new \ - && apt-get update \ - && curl -sL https://deb.nodesource.com/setup_lts.x | bash \ - && apt-get install -y apt-utils \ - && apt-get install -y nodejs \ - && apt-get install -y build-essential \ - && apt-get install -y inotify-tools \ - && mix local.rebar --force + && mix deps.get --only $MIX_ENV \ + && mix deps.compile \ + && mix assets.deploy \ + && mix phx.digest \ + && mix compile \ + && mix release \ + && mix phx.gen.release -COPY . . +FROM elixir:1.14.5-otp-25 +ENV MIX_ENV=prod + +WORKDIR /explorer -RUN mix local.hex --force -RUN mix deps.get +COPY --from=builder /explorer/_build/$MIX_ENV/rel/starknet_explorer . -CMD mix ecto.create && mix ecto.migrate && mix phx.server +EXPOSE 4000 +CMD ["/explorer/bin/starknet_explorer", "start"] diff --git a/config/dev.exs b/config/dev.exs index aa3c9f6c..77cce878 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -27,7 +27,7 @@ config :starknet_explorer, StarknetExplorer.Repo, config :starknet_explorer, StarknetExplorerWeb.Endpoint, # Binding to loopback ipv4 address prevents access from other machines. # Change to `ip: {0, 0, 0, 0}` to allow access from other machines. - http: [ip: {0, 0, 0, 0}, port: 4000], + http: [ip: {127, 0, 0, 1}, port: 4000], check_origin: false, code_reloader: true, debug_errors: true, diff --git a/config/runtime.exs b/config/runtime.exs index 0e9b8ca6..0dd1c833 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -56,11 +56,12 @@ if config_env() == :prod do You can generate one by calling: mix phx.gen.secret """ - host = System.get_env("PHX_HOST") || "example.com" + # host = System.get_env("PHX_HOST") || "example.com" port = String.to_integer(System.get_env("PORT") || "4000") config :starknet_explorer, StarknetExplorerWeb.Endpoint, - url: [host: host, port: 443, scheme: "https"], + server: true, + # url: [host: host, port: 443, scheme: "https"], http: [ # Enable IPv6 and bind on all interfaces. # Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access. From 021a97702f2953fe7618f6d2f57b69178634be48 Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Mon, 17 Jul 2023 12:07:26 +0200 Subject: [PATCH 8/8] Revert changes to dev.exs --- config/dev.exs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/config/dev.exs b/config/dev.exs index 77cce878..270de05c 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -1,19 +1,11 @@ import Config -database_url = - System.get_env("DATABASE_URL") || - raise """ - environment variable DATABASE_URL is missing. - For example: ecto://USER:PASS@HOST/DATABASE - """ - # Configure your database config :starknet_explorer, StarknetExplorer.Repo, - # username: "postgres", - # password: "postgres", - # hostname: "localhost", - # database: "starknet_explorer_dev", - url: database_url, + username: "postgres", + password: "postgres", + hostname: "localhost", + database: "starknet_explorer_dev", stacktrace: true, show_sensitive_data_on_connection_error: true, pool_size: 10