diff --git a/.dockerignore b/.dockerignore index 3900dd9f2..c38e4531c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,3 +7,4 @@ Makefile README* LICENSE test/ +node_modules diff --git a/Dockerfile b/Dockerfile index 84d3266be..53945e644 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,52 +2,64 @@ FROM elixir:1.10.2-alpine AS builder MAINTAINER docker@cloudfire.network -ARG MIX_ENV=prod -ARG PHOENIX_DIR=./apps/cloudfire +ENV MIX_ENV=prod +ARG PHOENIX_DIR=./apps/cf_phx # These are used only for building and won't matter later on # ENV DATABASE_URL=ecto://dummy:dummy@dummy/dummy # ENV SECRET_KEY_BASE=dummy # Install dependencies -RUN apk add npm +RUN apk add --update build-base npm git WORKDIR /app -RUN mix do local.hex --force, local.rebar --force +# Install hex + rebar +RUN mix local.hex --force +RUN mix local.rebar --force -COPY config/ . -COPY mix.exs ./ +COPY config config COPY mix.* ./ -COPY apps/cf_phx/mix.exs ./apps/cf_phx/ -COPY apps/system_engine/mix.exs ./apps/system_engine/ +COPY $PHOENIX_DIR/mix.* $PHOENIX_DIR/ +COPY apps/system_engine/mix.* ./apps/system_engine/ -RUN mix do deps.get --only $MIX_ENV, deps.compile - -COPY . . +RUN mix deps.get +RUN mix deps.compile +# Build assets +COPY $PHOENIX_DIR/assets $PHOENIX_DIR/assets +COPY priv priv +COPY $PHOENIX_DIR/priv $PHOENIX_DIR/priv RUN npm install --prefix $PHOENIX_DIR/assets RUN npm run deploy --prefix $PHOENIX_DIR/assets RUN mix phx.digest +# Build project +COPY $PHOENIX_DIR/lib $PHOENIX_DIR/lib +COPY apps/system_engine/lib ./apps/system_engine/ +RUN mix compile + +# Build release RUN mix release bundled # The built application is now contained in _build/ -# This is what the builder image is based on -FROM alpine:3.11 -RUN apk add --no-cache \ - ncurses-dev \ - openssl-dev + +# -------------------------------------------------- +FROM alpine:3.11 AS app +RUN apk add --update bash openssl EXPOSE 4000 ENV PORT=4000 \ - MIX_ENV=prod \ SHELL=/bin/bash +RUN mkdir /app WORKDIR /app -COPY --from=builder /app/_build/prod/rel/bundled . -CMD ["bin/bundled", "start"] +COPY --from=builder /app/_build/prod/rel/bundled . +RUN chown -R nobody: /app +USER nobody + +ENV HOME=/app diff --git a/apps/cf_phx/assets/package-lock.json b/apps/cf_phx/assets/package-lock.json index bc4128cfa..1da4d9967 100644 --- a/apps/cf_phx/assets/package-lock.json +++ b/apps/cf_phx/assets/package-lock.json @@ -5164,10 +5164,10 @@ } }, "phoenix": { - "version": "file:../deps/phoenix" + "version": "file:../../../deps/phoenix" }, "phoenix_html": { - "version": "file:../deps/phoenix_html" + "version": "file:../../../deps/phoenix_html" }, "pify": { "version": "4.0.1", diff --git a/apps/cf_phx/lib/cf_phx/release.ex b/apps/cf_phx/lib/cf_phx/release.ex new file mode 100644 index 000000000..2693874e0 --- /dev/null +++ b/apps/cf_phx/lib/cf_phx/release.ex @@ -0,0 +1,24 @@ +defmodule CfPhx.Release do + @app :cf_phx + + def migrate do + 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 diff --git a/mix.exs b/mix.exs index a3854a355..404a42d5d 100644 --- a/mix.exs +++ b/mix.exs @@ -24,6 +24,8 @@ defmodule CloudfireUmbrella.MixProject do # # Run "mix help deps" for examples and options. defp deps do - [] + [ + {:jason, "~> 1.0"} + ] end end