Skip to content

Commit 2acff02

Browse files
feat: add base Lago API codebase from upstream v1.46.0 (#2)
Integrates the core API codebase from the upstream repository to serve as the foundation for the custom billing system. - Upstream Source: https://github.com/getlago/lago-api/ - Release Tag: v1.46.0 This baseline commit includes the initial application logic
1 parent 1a67987 commit 2acff02

5,749 files changed

Lines changed: 598291 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.annotaterb.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
:position: bottom
3+
:position_in_additional_file_patterns: bottom
4+
:position_in_class: bottom
5+
:position_in_factory: bottom
6+
:position_in_fixture: bottom
7+
:position_in_routes: bottom
8+
:position_in_serializer: bottom
9+
:position_in_test: bottom
10+
:classified_sort: true
11+
:exclude_controllers: true
12+
:exclude_factories: true
13+
:exclude_fixtures: true
14+
:exclude_helpers: true
15+
:exclude_scaffolds: true
16+
:exclude_serializers: true
17+
:exclude_sti_subclasses: false
18+
:exclude_tests: true
19+
:force: false
20+
:format_markdown: false
21+
:format_rdoc: false
22+
:format_yard: false
23+
:frozen: false
24+
:ignore_model_sub_dir: false
25+
:ignore_unknown_models: false
26+
:include_version: false
27+
:show_check_constraints: false
28+
:show_complete_foreign_keys: false
29+
:show_foreign_keys: true
30+
:show_indexes: true
31+
:simple_indexes: false
32+
:sort: false
33+
:timestamp: false
34+
:trace: false
35+
:with_comment: true
36+
:with_column_comments: true
37+
:with_table_comments: true
38+
:active_admin: false
39+
:command:
40+
:debug: false
41+
:hide_default_column_types: "json,jsonb,hstore"
42+
:hide_limit_column_types: "integer,bigint,boolean"
43+
:ignore_columns:
44+
:ignore_routes:
45+
:models: true
46+
:routes: false
47+
:skip_on_db_migrate: false
48+
:target_action: :do_annotations
49+
:wrapper:
50+
:wrapper_close:
51+
:wrapper_open:
52+
:classes_default_to_s: []
53+
:additional_file_patterns: []
54+
:model_dir:
55+
- app/models
56+
:require: []
57+
:root_dir:
58+
- ''

.dockerignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/tmp/*
2+
.rsa_private.pem
3+
.rsa_public.pem
4+
5+
.git
6+
.gitignore
7+
.github
8+
9+
README.md
10+
LICENSE
11+
CODE_OF_CONDUCT.md
12+
CONTRIBUTING.md
13+
SECURITY.md
14+
15+
Dockerfile
16+
Dockerfile.dev

.env.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DATABASE_URL=postgresql://lago:changeme@localhost:5432/lago_test

.git-blame-ignore-revs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Enable TrailingCommaInHashLiteral rubocop rule for all files
2+
3803519f622313a50def9b5261dfce899bdaf12d
3+
f83dbe1f847414c927273523b6cf60f3a881a9f1
4+
747a2feea6530ef298722f464e47855507c21886
5+
15179f005dc0a6f7d61140581e123662535e4e53

.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# See https://git-scm.com/docs/gitattributes for more about git attribute files.
2+
3+
# Mark the database schema as having been generated.
4+
db/schema.rb linguist-generated
5+
schema.json linguist-generated
6+
schema.graphql linguist-generated
7+
8+
# Mark any vendored files as having been vendored.
9+
vendor/* linguist-vendored
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Front compatibility (PR check, informational)
2+
3+
# Runs on PRs targeting main that modify schema.graphql. Regenerates
4+
# lago-front's types from the PR's schema and runs tsc against
5+
# lago-front main. Failure is informational only — the job is marked
6+
# continue-on-error so it never blocks merging. Authors can still see
7+
# a red/green signal in the PR's checks panel and inspect logs when
8+
# something breaks.
9+
#
10+
# Path filter on schema.graphql — most PRs don't change the schema, so
11+
# the workflow rarely runs. Cost: a few minutes of CI per schema change.
12+
13+
on:
14+
pull_request:
15+
branches: [main]
16+
paths: ['schema.graphql']
17+
18+
jobs:
19+
front-typecheck:
20+
name: Front typecheck against PR schema (informational)
21+
runs-on: ubuntu-latest
22+
# Non-blocking: a failure here surfaces in the checks panel but does
23+
# not fail the workflow run, so branch protection cannot gate on it.
24+
continue-on-error: true
25+
26+
steps:
27+
- name: Checkout lago-api (PR head — the new schema)
28+
uses: actions/checkout@v6
29+
with:
30+
ref: ${{ github.event.pull_request.head.sha }}
31+
path: api
32+
33+
- name: Checkout lago-front (main — stable baseline)
34+
uses: actions/checkout@v6
35+
with:
36+
repository: getlago/lago-front
37+
ref: main
38+
path: front
39+
40+
- name: Set up pnpm
41+
uses: pnpm/action-setup@v6
42+
with:
43+
# lago-front declares its pnpm version in `packageManager`.
44+
# Point the action at front's package.json so the version
45+
# tracks whatever lago-front pins, no manual upkeep here.
46+
package_json_file: front/package.json
47+
48+
- name: Set up Node.js
49+
uses: actions/setup-node@v6
50+
with:
51+
# Inherit the version from lago-front's own package.json
52+
# (engines.node) so this workflow tracks any node bump on the
53+
# front side without manual upkeep here.
54+
node-version-file: front/package.json
55+
cache: pnpm
56+
cache-dependency-path: front/pnpm-lock.yaml
57+
58+
- name: Install front dependencies
59+
working-directory: front
60+
run: pnpm install --frozen-lockfile
61+
62+
- name: Build workspace packages (prebuild)
63+
working-directory: front
64+
run: pnpm prebuild
65+
66+
- name: Regenerate front types from PR schema
67+
working-directory: front
68+
env:
69+
# graphql-codegen accepts file paths in its `schema:` field.
70+
# codegen.yml reads ${CODEGEN_API}; pointing it at the API
71+
# PR's checked-in schema.graphql skips the API boot step
72+
# entirely — no docker compose, no resolvers, just the schema.
73+
CODEGEN_API: ../api/schema.graphql
74+
run: pnpm codegen
75+
76+
- name: Type-check front
77+
working-directory: front
78+
run: pnpm tsc --noEmit
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: "Internal Build"
2+
on:
3+
push:
4+
branches:
5+
- main
6+
workflow_dispatch:
7+
inputs:
8+
sidekiq_pro:
9+
type: boolean
10+
default: true
11+
description: Enable Sidekiq Pro
12+
permissions: {}
13+
jobs:
14+
build-api-image:
15+
runs-on: ubuntu-latest
16+
name: Build API Image
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Configure AWS Credentials
21+
uses: aws-actions/configure-aws-credentials@v4
22+
with:
23+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
24+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
25+
aws-region: us-east-1
26+
27+
- name: Login to Amazon ECR
28+
id: login-ecr
29+
uses: aws-actions/amazon-ecr-login@v2
30+
31+
- name: Add version into docker image
32+
run: echo ${{ github.sha }} > ./LAGO_VERSION
33+
34+
- name: Docker tag
35+
id: docker_tag
36+
env:
37+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
38+
ECR_REPOSITORY: lago-api-production
39+
IMAGE_TAG: ${{ github.sha }}
40+
run: echo "tag=$(echo $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG)" >> $GITHUB_OUTPUT
41+
42+
- name: Build and push
43+
id: build
44+
uses: docker/build-push-action@v6
45+
with:
46+
context: .
47+
push: true
48+
tags: ${{ steps.docker_tag.outputs.tag }}
49+
build-args: |
50+
BUNDLE_WITH=${{ (github.event_name == 'push' || github.event.inputs.sidekiq_pro == 'true') && 'sidekiq-pro' || '' }}
51+
secrets: |
52+
"BUNDLE_GEMS__CONTRIBSYS__COM=${{ secrets.BUNDLE_GEMS__CONTRIBSYS__COM }}"

.github/workflows/linters.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Linters
2+
on: [pull_request]
3+
permissions: {}
4+
jobs:
5+
linters:
6+
name: Linters
7+
runs-on: ubuntu-latest
8+
if: ${{ github.actor != 'dependabot[bot]' }}
9+
env:
10+
RAILS_ENV: production
11+
RAILS_MASTER_KEY: N+XcWoGDzKjuoxrU8BIPN5D0/GSuqx9s
12+
SECRET_KEY_BASE: cvIAI6ycC0OnVDRAjT5hmbRxnjCxl4YB
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
- name: Setup Ruby
19+
uses: ruby/setup-ruby@v1
20+
with:
21+
ruby-version: "4.0.2"
22+
bundler-cache: true
23+
- name: Setup Rubocop
24+
# A bug requires the use of `bundle install` to use `rubocop-rails`. A fix is coming to Rubocop.
25+
# See: https://github.com/rubocop/rubocop/issues/12823
26+
run: |
27+
bundle install
28+
- name: Run Rubocop
29+
# We must pass the list of files because for now, rubocop on the entire project throws too many errors.
30+
# We exclude the db/schema.rb file explicitly because passing a list of files will override the `AllCops.Exclude` config in .rubocop.yml
31+
run: |
32+
FILES=$(git diff --diff-filter=d --name-only origin/${{ github.base_ref }}...HEAD -- '*.rb' ':!db/*structure.sql')
33+
if [ -z "$FILES" ]; then
34+
echo "No Ruby files to lint"
35+
exit 0
36+
else
37+
echo "Linting Ruby files"
38+
bundle exec rubocop $FILES
39+
fi
40+
- name: Generate RSA keys
41+
run: ./scripts/generate.rsa.sh
42+
- name: Zeitwerk check
43+
run: bin/rails zeitwerk:check
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Run rails migrations
2+
on:
3+
push:
4+
branches:
5+
- "main"
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
permissions: {}
9+
jobs:
10+
run-migrations:
11+
name: Run migrations
12+
runs-on: ubuntu-latest
13+
services:
14+
postgres:
15+
image: getlago/postgres-partman:15.0-alpine
16+
ports:
17+
- "5432:5432"
18+
env:
19+
POSTGRES_DB: lago
20+
POSTGRES_USER: lago
21+
POSTGRES_PASSWORD: lago
22+
env:
23+
RAILS_ENV: test
24+
DATABASE_URL: "postgres://lago:lago@localhost:5432/lago"
25+
RAILS_MASTER_KEY: N+XcWoGDzKjuoxrU8BIPN5D0/GSuqx9s
26+
SECRET_KEY_BASE: cvIAI6ycC0OnVDRAjT5hmbRxnjCxl4YB
27+
ENCRYPTION_PRIMARY_KEY: 5I9mjfzry2P787x4S5ZuDdJwXNgYEwqo
28+
ENCRYPTION_DETERMINISTIC_KEY: SGiZzmh18EjBF9gSW8LCNk7pelauWVr4
29+
ENCRYPTION_KEY_DERIVATION_SALT: q3pkMw34ZkRPFSf2LmtWe705yw532Pf7
30+
LAGO_API_URL: https://api.lago.dev
31+
LAGO_PDF_URL: https://pdf.lago.dev
32+
LAGO_FROM_EMAIL: noreply@getlago.com
33+
LAGO_CLICKHOUSE_ENABLED: true
34+
LAGO_CLICKHOUSE_MIGRATIONS_ENABLED: true
35+
LAGO_CLICKHOUSE_HOST: localhost
36+
LAGO_CLICKHOUSE_DATABASE: default
37+
LAGO_CLICKHOUSE_USERNAME: ""
38+
LAGO_CLICKHOUSE_PASSWORD: "password"
39+
LAGO_DISABLE_SCHEMA_DUMP: true
40+
LAGO_KAFKA_EVENTS_CHARGED_IN_ADVANCE_TOPIC: events_charged_in_advance
41+
ANNOTATE_SKIP_ON_DB_MIGRATE: 1
42+
steps:
43+
- name: Checkout code
44+
uses: actions/checkout@v4
45+
- name: Install Ruby and gems
46+
uses: ruby/setup-ruby@v1
47+
with:
48+
ruby-version: "4.0.2"
49+
bundler-cache: true
50+
- name: Install pg 14
51+
uses: tj-actions/install-postgresql@v3
52+
with:
53+
postgresql-version: "15"
54+
- name: Start Clickhouse database
55+
run: |
56+
docker run -d --rm -p 8123:8123 -p 9000:9000 --ulimit nofile=262144:262144 -v ./clickhouse-s3:/var/lib/clickhouse-s3 -v ./ci/clickhouse/config.xml:/etc/clickhouse-server/config.d/config.xml -e CLICKHOUSE_PASSWORD=password clickhouse/clickhouse-server:25.12-alpine
57+
shell: bash
58+
- name: Generate RSA keys
59+
run: ./scripts/generate.rsa.sh
60+
- run: "pg_dump --version"
61+
- name: Move db schema for comparison
62+
run: mv db/structure.sql db/structure-before-dump.sql
63+
- name: Perform Postgres database migrations
64+
run: bin/rails db:migrate:primary
65+
- name: dump schema
66+
run: LAGO_DISABLE_SCHEMA_DUMP="" bin/rails db:schema:dump:primary
67+
- name: Ensure no changes to structure.sql (excluding restrict/unrestrict)
68+
run: |
69+
grep -v '\\restrict' db/structure.sql | grep -v '\\unrestrict' | grep -v 'Dumped from database version' | grep -v 'Dumped by pg_dump version' | sed '/^[[:space:]]*$/d' > db/structure.sql.filtered
70+
grep -v '\\restrict' db/structure-before-dump.sql | grep -v '\\unrestrict' | grep -v 'Dumped from database version' | grep -v 'Dumped by pg_dump version' | sed '/^[[:space:]]*$/d' > db/structure-before-dump.sql.filtered
71+
diff db/structure.sql.filtered db/structure-before-dump.sql.filtered
72+
- name: Ensure annotations are up to date
73+
run: bundle exec annotaterb --frozen
74+
- name: Perform Clickhouse database migrations
75+
run: bin/rails db:migrate:clickhouse

0 commit comments

Comments
 (0)