move more fully to runtime config with release, improved docker build, updated phx liveview js
This commit is contained in:
parent
db9f127e7b
commit
573a1e9cfe
38 changed files with 428 additions and 205 deletions
45
.dockerignore
Normal file
45
.dockerignore
Normal file
|
@ -0,0 +1,45 @@
|
|||
# This file excludes paths from the Docker build context.
|
||||
#
|
||||
# By default, Docker's build context includes all files (and folders) in the
|
||||
# current directory. Even if a file isn't copied into the container it is still sent to
|
||||
# the Docker daemon.
|
||||
#
|
||||
# There are multiple reasons to exclude files from the build context:
|
||||
#
|
||||
# 1. Prevent nested folders from being copied into the container (ex: exclude
|
||||
# /assets/node_modules when copying /assets)
|
||||
# 2. Reduce the size of the build context and improve build time (ex. /build, /deps, /doc)
|
||||
# 3. Avoid sending files containing sensitive information
|
||||
#
|
||||
# More information on using .dockerignore is available here:
|
||||
# https://docs.docker.com/engine/reference/builder/#dockerignore-file
|
||||
|
||||
.dockerignore
|
||||
|
||||
# Ignore git, but keep git HEAD and refs to access current commit hash if needed:
|
||||
#
|
||||
# $ cat .git/HEAD | awk '{print ".git/"$2}' | xargs cat
|
||||
# d0b8727759e1e0e7aa3d41707d12376e373d5ecc
|
||||
.git
|
||||
!.git/HEAD
|
||||
!.git/refs
|
||||
|
||||
# Common development/test artifacts
|
||||
/cover/
|
||||
/doc/
|
||||
/test/
|
||||
/tmp/
|
||||
.elixir_ls
|
||||
|
||||
# Mix artifacts
|
||||
/_build/
|
||||
/deps/
|
||||
*.ez
|
||||
|
||||
# Generated on crash by the VM
|
||||
erl_crash.dump
|
||||
|
||||
# Static artifacts - These should be fetched and built inside the Docker image
|
||||
/assets/node_modules/
|
||||
/priv/static/assets/
|
||||
/priv/static/cache_manifest.json
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -50,3 +50,4 @@ npm-debug.log
|
|||
|
||||
# dev
|
||||
TODO.md
|
||||
NOTES.md
|
||||
|
|
109
Dockerfile
109
Dockerfile
|
@ -1,31 +1,96 @@
|
|||
# ./Dockerfile
|
||||
# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian instead of
|
||||
# Alpine to avoid DNS resolution issues in production.
|
||||
#
|
||||
# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu
|
||||
# https://hub.docker.com/_/ubuntu?tab=tags
|
||||
#
|
||||
#
|
||||
# This file is based on these images:
|
||||
#
|
||||
# - https://hub.docker.com/r/hexpm/elixir/tags - for the build image
|
||||
# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20230109-slim - for the release image
|
||||
# - https://pkgs.org/ - resource for finding needed packages
|
||||
# - Ex: hexpm/elixir:1.14.3-erlang-25.2.1-debian-bullseye-20230109-slim
|
||||
#
|
||||
ARG ELIXIR_VERSION=1.14.3
|
||||
ARG OTP_VERSION=25.2.1
|
||||
ARG DEBIAN_VERSION=bullseye-20230109-slim
|
||||
|
||||
# Extend from the official Elixir image
|
||||
FROM elixir:1.13.4-otp-25-alpine
|
||||
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
|
||||
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
|
||||
|
||||
# # install the package postgresql-client to run pg_isready within entrypoint script
|
||||
# RUN apt-get update && \
|
||||
# apt-get install -y postgresql-client
|
||||
FROM ${BUILDER_IMAGE} as builder
|
||||
|
||||
# Create app directory and copy the Elixir project into it
|
||||
RUN mkdir /app
|
||||
COPY . /app
|
||||
# install build dependencies
|
||||
RUN apt-get update -y && apt-get install -y build-essential git curl && \
|
||||
curl -fsSL https://deb.nodesource.com/setup_19.x | bash - && \
|
||||
apt-get install -y nodejs && apt-get clean && \
|
||||
rm -f /var/lib/apt/lists/*_* && npm i -g npm
|
||||
|
||||
# prepare build dir
|
||||
WORKDIR /app
|
||||
|
||||
# Install the build tools we'll need
|
||||
RUN apk update && \
|
||||
apk upgrade --no-cache && \
|
||||
apk add --no-cache \
|
||||
build-base && \
|
||||
mix local.rebar --force && \
|
||||
mix local.hex --force
|
||||
# install hex + rebar
|
||||
RUN mix local.hex --force && \
|
||||
mix local.rebar --force
|
||||
|
||||
# set build ENV
|
||||
ENV MIX_ENV="prod"
|
||||
|
||||
# The environment to build with
|
||||
ENV MIX_ENV=prod
|
||||
# install mix dependencies
|
||||
COPY mix.exs mix.lock ./
|
||||
RUN mix deps.get --only $MIX_ENV
|
||||
RUN mkdir config
|
||||
|
||||
# Get deps and compile
|
||||
RUN mix do deps.get, deps.compile, compile
|
||||
# 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
|
||||
|
||||
# Start command
|
||||
CMD = ["/app/entrypoint.sh"]
|
||||
COPY priv priv
|
||||
|
||||
COPY lib lib
|
||||
|
||||
COPY assets assets
|
||||
|
||||
# install node modules
|
||||
RUN npm --prefix assets install
|
||||
# compile assets
|
||||
RUN mix assets.deploy
|
||||
|
||||
# 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 && apt-get install -y libstdc++6 openssl libncurses5 locales \
|
||||
&& 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/shift73k ./
|
||||
|
||||
USER nobody
|
||||
|
||||
CMD ["/app/bin/server"]
|
31
Dockerfile.bak
Normal file
31
Dockerfile.bak
Normal file
|
@ -0,0 +1,31 @@
|
|||
# ./Dockerfile
|
||||
|
||||
# Extend from the official Elixir image
|
||||
FROM elixir:1.13.4-otp-25-alpine
|
||||
|
||||
# # install the package postgresql-client to run pg_isready within entrypoint script
|
||||
# RUN apt-get update && \
|
||||
# apt-get install -y postgresql-client
|
||||
|
||||
# Create app directory and copy the Elixir project into it
|
||||
RUN mkdir /app
|
||||
COPY . /app
|
||||
WORKDIR /app
|
||||
|
||||
# Install the build tools we'll need
|
||||
RUN apk update && \
|
||||
apk upgrade --no-cache && \
|
||||
apk add --no-cache \
|
||||
build-base && \
|
||||
mix local.rebar --force && \
|
||||
mix local.hex --force
|
||||
|
||||
|
||||
# The environment to build with
|
||||
ENV MIX_ENV=prod
|
||||
|
||||
# Get deps and compile
|
||||
RUN mix do deps.get, deps.compile, compile
|
||||
|
||||
# Start command
|
||||
CMD = ["/app/entrypoint.sh"]
|
70
README.md
70
README.md
|
@ -11,12 +11,14 @@ To run in production, you'll need to provide several environment variable values
|
|||
```bash
|
||||
MIX_ENV=prod \
|
||||
PHX_SERVER=true \
|
||||
TZ=America/New_York \
|
||||
DB_SOCK=[postgres unix socket path] \
|
||||
DB_NAME=[postgres db name] \
|
||||
DB_USER=[postgres db user] \
|
||||
DB_PASS=[postgres db user password] \
|
||||
SECRET_KEY_BASE=[phoenix secret key base] \
|
||||
PHX_HOST=[server fqdn (e.g., shift.73k.us)] \
|
||||
PORT=4000 \
|
||||
SMTP_RELAY=[smtp server] \
|
||||
SMTP_PORT=[smtp port] \
|
||||
SMTP_USER=[smtp username] \
|
||||
|
@ -28,26 +30,60 @@ ALLOW_REG=[open for registration? true/false] \
|
|||
iex -S mix phx.server
|
||||
```
|
||||
|
||||
### Rebuilding assets for production
|
||||
|
||||
```bash
|
||||
# rebuild static assets:
|
||||
MIX_ENV=prod mix phx.digest.clean --all
|
||||
rm -rf ./priv/static/*
|
||||
npm --prefix assets run build
|
||||
MIX_ENV=prod mix phx.digest
|
||||
# then do a new commit and push...
|
||||
```
|
||||
|
||||
## TODO
|
||||
|
||||
- [X] ~~*Proper modal to delete shifts?*~~ [2022-08-14]
|
||||
- [ ] move runtime config out of compile-time config files, to move towards supporting releases
|
||||
- [ ] probably need to use `def get_app_config` style functions instead of `@module_var` module variables, ([see this](https://stephenbussey.com/2019/01/03/understanding-compile-time-dependencies-in-elixir-a-bug-hunt.html))
|
||||
- [ ] Update tests, which are probably all way out of date. But I also don't care that much for this project...
|
||||
- [X] ~~*move runtime config out of compile-time config files, to move towards supporting releases*~~ [2023-01-28]
|
||||
- [ ] bootstrap dark mode?
|
||||
- [ ] update tests, which are way out of date? Also I don't care?
|
||||
|
||||
## Deploying
|
||||
## Deploying with docker
|
||||
|
||||
I'm using a dumb & simple docker approach to deploying this now. Nothing automated, the basic steps are:
|
||||
The Dockerfile will enable building a new container. I do it all with docker compose, here's an example compose yml:
|
||||
|
||||
1. ensure latest assets are built, digested, and committed to the repo
|
||||
|
||||
```shell
|
||||
# rebuild static assets:
|
||||
MIX_ENV=prod mix phx.digest.clean --all
|
||||
rm -rf ./priv/static/*
|
||||
npm --prefix assets run build
|
||||
MIX_ENV=prod mix phx.digest
|
||||
# then do a new commit and push...
|
||||
```
|
||||
|
||||
2. on server, build a new container, and run it
|
||||
```yaml
|
||||
version: '3.9'
|
||||
services:
|
||||
shift73k:
|
||||
build:
|
||||
context: ./shift73k # relative path from docker-compose.yml to shift73k repo
|
||||
network: host
|
||||
container_name: www-shift73k
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
- /srv/dck/postgres/sock/postgres:/var/run/postgresql # if using unix socket
|
||||
# env_file: ./shift73k.env # optionally, put your env vars in a separate file
|
||||
environment:
|
||||
- PHX_SERVER=true
|
||||
- TZ=America/New_York
|
||||
- DB_SOCK=/var/run/postgresql # if using unix socket instead of db url
|
||||
- DB_NAME=[postgres db name] # if using unix socket instead of db url
|
||||
- DB_USER=[postgres db user] # if using unix socket instead of db url
|
||||
- DB_PASS=[postgres db user password] # if using unix socket instead of db url
|
||||
- SECRET_KEY_BASE=[phoenix secret key base]
|
||||
- PHX_HOST=[server fqdn (e.g., shift.73k.us)]
|
||||
- PORT=4000
|
||||
- SMTP_RELAY=[smtp server]
|
||||
- SMTP_PORT=[smtp port]
|
||||
- SMTP_USER=[smtp username]
|
||||
- SMTP_PASS=[smtp user password]
|
||||
- MAIL_REPLY_TO=reply@73k.us
|
||||
- MAIL_FROM_FRIENDLY=Shift73k
|
||||
- MAIL_FROM_ADDR=shift73k@73k.us
|
||||
- ALLOW_REG=[open for registration? true/false]
|
||||
ports:
|
||||
- 4000:4000
|
||||
```
|
||||
|
|
9
assets/package-lock.json
generated
9
assets/package-lock.json
generated
|
@ -14,12 +14,12 @@
|
|||
"hamburgers": "^1.2.1",
|
||||
"phoenix": "^1.6.11",
|
||||
"phoenix_html": "^3.2.0",
|
||||
"phoenix_live_view": "^0.17.11",
|
||||
"topbar": "^1.x"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.6.5",
|
||||
"@types/phoenix": "^1.5.4",
|
||||
"phoenix_live_view": "^0.18.11",
|
||||
"sass": "^1.54.3",
|
||||
"svg-sprite-generator": "^0.0.7",
|
||||
"vite": "^4.0.4"
|
||||
|
@ -847,9 +847,10 @@
|
|||
"integrity": "sha512-zv7PIZk0MPkF0ax8n465Q6w86+sGAy5cTem6KcbkUbdgxGc0y3WZmzkM2bSlYdSGbLEZfjXxos1G72xXsha6xA=="
|
||||
},
|
||||
"node_modules/phoenix_live_view": {
|
||||
"version": "0.17.12",
|
||||
"resolved": "https://registry.npmjs.org/phoenix_live_view/-/phoenix_live_view-0.17.12.tgz",
|
||||
"integrity": "sha512-hHK43hPNd8vnY1+arUp2b0e//uP6bGMsCEKw556vG8Nth1EUqnJ8Vi0Shu1ykG2VId5HtBJTSjiwnx+wERSGHw=="
|
||||
"version": "0.18.11",
|
||||
"resolved": "https://registry.npmjs.org/phoenix_live_view/-/phoenix_live_view-0.18.11.tgz",
|
||||
"integrity": "sha512-p/mBu/O3iVLvAreUoDeSZ4/myQJJeR8BH7Yu9LVCMI2xe2IZ2mffxtDGJb0mxnJrUQa7p03HHNlKGXj7LSJDdg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/picocolors": {
|
||||
"version": "1.0.0",
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
"devDependencies": {
|
||||
"@types/node": "^18.6.5",
|
||||
"@types/phoenix": "^1.5.4",
|
||||
"phoenix_live_view": "^0.18.11",
|
||||
"sass": "^1.54.3",
|
||||
"svg-sprite-generator": "^0.0.7",
|
||||
"vite": "^4.0.4"
|
||||
|
@ -22,7 +23,6 @@
|
|||
"hamburgers": "^1.2.1",
|
||||
"phoenix": "^1.6.11",
|
||||
"phoenix_html": "^3.2.0",
|
||||
"phoenix_live_view": "^0.17.11",
|
||||
"topbar": "^1.x"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,13 +12,6 @@ config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase
|
|||
config :shift73k,
|
||||
ecto_repos: [Shift73k.Repo]
|
||||
|
||||
# Custom application global variables
|
||||
config :shift73k, :app_global_vars,
|
||||
time_zone: "America/New_York",
|
||||
mailer_reply_to: "reply_to@example.com",
|
||||
mailer_from: "app_name@example.com",
|
||||
allow_registration: :true
|
||||
|
||||
# Configures the endpoint
|
||||
config :shift73k, Shift73kWeb.Endpoint,
|
||||
url: [host: "localhost"],
|
||||
|
|
|
@ -123,7 +123,11 @@ config :shift73k, Shift73k.Mailer,
|
|||
no_mx_lookups: false
|
||||
|
||||
config :shift73k, :app_global_vars,
|
||||
mailer_reply_to: System.get_env("APP_REPLY_TO"),
|
||||
mailer_from: {System.get_env("MAIL_FROM_FRIENDLY"), System.get_env("MAIL_FROM_ADDR")},
|
||||
allow_registration: System.get_env("ALLOW_REG")
|
||||
time_zone: System.get_env("TZ") || "America/New_York",
|
||||
mailer_reply_to: System.get_env("MAIL_REPLY_TO") || "reply_to@example.com",
|
||||
mailer_from: {
|
||||
System.get_env("MAIL_FROM_FRIENDLY") || "Shift73k",
|
||||
System.get_env("MAIL_FROM_ADDR") || "app_name@example.com"
|
||||
},
|
||||
allow_registration: System.get_env("ALLOW_REG") || :true
|
||||
end
|
||||
|
|
|
@ -7,12 +7,32 @@ defmodule Shift73k do
|
|||
if it comes from the database, an external API or others.
|
||||
"""
|
||||
|
||||
@app_vars Application.compile_env(:shift73k, :app_global_vars, time_zone: "America/New_York")
|
||||
@app_time_zone @app_vars[:time_zone]
|
||||
|
||||
@weekdays [:monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday]
|
||||
|
||||
def app_time_zone, do: @app_time_zone
|
||||
defp get_app_config_env do
|
||||
Application.get_env(:shift73k, :app_global_vars,
|
||||
time_zone: "America/New_York",
|
||||
allow_registration: :true,
|
||||
mailer_reply_to: "admin@example.com",
|
||||
mailer_from: {"Shift73k", "shift73k@example.com"}
|
||||
)
|
||||
end
|
||||
|
||||
def weekdays, do: @weekdays
|
||||
|
||||
def get_app_time_zone, do:
|
||||
get_app_config_env() |> Keyword.fetch!(:time_zone) |> IO.inspect(label: "time_zone", pretty: :true)
|
||||
|
||||
def get_app_mailer_from, do:
|
||||
get_app_config_env() |> Keyword.fetch!(:mailer_from) |> IO.inspect(label: "mailer_from", pretty: :true)
|
||||
|
||||
def get_app_mailer_reply_to, do:
|
||||
get_app_config_env() |> Keyword.fetch!(:mailer_reply_to) |> IO.inspect(label: "mailer_reply_to", pretty: :true)
|
||||
|
||||
def get_app_allow_reg, do:
|
||||
get_app_config_env() |> Keyword.fetch!(:allow_registration) |> get_app_allow_reg()
|
||||
|> IO.inspect(label: "allow_registration", pretty: :true)
|
||||
def get_app_allow_reg("false"), do: :false
|
||||
def get_app_allow_reg(:false), do: :false
|
||||
def get_app_allow_reg(_not_false), do: :true
|
||||
end
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
defmodule Shift73k.Mailer.UserEmail do
|
||||
import Swoosh.Email
|
||||
import Shift73k, only: [get_app_mailer_from: 0, get_app_mailer_reply_to: 0]
|
||||
|
||||
@mailer_vars Application.compile_env(:shift73k, :app_global_vars,
|
||||
mailer_reply_to: "admin@example.com",
|
||||
mailer_from: {"Shift73k", "shift73k@example.com"}
|
||||
)
|
||||
|
||||
def compose(user_email, subject, body_text) do
|
||||
new()
|
||||
|> from(@mailer_vars[:mailer_from])
|
||||
|> from(get_app_mailer_from())
|
||||
|> to(user_email)
|
||||
|> header("Reply-To", @mailer_vars[:mailer_reply_to])
|
||||
|> header("Reply-To", get_app_mailer_reply_to())
|
||||
|> subject(subject)
|
||||
|> text_body(body_text)
|
||||
end
|
||||
|
|
28
lib/shift73k/release.ex
Normal file
28
lib/shift73k/release.ex
Normal file
|
@ -0,0 +1,28 @@
|
|||
defmodule Shift73k.Release do
|
||||
@moduledoc """
|
||||
Used for executing DB release tasks when run in production without Mix
|
||||
installed.
|
||||
"""
|
||||
@app :shift73k
|
||||
|
||||
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
|
|
@ -1,7 +1,7 @@
|
|||
defmodule Shift73k.Shifts.Templates.ShiftTemplate do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
import Shift73k, only: [app_time_zone: 0]
|
||||
import Shift73k, only: [get_app_time_zone: 0]
|
||||
|
||||
alias Shift73k.Shifts
|
||||
alias Shift73k.Shifts.Templates.ShiftTemplate
|
||||
|
@ -12,7 +12,7 @@ defmodule Shift73k.Shifts.Templates.ShiftTemplate do
|
|||
field :subject, :string
|
||||
field :description, :string
|
||||
field :location, :string
|
||||
field :time_zone, :string, default: app_time_zone()
|
||||
field :time_zone, :string, default: get_app_time_zone()
|
||||
field :time_start, :time, default: ~T[09:00:00]
|
||||
field :time_end, :time, default: ~T[17:00:00]
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
defmodule Shift73kWeb.ShiftAssignLive.Index do
|
||||
use Shift73kWeb, :live_view
|
||||
import Shift73k, only: [app_time_zone: 0]
|
||||
import Shift73k, only: [get_app_time_zone: 0]
|
||||
|
||||
alias Shift73k.Repo
|
||||
alias Shift73k.Shifts
|
||||
|
|
|
@ -127,7 +127,7 @@
|
|||
disabled: @shift_template.id != @custom_shift.id,
|
||||
phx_debounce: 250,
|
||||
list: "tz_list",
|
||||
placeholder: "Default: #{app_time_zone()}"
|
||||
placeholder: "Default: #{get_app_time_zone()}"
|
||||
%>
|
||||
<datalist id="tz_list">
|
||||
<%= for tz_name <- Tzdata.zone_list() do %>
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<div class="inner-addon left-addon mb-3">
|
||||
<i class="bi bi-map icon is-left text-muted fs-5"></i>
|
||||
<%= text_input iimf, :time_zone,
|
||||
value: Shift73k.app_time_zone(),
|
||||
value: Shift73k.get_app_time_zone(),
|
||||
class: @tz_valid && "form-control" || "form-control is-invalid",
|
||||
phx_debounce: 250,
|
||||
aria_describedby: "ics-import-tz-error",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
defmodule Shift73kWeb.ShiftTemplateLive.FormComponent do
|
||||
use Shift73kWeb, :live_component
|
||||
import Shift73k, only: [app_time_zone: 0]
|
||||
import Shift73k, only: [get_app_time_zone: 0]
|
||||
|
||||
alias Shift73k.Shifts.Templates
|
||||
alias Shift73k.Shifts.Templates.ShiftTemplate
|
||||
|
|
|
@ -88,7 +88,7 @@
|
|||
class: input_class(f, :time_zone, "form-control"),
|
||||
phx_debounce: 250,
|
||||
list: "tz_list",
|
||||
placeholder: "Default: #{app_time_zone()}"
|
||||
placeholder: "Default: #{get_app_time_zone()}"
|
||||
%>
|
||||
<datalist id="tz_list">
|
||||
<%= for tz_name <- Tzdata.zone_list() do %>
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
defmodule Shift73kWeb.UserLive.ResetPassword do
|
||||
use Shift73kWeb, :live_view
|
||||
|
||||
import Shift73k, only: [get_app_allow_reg: 0]
|
||||
|
||||
alias Shift73k.Accounts
|
||||
alias Shift73k.Accounts.User
|
||||
|
||||
@app_vars Application.compile_env(:shift73k, :app_global_vars, allow_registration: :true)
|
||||
@app_allow_registration @app_vars[:allow_registration]
|
||||
|
||||
@impl true
|
||||
def mount(_params, session, socket) do
|
||||
|
@ -41,5 +41,5 @@ defmodule Shift73kWeb.UserLive.ResetPassword do
|
|||
end
|
||||
end
|
||||
|
||||
def allow_registration, do: @app_allow_registration
|
||||
def allow_registration, do: get_app_allow_reg()
|
||||
end
|
||||
|
|
|
@ -198,7 +198,7 @@ defmodule Shift73kWeb.UserManagementLive.Index do
|
|||
|
||||
def dt_out(ndt) do
|
||||
ndt
|
||||
|> DateTime.from_naive!(Shift73k.app_time_zone())
|
||||
|> DateTime.from_naive!(Shift73k.get_app_time_zone())
|
||||
|> Calendar.strftime("%Y %b %-d, %-I:%M %p")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,12 +4,11 @@ defmodule Shift73kWeb.EnsureAllowRegistrationPlug do
|
|||
"""
|
||||
import Plug.Conn
|
||||
import Phoenix.Controller
|
||||
import Shift73k, only: [get_app_allow_reg: 0]
|
||||
|
||||
alias Shift73k.Repo
|
||||
alias Shift73k.Accounts.User
|
||||
|
||||
@app_vars Application.compile_env(:shift73k, :app_global_vars, allow_registration: :true)
|
||||
@app_allow_registration @app_vars[:allow_registration]
|
||||
|
||||
@doc false
|
||||
@spec init(any()) :: any()
|
||||
|
@ -19,7 +18,7 @@ defmodule Shift73kWeb.EnsureAllowRegistrationPlug do
|
|||
@spec call(Conn.t(), atom() | [atom()]) :: Conn.t()
|
||||
def call(conn, _opts) do
|
||||
# If there aren't even any users, or registration is allowed
|
||||
if !Repo.exists?(User) || @app_allow_registration do
|
||||
if !Repo.exists?(User) || get_app_allow_reg() do
|
||||
# We will allow registration
|
||||
conn
|
||||
else
|
||||
|
|
|
@ -12,13 +12,13 @@
|
|||
<% end %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link nav_link_opts(@conn, to: Routes.shift_index_path(@conn, :index), class: "dropdown-item") do %>
|
||||
<i class="bi bi-card-list me-1"></i> My Scheduled Shifts
|
||||
<%= link nav_link_opts(@conn, to: Routes.shift_template_index_path(@conn, :index), class: "dropdown-item") do %>
|
||||
<i class="bi bi-clock-history me-1"></i> My Shift Templates
|
||||
<% end %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link nav_link_opts(@conn, to: Routes.shift_template_index_path(@conn, :index), class: "dropdown-item") do %>
|
||||
<i class="bi bi-clock-history me-1"></i> My Shift Templates
|
||||
<%= link nav_link_opts(@conn, to: Routes.shift_index_path(@conn, :index), class: "dropdown-item") do %>
|
||||
<i class="bi bi-card-list me-1"></i> My Scheduled Shifts
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
defmodule Shift73kWeb.LayoutView do
|
||||
use Shift73kWeb, :view
|
||||
import Shift73k, only: [get_app_allow_reg: 0]
|
||||
alias Shift73k.Repo
|
||||
alias Shift73k.Accounts.User
|
||||
alias Shift73kWeb.Roles
|
||||
|
||||
@app_vars Application.compile_env(:shift73k, :app_global_vars, allow_registration: :true)
|
||||
@app_allow_registration @app_vars[:allow_registration]
|
||||
|
||||
# With a Vite.js-based workflow, we will import different asset files in development
|
||||
# and in production builds. Therefore, we will need a way to conditionally render
|
||||
|
@ -14,7 +13,7 @@ defmodule Shift73kWeb.LayoutView do
|
|||
@env Mix.env() # remember value at compile time
|
||||
def dev_env?, do: @env == :dev
|
||||
|
||||
def allow_registration, do: @app_allow_registration
|
||||
def allow_registration, do: get_app_allow_reg()
|
||||
|
||||
def nav_link_opts(conn, opts) do
|
||||
case Keyword.get(opts, :to) == Phoenix.Controller.current_path(conn) do
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
defmodule Shift73kWeb.UserConfirmationView do
|
||||
use Shift73kWeb, :view
|
||||
import Shift73k, only: [get_app_allow_reg: 0]
|
||||
alias Shift73k.Accounts.User
|
||||
|
||||
@app_vars Application.compile_env(:shift73k, :app_global_vars, allow_registration: :true)
|
||||
@app_allow_registration @app_vars[:allow_registration]
|
||||
|
||||
def allow_registration, do: @app_allow_registration
|
||||
def allow_registration, do: get_app_allow_reg()
|
||||
end
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
defmodule Shift73kWeb.UserResetPasswordView do
|
||||
use Shift73kWeb, :view
|
||||
import Shift73k, only: [get_app_allow_reg: 0]
|
||||
alias Shift73k.Accounts.User
|
||||
|
||||
@app_vars Application.compile_env(:shift73k, :app_global_vars, allow_registration: :true)
|
||||
@app_allow_registration @app_vars[:allow_registration]
|
||||
|
||||
def allow_registration, do: @app_allow_registration
|
||||
def allow_registration, do: get_app_allow_reg()
|
||||
end
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
defmodule Shift73kWeb.UserSessionView do
|
||||
use Shift73kWeb, :view
|
||||
import Shift73k, only: [get_app_allow_reg: 0]
|
||||
alias Shift73k.Accounts.User
|
||||
|
||||
@app_vars Application.compile_env(:shift73k, :app_global_vars, allow_registration: :true)
|
||||
@app_allow_registration @app_vars[:allow_registration]
|
||||
|
||||
def allow_registration, do: @app_allow_registration
|
||||
def allow_registration, do: get_app_allow_reg()
|
||||
end
|
||||
|
|
5
mix.exs
5
mix.exs
|
@ -4,7 +4,7 @@ defmodule Shift73k.MixProject do
|
|||
def project do
|
||||
[
|
||||
app: :shift73k,
|
||||
version: "0.1.2",
|
||||
version: "0.2.1",
|
||||
elixir: "~> 1.12",
|
||||
elixirc_paths: elixirc_paths(Mix.env()),
|
||||
compilers: Mix.compilers(),
|
||||
|
@ -71,7 +71,8 @@ defmodule Shift73k.MixProject do
|
|||
setup: ["deps.get", "ecto.setup", "cmd npm install --prefix assets"],
|
||||
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
|
||||
"ecto.reset": ["ecto.drop", "ecto.setup"],
|
||||
test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"]
|
||||
test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"],
|
||||
"assets.deploy": ["cmd npm --prefix assets run build", "phx.digest"]
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
82
priv/static/assets/app-6b490c3bfbd4fd9a3a19b678041545bf.js
Normal file
82
priv/static/assets/app-6b490c3bfbd4fd9a3a19b678041545bf.js
Normal file
File diff suppressed because one or more lines are too long
BIN
priv/static/assets/app-6b490c3bfbd4fd9a3a19b678041545bf.js.gz
Normal file
BIN
priv/static/assets/app-6b490c3bfbd4fd9a3a19b678041545bf.js.gz
Normal file
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
3
rel/overlays/bin/migrate
Executable file
3
rel/overlays/bin/migrate
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
cd -P -- "$(dirname -- "$0")"
|
||||
exec ./shift73k eval Shift73k.Release.migrate
|
1
rel/overlays/bin/migrate.bat
Executable file
1
rel/overlays/bin/migrate.bat
Executable file
|
@ -0,0 +1 @@
|
|||
call "%~dp0\shift73k" eval Shift73k.Release.migrate
|
3
rel/overlays/bin/server
Executable file
3
rel/overlays/bin/server
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
cd -P -- "$(dirname -- "$0")"
|
||||
PHX_SERVER=true exec ./shift73k start
|
2
rel/overlays/bin/server.bat
Executable file
2
rel/overlays/bin/server.bat
Executable file
|
@ -0,0 +1,2 @@
|
|||
set PHX_SERVER=true
|
||||
call "%~dp0\shift73k" start
|
Loading…
Reference in a new issue