-
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.
- Loading branch information
Showing
8 changed files
with
163 additions
and
32 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 |
---|---|---|
|
@@ -36,3 +36,4 @@ npm-debug.log | |
/assets/node_modules/ | ||
|
||
.env* | ||
.DS_Store |
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
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,46 @@ | ||
ARG ELIXIR_VERSION=1.17.2 | ||
ARG OTP_VERSION=27.0.1 | ||
ARG DEBIAN_VERSION=bookworm-20240722-slim | ||
ARG BUN_VERSION=1.1.21 | ||
|
||
ARG ASSETS_BUILDER_IMAGE="oven/bun:${BUN_VERSION}-slim" | ||
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}" | ||
|
||
################################################################################ | ||
|
||
FROM ${ASSETS_BUILDER_IMAGE} as assets_builder | ||
|
||
WORKDIR /app | ||
|
||
COPY assets assets | ||
RUN cd assets && bun --bun install | ||
|
||
################################################################################ | ||
|
||
FROM ${BUILDER_IMAGE} as builder | ||
|
||
# install build dependencies | ||
RUN apt-get update -y && apt-get install -y build-essential git curl unzip inotify-tools \ | ||
&& 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="dev" | ||
|
||
#! https://elixirforum.com/t/arm64-dockerfile-failing/57317/12 | ||
ENV ERL_FLAGS="+JPperf true" | ||
|
||
# install mix dependencies | ||
COPY mix.exs mix.lock ./ | ||
RUN mix deps.get | ||
|
||
COPY --from=assets_builder /app/assets assets | ||
|
||
CMD ["mix", "phx.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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
volumes: | ||
qwynk_postgres_data: | ||
|
||
networks: | ||
qwynk-nw: | ||
driver: bridge | ||
|
||
services: | ||
web: | ||
container_name: qwynk-web | ||
build: | ||
context: . | ||
dockerfile: dev.Dockerfile | ||
ports: | ||
- "4000:4000" | ||
volumes: | ||
- .:/app | ||
- ./deps:/app/deps | ||
- ./_build:/app/_build | ||
depends_on: | ||
- db | ||
env_file: | ||
- .env | ||
environment: | ||
DATABASE_URL: postgres://user:password@db/qwynk_db | ||
SECRET_KEY_BASE: e9Etkgml4tYuWm2KR90WMKn8PLUGd0RV08FnZ+XFpHcK02PeGIu3E364tkfSU0BR | ||
MIX_ENV: dev | ||
networks: | ||
- qwynk-nw | ||
|
||
db: | ||
image: postgres:16-alpine | ||
volumes: | ||
- qwynk_postgres_data:/var/lib/postgresql/data/ | ||
environment: | ||
- POSTGRES_DB=qwynk_db | ||
- POSTGRES_USER=user | ||
- POSTGRES_PASSWORD=password | ||
networks: | ||
- qwynk-nw | ||
|
||
# redis: | ||
# image: redis:7-alpine | ||
# networks: | ||
# - twizl-nw |
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,5 +1,9 @@ | ||
defmodule Qwynk.Repo do | ||
use Ecto.Repo, | ||
otp_app: :qwynk, | ||
adapter: Ecto.Adapters.Postgres | ||
use AshPostgres.Repo, | ||
otp_app: :qwynk | ||
|
||
# Installs extensions that ash commonly uses | ||
def installed_extensions do | ||
["ash-functions", "uuid-ossp", "citext"] | ||
end | ||
end |
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,11 @@ | ||
defmodule Qwynk.UrlShortener do | ||
use Ash.Domain | ||
|
||
resources do | ||
resource Qwynk.UrlShortener.Urls do | ||
end | ||
|
||
# resource Qwynk.UrlShortener.Analytics do | ||
# end | ||
end | ||
end |
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,41 @@ | ||
defmodule Qwynk.UrlShortener.Urls do | ||
use Ash.Resource, | ||
domain: Qwynk.UrlShortener, | ||
data_layer: AshPostgres.DataLayer | ||
|
||
postgres do | ||
table "urls" | ||
repo Qwynk.Repo | ||
end | ||
|
||
actions do | ||
defaults [:read, :create, :update, :destroy] | ||
|
||
create :shorten do | ||
accept [:original_url] | ||
# change fn changeset -> | ||
# changeset | ||
# |> Ash.Changeset.change([shortened_url: Qwynk.UrlShortener.Generators.Slug.generate()]) | ||
# |> Qwynk.UrlShortener.Services.UrlValidator.sanitize_inputs() | ||
# end | ||
end | ||
|
||
read :get do | ||
argument :shortened_url, :string, allow_nil?: false | ||
get? true | ||
filter expr(shortened_url == ^arg(:shortened_url)) | ||
end | ||
end | ||
|
||
attributes do | ||
uuid_primary_key :id | ||
attribute :original_url, :string do | ||
allow_nil? false | ||
end | ||
attribute :shortened_url, :string do | ||
# generate fn _ -> | ||
# Qwynk.UrlShortener.Generators.Slug.generate() | ||
# end | ||
end | ||
end | ||
end |
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