Skip to content

Commit

Permalink
Bring over elixir from remote.
Browse files Browse the repository at this point in the history
  • Loading branch information
callmeclover committed Mar 15, 2024
1 parent 6ceaf5f commit da1859a
Show file tree
Hide file tree
Showing 66 changed files with 3,133 additions and 269 deletions.
40 changes: 40 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# flyctl launch added from .elixir_ls/.gitignore
.elixir_ls/**/*

# flyctl launch added from .gitignore
# 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

# Ignore package tarball (built via "mix hex.build").
**/chat-*.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

**/.vscode
**/.env
6 changes: 6 additions & 0 deletions .formatter.exs
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"]
]
24 changes: 24 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: 2
updates:
- package-ecosystem: mix
directory: "/"
schedule:
interval: weekly
time: "17:00"
timezone: Europe/London
ignore:
# ignore all patch updates in dev dependencies ref: github.com/dwyl/technology-stack/issues/126 [alphabetical list]
- dependency-name: "credo"
update-types: ["version-update:semver-patch"]
- dependency-name: "dialyxir"
update-types: ["version-update:semver-patch"]
- dependency-name: "excoveralls"
update-types: ["version-update:semver-patch"]
- dependency-name: "ex_doc"
update-types: ["version-update:semver-patch"]
- dependency-name: "esbuild"
update-types: ["version-update:semver-patch"]
- dependency-name: "floki"
update-types: ["version-update:semver-patch"]
- dependency-name: "phoenix_live_reload"
update-types: ["version-update:semver-patch"]
62 changes: 62 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Elixir CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
name: Build and test
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12
ports: ['5432:5432']
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: '1.14.2' # Define the elixir version [required]
otp-version: '25.1.2' # Define the OTP version [required]
- name: Restore dependencies cache
uses: actions/cache@v2
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Install dependencies
run: mix deps.get
- name: Run Tests
run: mix coveralls.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MIX_ENV: test
AUTH_API_KEY: ${{ secrets.AUTH_API_KEY }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1

# Continuous Deployment to Fly.io
# https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/
deploy:
name: Deploy app
runs-on: ubuntu-latest
needs: build
# https://stackoverflow.com/questions/58139406/only-run-job-on-specific-branch-with-github-actions
if: github.ref == 'refs/heads/main'
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
steps:
- uses: actions/checkout@v2
- uses: superfly/[email protected]
with:
args: "deploy"
42 changes: 40 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
node_modules
tmp
# 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

# Ignore package tarball (built via "mix hex.build").
chat-*.tar

# Ignore assets that are produced by build tools.
/priv/static/assets/
/priv/static

# 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/

.vscode/
.env
.DS_Store

.elixir_ls
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "bartender"]
path = bartender
url = https://github.com/stalepretzels/bartender
99 changes: 89 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,95 @@
# Use the official Node.js image as the base image
FROM node:20.5.1
# 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-20220801-slim - for the release image
# - https://pkgs.org/ - resource for finding needed packages
# - Ex: hexpm/elixir:1.14.1-erlang-25.1.1-debian-bullseye-20220801-slim
#
ARG ELIXIR_VERSION=1.14.1
ARG OTP_VERSION=25.1.1
ARG DEBIAN_VERSION=bullseye-20220801-slim

# Set the working directory in the container
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

# Copy the application files into the working directory
COPY . /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 \
&& 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"

# Install the application dependencies
RUN yarn install
# Only copy the final release from the build stage
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/chat ./

EXPOSE 8443/tcp
USER nobody

# Define the entry point for the container
CMD ["node", "index.js"]
CMD ["/app/bin/server"]
# Appended by flyctl
ENV ECTO_IPV6 true
ENV ERL_AFLAGS "-proto_dist inet6_tcp"
Loading

0 comments on commit da1859a

Please sign in to comment.