Skip to content

Commit

Permalink
feat: por from supabase-potion
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedsoupe committed Jan 13, 2024
0 parents commit 8525cd4
Show file tree
Hide file tree
Showing 67 changed files with 4,710 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .earthlyignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Ignore git, but keep git HEAD and refs to access current commit hash if needed
.git
!.git/HEAD
!.git/refs
.github

.elixir_ls
.vscode

# 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
/apps/plataforma_digital/assets/node_modules/
/apps/plataforma_digital/priv/static/assets/
/apps/plataforma_digital/priv/static/cache_manifest.json

# Nix artifacts
/.postgres/
/.direnv/
/.nix-*/
result

40 changes: 40 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export GPG_TTY="$(tty)"

# this allows mix to work on the local directory
export MIX_HOME=$PWD/.nix-mix
export HEX_HOME=$PWD/.nix-mix
export PATH=$MIX_HOME/bin:$HEX_HOME/bin:$PATH
export ERL_AFLAGS="-kernel shell_history enabled"

export LANG=en_US.UTF-8

use flake

# Setup postgresql
if test -d "/Applications/Postgres.app"; then
export DATABASE_USER="$(whoami)"
export DATABASE_PASSWORD=""
else
# postges related
export DATABASE_USER="supabase_potion"
export DATABASE_PASSWORD="supabase_potion"
export PG_DATABASE="supabase_potion_dev"
# keep all your db data in a folder inside the project
export PGHOST="$PWD/.postgres"
export PGDATA="$PGHOST/data"
export PGLOG="$PGHOST/server.log"

if [[ ! -d "$PGDATA" ]]; then
# initital set up of database server
initdb --auth=trust --no-locale --encoding=UTF8 -U=$DATABASE_USER >/dev/null

# point to correct unix sockets
echo "unix_socket_directories = '$PGHOST'" >> "$PGDATA/postgresql.conf"
# creates loacl database user
echo "CREATE USER $DATABASE_USER SUPERUSER;" | postgres --single -E postgres
# creates local databse
echo "CREATE DATABASE $PG_DATABASE;" | postgres --single -E postgres
fi
fi

source .env
5 changes: 5 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Used by "mix format"
[
inputs: ["mix.exs", "config/*.exs"],
subdirectories: ["apps/*"]
]
11 changes: 11 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Problem

<!-- what problem is the PR is trying to solve? -->

## Solution

<!-- how is the PR solving the problem? -->

## Rationale

<!-- why was it implemented the way it was? -->
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: ci

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

jobs:
build:
runs-on: ubuntu-latest
env:
GHCR_USERNAME: ${{ github.actor }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
FORCE_COLOR: 1
steps:
- uses: actions/checkout@v3
- name: Put back the git branch into git (Earthly uses it for tagging)
run: |
branch=""
if [ -n "$GITHUB_HEAD_REF" ]; then
branch="$GITHUB_HEAD_REF"
else
branch="${GITHUB_REF##*/}"
fi
git checkout -b "$branch" || true
- name: Docker Login
run: docker login https://ghcr.io --username "$GHCR_USERNAME" --password "$GHCR_TOKEN"
- name: Download latest earthly
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"

- name: Earthly version
run: earthly --version

- name: Run CI
run: earthly -P +ci

- name: Run Tests
run: earthly -P +test
30 changes: 30 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: release

on:
push:
tags:
- '*'

env:
MIX_ENV: prod

jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
elixir: [1.15.7]
otp: [26.1.2]
steps:
- uses: actions/checkout@v3
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- name: Publish to Hex
uses: synchronal/hex-publish-action@v3
with:
name: supabase_potion
key: ${{ secrets.HEX_PM_KEY }}
tag-release: true
40 changes: 40 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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 third-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/

# Nix files
/.nix-mix/
/.postgres/
result

# Secrets files
.env

# LSP files
/.lexical/

# Nix files
result

/.elixir_ls/
/.elixir-tools/
33 changes: 33 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
VERSION 0.7

ARG MIX_ENV=test

deps:
ARG ELIXIR=1.15.7
ARG OTP=26.1.2
FROM hexpm/elixir:${ELIXIR}-erlang-${OTP}-alpine-3.17.5
RUN apk add --no-cache build-base
WORKDIR /src
RUN mix local.rebar --force
RUN mix local.hex --force
COPY mix.exs mix.lock ./
COPY --dir lib . # check .earthlyignore
RUN mix deps.get
RUN mix deps.compile --force
RUN mix compile
SAVE ARTIFACT /src/_build AS LOCAL _build
SAVE ARTIFACT /src/deps AS LOCAL deps

ci:
FROM +deps
COPY .formatter.exs .
RUN mix clean
RUN mix compile --warning-as-errors
RUN mix format --check-formatted
RUN mix credo --strict

test:
FROM +deps
COPY mix.exs mix.lock ./
COPY --dir lib ./
RUN mix test
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

Copyright (C) 2023 Zoey Pessanha <[email protected]>

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Supabase Auth (GoTrue)
7 changes: 7 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Config

if config_env() == :dev do
config :supabase_potion,
supabase_base_url: System.get_env("SUPABASE_URL"),
supabase_api_key: System.get_env("SUPABASE_KEY")
end
25 changes: 25 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
description = "A complete Supabase SDK for Elixir alchemists";

outputs = {nixpkgs, ...}: let
for-all-systems = function:
nixpkgs.lib.genAttrs [
"x86_64-linux"
"aarch64-darwin"
] (system:
function rec {
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs.beam.interpreters) erlang_26;
inherit (pkgs.beam) packagesWith;
beam-pkgs = packagesWith erlang_26;
deps = import ./nix/deps.nix {
inherit (pkgs) lib;
beamPackages = beam-pkgs;
};
});
in {
devShells = for-all-systems ({
pkgs,
beam-pkgs,
...
}: rec {
default = supabase-potion;
supabase-potion = pkgs.mkShell {
name = "supabase-potion";
shellHook = "mkdir -p $PWD/.nix-mix";
packages = with pkgs;
[beam-pkgs.elixir_1_15 earthly]
++ lib.optional stdenv.isDarwin [
darwin.apple_sdk.frameworks.CoreServices
darwin.apple_sdk.frameworks.CoreFoundation
];
};
});
};
}
Loading

0 comments on commit 8525cd4

Please sign in to comment.