-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from pulibrary/11-generate-app
Generate Elixir Application
- Loading branch information
Showing
55 changed files
with
2,839 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
import_deps: [:ecto, :ecto_sql, :phoenix], | ||
subdirectories: ["priv/*/migrations"], | ||
plugins: [Phoenix.LiveView.HTMLFormatter], | ||
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Create and publish a Docker image | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. | ||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. | ||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. | ||
permissions: | ||
contents: read | ||
packages: write | ||
# | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=sha | ||
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. | ||
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. | ||
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
file: Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# The directory Mix will write compiled artifacts to. | ||
/_build/ | ||
|
||
# If you run "mix test --cover", coverage assets end up here. | ||
/cover/ | ||
|
||
# The directory Mix downloads your dependencies sources to. | ||
/deps/ | ||
|
||
# Where 3rd-party dependencies like ExDoc output generated docs. | ||
/doc/ | ||
|
||
# Ignore .fetch files in case you like to edit your project deps locally. | ||
/.fetch | ||
|
||
# If the VM crashes, it generates a dump, let's ignore it too. | ||
erl_crash.dump | ||
|
||
# Also ignore archive artifacts (built via "mix archive.build"). | ||
*.ez | ||
|
||
# Temporary files, for example, from tests. | ||
/tmp/ | ||
|
||
# Ignore package tarball (built via "mix hex.build"). | ||
dpul_collections-*.tar | ||
|
||
# Ignore assets that are produced by build tools. | ||
/priv/static/assets/ | ||
|
||
# Ignore digested assets cache. | ||
/priv/static/cache_manifest.json | ||
|
||
# In case you use Node.js/npm, you want to ignore these. | ||
npm-debug.log | ||
/assets/node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,5 @@ | ||
name: dpul-collections | ||
services: | ||
solr: | ||
api: 3 | ||
type: lando | ||
app_mount: false | ||
moreHttpPorts: | ||
- 8983 | ||
services: | ||
image: ghcr.io/pulibrary/dpul-collections:fixtures-v1 | ||
ports: | ||
- "8983:8983" | ||
command: solr-fg | ||
database: | ||
type: postgres:15 | ||
portforward: 5434 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
elixir 1.16.3-otp-26 | ||
erlang 26.2.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# 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-20240513-slim - for the release image | ||
# - https://pkgs.org/ - resource for finding needed packages | ||
# - Ex: hexpm/elixir:1.16.3-erlang-26.2.5-debian-bullseye-20240513-slim | ||
# | ||
ARG ELIXIR_VERSION=1.16.3 | ||
ARG OTP_VERSION=26.2.5 | ||
ARG DEBIAN_VERSION=bookworm-20240513-slim | ||
|
||
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}" | ||
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}" | ||
|
||
FROM ${BUILDER_IMAGE} as builder | ||
|
||
# install build dependencies | ||
RUN apt-get update -y && apt-get install -y build-essential git \ | ||
&& apt-get clean && rm -f /var/lib/apt/lists/*_* | ||
|
||
# prepare build dir | ||
WORKDIR /app | ||
|
||
# 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 | ||
|
||
COPY lib lib | ||
|
||
COPY assets assets | ||
|
||
# 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 ca-certificates \ | ||
&& 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/dpul_collections ./ | ||
|
||
USER nobody | ||
|
||
# If using an environment that doesn't automatically reap zombie processes, it is | ||
# advised to add an init process such as tini via `apt-get install` | ||
# above and adding an entrypoint. See https://github.com/krallin/tini for details | ||
# ENTRYPOINT ["/tini", "--"] | ||
|
||
CMD ["/app/bin/server"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,28 @@ | ||
# DPUL Collections | ||
# DpulCollections | ||
|
||
To run the development database type: `lando start` | ||
|
||
To start your Phoenix server: | ||
|
||
* Run `mix setup` to install and setup dependencies | ||
* Start Phoenix endpoint with `mix phx.server` or inside IEx with `iex -S mix phx.server` | ||
|
||
Now you can visit [`localhost:4000`](http://localhost:4000) from your browser. | ||
|
||
Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html). | ||
|
||
## Build & Run Production Docker Image Locally | ||
|
||
Build Docker Image: `docker build . -t dpul-collections` | ||
|
||
The SECRET_KEY_BASE below is just a filler one for the purpose of testing locally. | ||
|
||
Run Docker Image: `docker run -t -p 4000:4000 -e DATABASE_URL='ecto://postgres:@host.docker.internal:5434/database' -e SECRET_KEY_BASE='B8rwzeX3DFLveiJ4cP28lRGc0PWdEr8ZF/hDoPRucw95Nzf2IPnu7lhEB+Yldx6Z' dpul-collections` | ||
|
||
## Learn more | ||
|
||
* Official website: https://www.phoenixframework.org/ | ||
* Guides: https://hexdocs.pm/phoenix/overview.html | ||
* Docs: https://hexdocs.pm/phoenix | ||
* Forum: https://elixirforum.com/c/phoenix-forum | ||
* Source: https://github.com/phoenixframework/phoenix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@import "tailwindcss/base"; | ||
@import "tailwindcss/components"; | ||
@import "tailwindcss/utilities"; | ||
|
||
/* This file is for your main application CSS */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// If you want to use Phoenix channels, run `mix help phx.gen.channel` | ||
// to get started and then uncomment the line below. | ||
// import "./user_socket.js" | ||
|
||
// You can include dependencies in two ways. | ||
// | ||
// The simplest option is to put them in assets/vendor and | ||
// import them using relative paths: | ||
// | ||
// import "../vendor/some-package.js" | ||
// | ||
// Alternatively, you can `npm install some-package --prefix assets` and import | ||
// them using a path starting with the package name: | ||
// | ||
// import "some-package" | ||
// | ||
|
||
// Include phoenix_html to handle method=PUT/DELETE in forms and buttons. | ||
import "phoenix_html" | ||
// Establish Phoenix Socket and LiveView configuration. | ||
import {Socket} from "phoenix" | ||
import {LiveSocket} from "phoenix_live_view" | ||
import topbar from "../vendor/topbar" | ||
|
||
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content") | ||
let liveSocket = new LiveSocket("/live", Socket, { | ||
longPollFallbackMs: 2500, | ||
params: {_csrf_token: csrfToken} | ||
}) | ||
|
||
// Show progress bar on live navigation and form submits | ||
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"}) | ||
window.addEventListener("phx:page-loading-start", _info => topbar.show(300)) | ||
window.addEventListener("phx:page-loading-stop", _info => topbar.hide()) | ||
|
||
// connect if there are any LiveViews on the page | ||
liveSocket.connect() | ||
|
||
// expose liveSocket on window for web console debug logs and latency simulation: | ||
// >> liveSocket.enableDebug() | ||
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session | ||
// >> liveSocket.disableLatencySim() | ||
window.liveSocket = liveSocket | ||
|
Oops, something went wrong.