diff --git a/.dockerignore b/.dockerignore index c88329e6..2c5174f3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -8,7 +8,9 @@ /doc/ /test/ /tmp/ -.elixir_ls +.elixir_ls/ +.elixir-tools/ +.lexical/ # Mix artifacts /_build/ @@ -19,9 +21,9 @@ erl_crash.dump # Static artifacts - These should be fetched and built inside the Docker image -/apps/plataforma_digital/assets/node_modules/ -/apps/plataforma_digital/priv/static/assets/ -/apps/plataforma_digital/priv/static/cache_manifest.json +/assets/node_modules/ +/priv/static/assets/ +/priv/static/cache_manifest.json # Nix artifacts /.postgres/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..b72bc236 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,82 @@ +ARG ELIXIR_VERSION=1.15.4 +ARG OTP_VERSION=25.3.2.5 +ARG DEBIAN_VERSION=buster-20230612 + +ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}" +ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}" + +FROM ${BUILDER_IMAGE} as builder + +# prepare build dir +WORKDIR /app + +RUN apt-get update -y +RUN apt-get install -y build-essential curl +RUN curl -sL https://deb.nodesource.com/setup_18.x | bash - +RUN apt-get install -y nodejs +RUN apt-get clean && rm -f /var/lib/apt/lists/*_* + +# install hex + rebar +RUN mix local.hex --force && \ + mix local.rebar --force + +# set build ENV +ENV MIX_ENV="prod" + +# install mix dependencies +COPY mix.exs mix.lock ./ +RUN mix deps.get --only $MIX_ENV +RUN mkdir config + +# copy compile-time config files before we compile dependencies +# to ensure any relevant config change will trigger the dependencies +# to be re-compiled. +COPY config/config.exs config/${MIX_ENV}.exs config/ +RUN mix deps.compile + +COPY priv priv + +# compile assets +COPY assets assets +# RUN echo $(npm --version) && exit 1 +RUN npm ci --prefix assets +RUN mix assets.deploy + +COPY lib lib + +# Compile the release +RUN mix compile + +# Changes to config/runtime.exs don't require recompiling the code +COPY config/runtime.exs config/ + +COPY rel rel +RUN mix release + +# start a new build stage so that the final image will only contain +# the compiled release and other runtime necessities +FROM ${RUNNER_IMAGE} + +RUN apt-get update -y +RUN apt-get install -y libstdc++6 openssl libncurses5 locales +RUN apt-get clean && rm -f /var/lib/apt/lists/*_* + +# Set the locale +RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen + +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 + +WORKDIR "/app" +RUN chown nobody /app + +# set runner ENV +ENV MIX_ENV="prod" + +# Only copy the final release from the build stage +COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/pescarte ./ + +USER nobody + +CMD ["/app/bin/server"] diff --git a/Earthfile b/Earthfile index 6e8d4e94..28a7a151 100644 --- a/Earthfile +++ b/Earthfile @@ -2,8 +2,9 @@ VERSION 0.7 deps: ARG ELIXIR=1.15.4 - ARG OTP=26.0.2 - FROM hexpm/elixir:${ELIXIR}-erlang-${OTP}-debian-buster-20230612-slim + ARG OTP=25.3.2.5 + ARG DEBIAN_VERSION=buster-20230612 + FROM hexpm/elixir:${ELIXIR}-erlang-${OTP}-debian-${DEBIAN_VERSION} RUN apt update -y && apt install -y build-essential WORKDIR /src COPY mix.exs mix.lock ./ @@ -59,13 +60,7 @@ release: SAVE ARTIFACT /src/_build/prod/rel/pescarte /app/_build/prod/rel/pescarte AS LOCAL release docker-prod: - FROM debian:buster-20230612-slim - RUN apt update -y && apt install -y openssl libncurses5 - WORKDIR /app - RUN chown nobody /app - USER nobody - COPY +release/app/_build/prod/rel/pescarte . - CMD ["./bin/pescarte", "eval", "Pescarte.Release.migrate", "&&", "exec", "./bin/pescarte", "start"] + FROM DOCKERFILE . ARG GITHUB_REPO SAVE IMAGE --push ghcr.io/$GITHUB_REPO:prod diff --git a/assets/package-lock.json b/assets/package-lock.json index 28193568..7ec65a4f 100644 --- a/assets/package-lock.json +++ b/assets/package-lock.json @@ -1,7 +1,7 @@ { "name": "@pescarte/plataforma-pescarte", "version": "0.1.0", - "lockfileVersion": 2, + "lockfileVersion": 3, "requires": true, "packages": { "": { @@ -11,23 +11,23 @@ "dependencies": { "esbuild": "^0.17.10", "inputmask": "^5.0.7", - "phoenix": "file:../../../deps/phoenix", - "phoenix_html": "file:../../../deps/phoenix_html", - "phoenix_live_view": "file:../../../deps/phoenix_live_view", + "phoenix": "file:../deps/phoenix", + "phoenix_html": "file:../deps/phoenix_html", + "phoenix_live_view": "file:../deps/phoenix_live_view", "sass": "^1.63.4", "tailwindcss": "^3.2.7", "topbar": "^1.0.1" } }, - "../../../deps/phoenix": { - "version": "1.7.3", + "../deps/phoenix": { + "version": "1.7.10", "license": "MIT" }, - "../../../deps/phoenix_html": { - "version": "3.3.1" + "../deps/phoenix_html": { + "version": "3.3.3" }, - "../../../deps/phoenix_live_view": { - "version": "0.19.0", + "../deps/phoenix_live_view": { + "version": "0.20.1", "license": "MIT" }, "node_modules/@alloc/quick-lru": { @@ -532,15 +532,15 @@ "license": "MIT" }, "node_modules/phoenix": { - "resolved": "../../../deps/phoenix", + "resolved": "../deps/phoenix", "link": true }, "node_modules/phoenix_html": { - "resolved": "../../../deps/phoenix_html", + "resolved": "../deps/phoenix_html", "link": true }, "node_modules/phoenix_live_view": { - "resolved": "../../../deps/phoenix_live_view", + "resolved": "../deps/phoenix_live_view", "link": true }, "node_modules/picocolors": { @@ -914,494 +914,5 @@ "node": ">= 14" } } - }, - "dependencies": { - "@alloc/quick-lru": { - "version": "5.2.0" - }, - "@esbuild/darwin-arm64": { - "version": "0.17.19", - "optional": true - }, - "@jridgewell/gen-mapping": { - "version": "0.3.3", - "requires": { - "@jridgewell/set-array": "^1.0.1", - "@jridgewell/sourcemap-codec": "^1.4.10", - "@jridgewell/trace-mapping": "^0.3.9" - } - }, - "@jridgewell/resolve-uri": { - "version": "3.1.0" - }, - "@jridgewell/set-array": { - "version": "1.1.2" - }, - "@jridgewell/sourcemap-codec": { - "version": "1.4.15" - }, - "@jridgewell/trace-mapping": { - "version": "0.3.18", - "requires": { - "@jridgewell/resolve-uri": "3.1.0", - "@jridgewell/sourcemap-codec": "1.4.14" - }, - "dependencies": { - "@jridgewell/sourcemap-codec": { - "version": "1.4.14" - } - } - }, - "@nodelib/fs.scandir": { - "version": "2.1.5", - "requires": { - "@nodelib/fs.stat": "2.0.5", - "run-parallel": "^1.1.9" - } - }, - "@nodelib/fs.stat": { - "version": "2.0.5" - }, - "@nodelib/fs.walk": { - "version": "1.2.8", - "requires": { - "@nodelib/fs.scandir": "2.1.5", - "fastq": "^1.6.0" - } - }, - "any-promise": { - "version": "1.3.0" - }, - "anymatch": { - "version": "3.1.3", - "requires": { - "normalize-path": "^3.0.0", - "picomatch": "^2.0.4" - } - }, - "arg": { - "version": "5.0.2" - }, - "balanced-match": { - "version": "1.0.2" - }, - "binary-extensions": { - "version": "2.2.0" - }, - "brace-expansion": { - "version": "1.1.11", - "requires": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "braces": { - "version": "3.0.2", - "requires": { - "fill-range": "^7.0.1" - } - }, - "camelcase-css": { - "version": "2.0.1" - }, - "chokidar": { - "version": "3.5.3", - "requires": { - "anymatch": "~3.1.2", - "braces": "~3.0.2", - "fsevents": "~2.3.2", - "glob-parent": "~5.1.2", - "is-binary-path": "~2.1.0", - "is-glob": "~4.0.1", - "normalize-path": "~3.0.0", - "readdirp": "~3.6.0" - } - }, - "commander": { - "version": "4.1.1" - }, - "concat-map": { - "version": "0.0.1" - }, - "cssesc": { - "version": "3.0.0" - }, - "didyoumean": { - "version": "1.2.2" - }, - "dlv": { - "version": "1.1.3" - }, - "esbuild": { - "version": "0.17.19", - "requires": { - "@esbuild/android-arm": "0.17.19", - "@esbuild/android-arm64": "0.17.19", - "@esbuild/android-x64": "0.17.19", - "@esbuild/darwin-arm64": "0.17.19", - "@esbuild/darwin-x64": "0.17.19", - "@esbuild/freebsd-arm64": "0.17.19", - "@esbuild/freebsd-x64": "0.17.19", - "@esbuild/linux-arm": "0.17.19", - "@esbuild/linux-arm64": "0.17.19", - "@esbuild/linux-ia32": "0.17.19", - "@esbuild/linux-loong64": "0.17.19", - "@esbuild/linux-mips64el": "0.17.19", - "@esbuild/linux-ppc64": "0.17.19", - "@esbuild/linux-riscv64": "0.17.19", - "@esbuild/linux-s390x": "0.17.19", - "@esbuild/linux-x64": "0.17.19", - "@esbuild/netbsd-x64": "0.17.19", - "@esbuild/openbsd-x64": "0.17.19", - "@esbuild/sunos-x64": "0.17.19", - "@esbuild/win32-arm64": "0.17.19", - "@esbuild/win32-ia32": "0.17.19", - "@esbuild/win32-x64": "0.17.19" - } - }, - "fast-glob": { - "version": "3.3.0", - "requires": { - "@nodelib/fs.stat": "^2.0.2", - "@nodelib/fs.walk": "^1.2.3", - "glob-parent": "^5.1.2", - "merge2": "^1.3.0", - "micromatch": "^4.0.4" - } - }, - "fastq": { - "version": "1.15.0", - "requires": { - "reusify": "^1.0.4" - } - }, - "fill-range": { - "version": "7.0.1", - "requires": { - "to-regex-range": "^5.0.1" - } - }, - "fs.realpath": { - "version": "1.0.0" - }, - "fsevents": { - "version": "2.3.2", - "optional": true - }, - "function-bind": { - "version": "1.1.1" - }, - "glob": { - "version": "7.1.6", - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - }, - "glob-parent": { - "version": "5.1.2", - "requires": { - "is-glob": "^4.0.1" - } - }, - "has": { - "version": "1.0.3", - "requires": { - "function-bind": "^1.1.1" - } - }, - "immutable": { - "version": "4.3.1" - }, - "inflight": { - "version": "1.0.6", - "requires": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "inherits": { - "version": "2.0.4" - }, - "inputmask": { - "version": "5.0.8" - }, - "is-binary-path": { - "version": "2.1.0", - "requires": { - "binary-extensions": "^2.0.0" - } - }, - "is-core-module": { - "version": "2.12.1", - "requires": { - "has": "^1.0.3" - } - }, - "is-extglob": { - "version": "2.1.1" - }, - "is-glob": { - "version": "4.0.3", - "requires": { - "is-extglob": "^2.1.1" - } - }, - "is-number": { - "version": "7.0.0" - }, - "jiti": { - "version": "1.19.1" - }, - "lilconfig": { - "version": "2.1.0" - }, - "lines-and-columns": { - "version": "1.2.4" - }, - "merge2": { - "version": "1.4.1" - }, - "micromatch": { - "version": "4.0.5", - "requires": { - "braces": "^3.0.2", - "picomatch": "^2.3.1" - } - }, - "minimatch": { - "version": "3.1.2", - "requires": { - "brace-expansion": "^1.1.7" - } - }, - "mz": { - "version": "2.7.0", - "requires": { - "any-promise": "^1.0.0", - "object-assign": "^4.0.1", - "thenify-all": "^1.0.0" - } - }, - "nanoid": { - "version": "3.3.6" - }, - "normalize-path": { - "version": "3.0.0" - }, - "object-assign": { - "version": "4.1.1" - }, - "object-hash": { - "version": "3.0.0" - }, - "once": { - "version": "1.4.0", - "requires": { - "wrappy": "1" - } - }, - "path-is-absolute": { - "version": "1.0.1" - }, - "path-parse": { - "version": "1.0.7" - }, - "phoenix": { - "version": "file:../../../deps/phoenix" - }, - "phoenix_html": { - "version": "file:../../../deps/phoenix_html" - }, - "phoenix_live_view": { - "version": "file:../../../deps/phoenix_live_view" - }, - "picocolors": { - "version": "1.0.0" - }, - "picomatch": { - "version": "2.3.1" - }, - "pify": { - "version": "2.3.0" - }, - "pirates": { - "version": "4.0.6" - }, - "postcss": { - "version": "8.4.26", - "requires": { - "nanoid": "^3.3.6", - "picocolors": "^1.0.0", - "source-map-js": "^1.0.2" - } - }, - "postcss-import": { - "version": "15.1.0", - "requires": { - "postcss-value-parser": "^4.0.0", - "read-cache": "^1.0.0", - "resolve": "^1.1.7" - } - }, - "postcss-js": { - "version": "4.0.1", - "requires": { - "camelcase-css": "^2.0.1" - } - }, - "postcss-load-config": { - "version": "4.0.1", - "requires": { - "lilconfig": "^2.0.5", - "yaml": "^2.1.1" - } - }, - "postcss-nested": { - "version": "6.0.1", - "requires": { - "postcss-selector-parser": "^6.0.11" - } - }, - "postcss-selector-parser": { - "version": "6.0.13", - "requires": { - "cssesc": "^3.0.0", - "util-deprecate": "^1.0.2" - } - }, - "postcss-value-parser": { - "version": "4.2.0" - }, - "queue-microtask": { - "version": "1.2.3" - }, - "read-cache": { - "version": "1.0.0", - "requires": { - "pify": "^2.3.0" - } - }, - "readdirp": { - "version": "3.6.0", - "requires": { - "picomatch": "^2.2.1" - } - }, - "resolve": { - "version": "1.22.2", - "requires": { - "is-core-module": "^2.11.0", - "path-parse": "^1.0.7", - "supports-preserve-symlinks-flag": "^1.0.0" - } - }, - "reusify": { - "version": "1.0.4" - }, - "run-parallel": { - "version": "1.2.0", - "requires": { - "queue-microtask": "^1.2.2" - } - }, - "sass": { - "version": "1.63.6", - "requires": { - "chokidar": ">=3.0.0 <4.0.0", - "immutable": "^4.0.0", - "source-map-js": ">=0.6.2 <2.0.0" - } - }, - "source-map-js": { - "version": "1.0.2" - }, - "sucrase": { - "version": "3.33.0", - "requires": { - "@jridgewell/gen-mapping": "^0.3.2", - "commander": "^4.0.0", - "glob": "7.1.6", - "lines-and-columns": "^1.1.6", - "mz": "^2.7.0", - "pirates": "^4.0.1", - "ts-interface-checker": "^0.1.9" - } - }, - "supports-preserve-symlinks-flag": { - "version": "1.0.0" - }, - "tailwindcss": { - "version": "3.3.3", - "requires": { - "@alloc/quick-lru": "^5.2.0", - "arg": "^5.0.2", - "chokidar": "^3.5.3", - "didyoumean": "^1.2.2", - "dlv": "^1.1.3", - "fast-glob": "^3.2.12", - "glob-parent": "^6.0.2", - "is-glob": "^4.0.3", - "jiti": "^1.18.2", - "lilconfig": "^2.1.0", - "micromatch": "^4.0.5", - "normalize-path": "^3.0.0", - "object-hash": "^3.0.0", - "picocolors": "^1.0.0", - "postcss": "^8.4.23", - "postcss-import": "^15.1.0", - "postcss-js": "^4.0.1", - "postcss-load-config": "^4.0.1", - "postcss-nested": "^6.0.1", - "postcss-selector-parser": "^6.0.11", - "resolve": "^1.22.2", - "sucrase": "^3.32.0" - }, - "dependencies": { - "glob-parent": { - "version": "6.0.2", - "requires": { - "is-glob": "^4.0.3" - } - } - } - }, - "thenify": { - "version": "3.3.1", - "requires": { - "any-promise": "^1.0.0" - } - }, - "thenify-all": { - "version": "1.6.0", - "requires": { - "thenify": ">= 3.1.0 < 4" - } - }, - "to-regex-range": { - "version": "5.0.1", - "requires": { - "is-number": "^7.0.0" - } - }, - "topbar": { - "version": "1.0.1" - }, - "ts-interface-checker": { - "version": "0.1.13" - }, - "util-deprecate": { - "version": "1.0.2" - }, - "wrappy": { - "version": "1.0.2" - }, - "yaml": { - "version": "2.3.1" - } } } diff --git a/assets/package.json b/assets/package.json index e23ebadf..ef6cf01b 100644 --- a/assets/package.json +++ b/assets/package.json @@ -9,11 +9,11 @@ "dependencies": { "esbuild": "^0.17.10", "inputmask": "^5.0.7", - "phoenix": "file:../../../deps/phoenix", - "phoenix_html": "file:../../../deps/phoenix_html", - "phoenix_live_view": "file:../../../deps/phoenix_live_view", + "phoenix": "file:../deps/phoenix", + "phoenix_html": "file:../deps/phoenix_html", + "phoenix_live_view": "file:../deps/phoenix_live_view", "sass": "^1.63.4", "tailwindcss": "^3.2.7", "topbar": "^1.0.1" } -} +} \ No newline at end of file diff --git a/rel/env.sh.eex b/rel/env.sh.eex deleted file mode 100644 index 4f278d24..00000000 --- a/rel/env.sh.eex +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - - # Sets and enables heart (recommended only in daemon mode) - case $RELEASE_COMMAND in - daemon*) - HEART_COMMAND="$RELEASE_ROOT/bin/$RELEASE_NAME $RELEASE_COMMAND" - export HEART_COMMAND - export ELIXIR_ERL_OPTIONS="-heart" - ;; - *) - ;; - esac - -# # Set the release to load code on demand (interactive) instead of preloading (embedded). -# export RELEASE_MODE=interactive - -# # Set the release to work across nodes. -# # RELEASE_DISTRIBUTION must be "sname" (local), "name" (distributed) or "none". -# export RELEASE_DISTRIBUTION=name -# export RELEASE_NODE=<%= @release.name %> diff --git a/rel/overlays/bin/server b/rel/overlays/bin/server new file mode 100755 index 00000000..7911099e --- /dev/null +++ b/rel/overlays/bin/server @@ -0,0 +1,5 @@ +#!/bin/sh +set -eu + +cd -P -- "$(dirname -- "$0")" +./pescarte eval Pescarte.Release.migrate && PHX_SERVER=true exec ./pescarte start diff --git a/rel/remote.vm.args.eex b/rel/remote.vm.args.eex deleted file mode 100644 index 983397a7..00000000 --- a/rel/remote.vm.args.eex +++ /dev/null @@ -1,8 +0,0 @@ -## Customize flags given to the VM: https://www.erlang.org/doc/man/erl.html -## -mode/-name/-sname/-setcookie are configured via env vars, do not set them here - -## Increase number of concurrent ports/sockets -##+Q 65536 - -## Tweak GC to run more often -##-env ERL_FULLSWEEP_AFTER 10 diff --git a/rel/vm.args.eex b/rel/vm.args.eex deleted file mode 100644 index acfdc9ba..00000000 --- a/rel/vm.args.eex +++ /dev/null @@ -1,8 +0,0 @@ -## Customize flags given to the VM: https://www.erlang.org/doc/man/erl.html -## -mode/-name/-sname/-setcookie are configured via env vars, do not set them here - -## Increase number of concurrent ports/sockets -##+Q 65536 - -## Tweak GC to run more often --env ERL_FULLSWEEP_AFTER 10