Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ erl_crash.dump

.env
.env.docker

local_testing
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ impact_tracker-*.tar

.env
.env.test
.env.docker

local_testing/certs
8 changes: 4 additions & 4 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
erlang 26.0.2
elixir 1.15.4-otp-26
nodejs 18.17.1
k6 0.47.0
erlang 27.3.3
elixir 1.18.3-otp-27
nodejs 22.12.0
k6 0.49.0
18 changes: 9 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
# 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-20230612-slim - for the release image
# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20260518-slim - for the release image
# - https://pkgs.org/ - resource for finding needed packages
# - Ex: hexpm/elixir:1.15.4-erlang-26.0.2-debian-bullseye-20230612-slim
# - Ex: hexpm/elixir:1.18.3-erlang-27.3.3-debian-bullseye-20260518-slim
#
ARG ELIXIR_VERSION=1.15.4
ARG OTP_VERSION=26.0.2
ARG DEBIAN_VERSION=bullseye-20230612-slim
ARG ELIXIR_VERSION=1.18.3
ARG OTP_VERSION=27.3.3
ARG DEBIAN_VERSION=bullseye-20260518-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
FROM ${BUILDER_IMAGE} AS builder

# install build dependencies
RUN apt-get update -y && apt-get install -y build-essential git \
Expand Down Expand Up @@ -70,9 +70,9 @@ RUN apt-get update -y && \
# 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
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8

WORKDIR "/app"
RUN chown nobody /app
Expand Down
44 changes: 33 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
# ImpactTracker

To start your Phoenix server:
## Local Development

* Run `mix setup` to install and setup dependencies
* Start Phoenix endpoint with `mix phx.server` or inside IEx with `iex -S mix phx.server`
You will need an instance of Postgresql that is available locally (either running on your
machine or in a container).

Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
Copy `.env.example` to `.env` and update where necessary. You can then use these env variables as
follows:

Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html).
```bash
env $(cat .env | grep -v '#' | xargs) mix ecto.migrate
env $(cat .env | grep -v '#' | xargs) iex -S mix phx.server
```

## Learn more
### Checking integration with Lightning

* 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
If you are running Lightning locally, you can use the docker compose setup to run IT locally as well.

```bash
# Only needed for the initial setup - generate certs for use by the postgres container
./local_testing/generate_certs.sh
```

```bash
# Start ImpactTracker up - it will listen on port 4001
docker compose -f local_testing/docker-compose.yml up --build -d
```

Configure you local Lightning instance to use http://127.0.0.1:4000 for usage tracking and you will
be able to submit to this instance.

## Running tests

Copy `.env.example` to `.env.test` and update where necessary. You can then use these env variables
as follows:

```bash
env $(cat .env.test | grep -v '#' | xargs) mix test
```
3 changes: 1 addition & 2 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ if config_env() == :prod do
if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: []

config :impact_tracker, ImpactTracker.Repo,
ssl: true,
ssl_opts: [
ssl: [
verify: :verify_none
],
url: database_url,
Expand Down
47 changes: 47 additions & 0 deletions local_testing/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
services:
impact_tracker_postgres:
image: postgres:16.14
environment:
POSTGRES_USER: impact_tracker
POSTGRES_PASSWORD: Secret123
POSTGRES_DB: impact_tracker
volumes:
- ./certs/server.crt:/var/lib/postgresql/server.crt:ro,Z
- ./certs/server.key:/var/lib/postgresql/server.key:ro,Z
- ./certs/ca.crt:/var/lib/postgresql/ca.crt:ro,Z
- pgdata:/var/lib/postgresql/data
entrypoint:
- bash
- -c
- |
cp /var/lib/postgresql/server.key /tmp/server.key && \
chmod 600 /tmp/server.key && \
chown postgres:postgres /tmp/server.key && \
exec docker-entrypoint.sh postgres \
-c 'ssl=on' \
-c 'ssl_cert_file=/var/lib/postgresql/server.crt' \
-c 'ssl_key_file=/tmp/server.key' \
-c 'ssl_ca_file=/var/lib/postgresql/ca.crt' \
ports:
- "127.0.0.1:15432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U impact_tracker -d impact_tracker -h localhost -p 5432"]
interval: 10s
timeout: 5s
retries: 5

impact_tracker:
build: ../
depends_on:
impact_tracker_postgres:
condition: service_healthy
environment:
DATABASE_URL: postgresql://impact_tracker:Secret123@impact_tracker_postgres:5432/impact_tracker
SECRET_KEY_BASE: thisisasecretkeybasedonotuseanywhereimportant
volumes:
- ./certs/ca.crt:/app/priv/ca.cert:ro,Z
ports:
- "127.0.0.1:4001:4000"

volumes:
pgdata:
26 changes: 26 additions & 0 deletions local_testing/generate_certs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -euo pipefail

parent_dir=$( cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P )
CERT_DIR="${parent_dir}/certs"
mkdir -p "$CERT_DIR"

# Fake CA
openssl req -x509 -newkey rsa:4096 -days 3650 -nodes \
-keyout "$CERT_DIR/ca.key" \
-out "$CERT_DIR/ca.crt" \
-subj "/CN=fake-ca-for-postgres"

openssl req -newkey rsa:4096 -nodes \
-keyout "$CERT_DIR/server.key" \
-out "$CERT_DIR/server.csr" \
-subj "/CN=image_tracker_postgres"

openssl x509 -req -days 3650 \
-in "$CERT_DIR/server.csr" \
-CA "$CERT_DIR/ca.crt" \
-CAkey "$CERT_DIR/ca.key" \
-CAcreateserial \
-out "$CERT_DIR/server.crt"

chmod 600 "$CERT_DIR/server.key"
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ defmodule ImpactTracker.MixProject do
{:gettext, "~> 0.20"},
{:jason, "~> 1.2"},
{:mock, "~> 0.3.8", only: [:test]},
{:oban, "~> 2.17"},
{:oban, "~> 2.22.0"},
{:phoenix, "~> 1.7.10"},
{:phoenix_ecto, "~> 4.4"},
{:phoenix_live_dashboard, "~> 0.8.2"},
Expand Down
Loading
Loading