From f4799e0674936245db11a48b0d57a053dc1307b4 Mon Sep 17 00:00:00 2001 From: Qwerty5Uiop Date: Thu, 30 Jun 2022 18:16:51 +0400 Subject: [PATCH] Clean up release --- apps/explorer/lib/release_tasks.ex | 23 +++++++++++++++++++++++ docker/Dockerfile | 18 +++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/apps/explorer/lib/release_tasks.ex b/apps/explorer/lib/release_tasks.ex index 146e77d6e2..14627d1b7b 100644 --- a/apps/explorer/lib/release_tasks.ex +++ b/apps/explorer/lib/release_tasks.ex @@ -16,6 +16,19 @@ defmodule Explorer.ReleaseTasks do @repos Application.compile_env(:blockscout, :ecto_repos, [Explorer.Repo]) + def create_and_migrate do + start_services() + + create() + run_migrations() + + stop_services() + end + + def create do + Enum.each(@repos, &create_db_for/1) + end + def migrate(_argv) do start_services() @@ -51,6 +64,16 @@ defmodule Explorer.ReleaseTasks do :init.stop() end + defp create_db_for(repo) do + IO.puts("Create #{inspect(repo)} database if it doesn't exist") + + case repo.__adapter__.storage_up(repo.config) do + :ok -> :ok + {:error, :already_up} -> :ok + {:error, term} -> {:error, term} + end + end + defp run_migrations do Enum.each(@repos, &run_migrations_for/1) end diff --git a/docker/Dockerfile b/docker/Dockerfile index 2f3c5dc924..d8547d5f38 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,6 @@ -FROM bitwalker/alpine-elixir-phoenix:1.13 +FROM bitwalker/alpine-elixir-phoenix:1.13 AS builder + +WORKDIR /opt/app RUN apk --no-cache --update add alpine-sdk gmp-dev automake libtool inotify-tools autoconf python3 file qemu-x86_64 @@ -64,5 +66,15 @@ RUN cd apps/explorer/ && \ RUN mix phx.digest -RUN mix release blockscout \ - && cp -R _build/${MIX_ENV}/rel/blockscout/* ./ +RUN mkdir -p /opt/release \ + && mix release blockscout \ + && mv _build/${MIX_ENV}/rel/blockscout /opt/release + +############################################################## +FROM bitwalker/alpine-elixir-phoenix:1.13 + +WORKDIR /opt/app + +COPY --from=builder /opt/release/blockscout . + +