diff --git a/.envrc b/.envrc index acf457f48b..fd36862f57 100644 --- a/.envrc +++ b/.envrc @@ -1,9 +1,18 @@ +# Required for op to know which account to use +export OP_ACCOUNT=changelog.1password.com + # Required for image publishing to work locally -export GITHUB_REPOSITORY="thechangelog/changelog.com" -export GITHUB_REF_NAME="master" +export GITHUB_REPOSITORY=thechangelog/changelog.com +export GITHUB_REF_NAME=master export IMAGE_OWNER=thechangelog export GHCR_USERNAME=$USER +# Required for Postgres imports to work locally +export PKG_CONFIG_PATH=$PKG_CONFIG_PATH +export PGUSER=postgres +export DB_USER=$PGUSER +export CHANGELOG_DEV_DB=changelog_dev + # Load secrets if configured - only available to changelog.com team members: # https://github.com/orgs/thechangelog/people source_env_if_exists .envrc.secrets diff --git a/changelog/.tool-versions b/changelog/.tool-versions deleted file mode 100644 index b2b57987c7..0000000000 --- a/changelog/.tool-versions +++ /dev/null @@ -1 +0,0 @@ -dagger 0.10.3 diff --git a/changelog/README.md b/changelog/README.md deleted file mode 100644 index aded8fab20..0000000000 --- a/changelog/README.md +++ /dev/null @@ -1,32 +0,0 @@ -This is a collection of functions that makes it easy to work with the app. - -These are currently intended for changelog.com core devs. In the future, we may -expand the scope to contributors too. - -## Pre-requisities - -- [Dagger v0.10.3](https://docs.dagger.io/install/) -- A container runtime - [Docker](https://docs.docker.com/engine/install/) is the most straightforward one - - If you have a [Fly.io Wireguard - Tunnel](https://fly.io/docs/networking/private-networking/) running, then - running `source envrc` will take care of this - -## What functions are available? - -> [!TIP] -> Run `dagger functions` to see what is available. - -### How can I connect my dev app to a fork of the production db? - -1. Ensure that you have a [Neon.tech API Key](https://neon.tech/docs/manage/api-keys) -2. Set the `NEON_API_KEY` environment variable value to your Neon.tech API Key -3. Run the following command: `dagger call db-branch --neon-api-key=env:NEON_API_KEY` - - ๐Ÿ’ก If you want to set a specific branch name, use the `--branch` flag -4. Follow the instructions in the command output (sets a few environment variables) -5. Start the app how you normally would (e.g. `mix phx.server`) - -## What functions are we missing? - -If there is a function that you are missing, [open a new GitHub -issue](https://github.com/thechangelog/changelog.com/issues/new) & cc -`@gerhard`. diff --git a/changelog/dagger.json b/changelog/dagger.json deleted file mode 100644 index 2f4cecdcaf..0000000000 --- a/changelog/dagger.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "changelog", - "sdk": "go", - "source": "dagger", - "engineVersion": "v0.10.3" -} diff --git a/changelog/dagger/.gitattributes b/changelog/dagger/.gitattributes deleted file mode 100644 index 6911ed2774..0000000000 --- a/changelog/dagger/.gitattributes +++ /dev/null @@ -1,3 +0,0 @@ -/dagger.gen.go linguist-generated -/internal/dagger/** linguist-generated -/internal/querybuilder/** linguist-generated diff --git a/changelog/dagger/.gitignore b/changelog/dagger/.gitignore deleted file mode 100644 index 26b5515eb9..0000000000 --- a/changelog/dagger/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/dagger.gen.go -/internal/dagger -/internal/querybuilder diff --git a/changelog/dagger/go.mod b/changelog/dagger/go.mod deleted file mode 100644 index 7a0f579229..0000000000 --- a/changelog/dagger/go.mod +++ /dev/null @@ -1,16 +0,0 @@ -module dagger/changelog - -go 1.21 - -require ( - github.com/99designs/gqlgen v0.17.31 - github.com/Khan/genqlient v0.6.0 - github.com/vektah/gqlparser/v2 v2.5.6 - golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa - golang.org/x/sync v0.6.0 -) - -require ( - github.com/kislerdm/neon-sdk-go v0.4.8 // indirect - github.com/stretchr/testify v1.9.0 // indirect -) diff --git a/changelog/dagger/go.sum b/changelog/dagger/go.sum deleted file mode 100644 index 2cf63c8e24..0000000000 --- a/changelog/dagger/go.sum +++ /dev/null @@ -1,37 +0,0 @@ -github.com/99designs/gqlgen v0.17.31 h1:VncSQ82VxieHkea8tz11p7h/zSbvHSxSDZfywqWt158= -github.com/99designs/gqlgen v0.17.31/go.mod h1:i4rEatMrzzu6RXaHydq1nmEPZkb3bKQsnxNRHS4DQB4= -github.com/Khan/genqlient v0.6.0 h1:Bwb1170ekuNIVIwTJEqvO8y7RxBxXu639VJOkKSrwAk= -github.com/Khan/genqlient v0.6.0/go.mod h1:rvChwWVTqXhiapdhLDV4bp9tz/Xvtewwkon4DpWWCRM= -github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo= -github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= -github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= -github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= -github.com/kislerdm/neon-sdk-go v0.4.8 h1:9O7dAFY3ZZruq1QnXqRBpc7wOT57jhr84m4ia4GcqY4= -github.com/kislerdm/neon-sdk-go v0.4.8/go.mod h1:WSwEZ7oeR5KfQoCuDh/04LZxnSKDcvfsZyfG/QicDb8= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= -github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/vektah/gqlparser/v2 v2.5.6 h1:Ou14T0N1s191eRMZ1gARVqohcbe1e8FrcONScsq8cRU= -github.com/vektah/gqlparser/v2 v2.5.6/go.mod h1:z8xXUff237NntSuH8mLFijZ+1tjV1swDbpDqjJmk6ME= -golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ= -golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/changelog/dagger/main.go b/changelog/dagger/main.go deleted file mode 100644 index 08592db5f1..0000000000 --- a/changelog/dagger/main.go +++ /dev/null @@ -1,99 +0,0 @@ -package main - -import ( - "context" - "fmt" - "time" - - neon "github.com/kislerdm/neon-sdk-go" -) - -type Changelog struct { - // +private - Verbose bool -} - -func New( - // +optional - // Adds more detail to the output, recommended in combination with --progress=plain - verbose string, -) *Changelog { - module := &Changelog{} - if verbose != "" { - module.Verbose = true - } - return module -} - -// Create a db branch on Neon.tech and return the connection string -// -// Example usage: dagger call db-branch --neon-api-key=env:NEON_API_KEY [--branch=BRANCH-NAME] -func (c *Changelog) DbBranch( - ctx context.Context, - // See https://neon.tech/docs/manage/api-keys - neonApiKey *Secret, - //+optional - // Project name, defaults to orange-sound-86604986 - project string, - //+optional - // Branch name, defaults to dev-YYYY-MM-DD - branch string, -) (string, error) { - if project == "" { - project = "orange-sound-86604986" - } - - if branch == "" { - branch = fmt.Sprintf("dev-%s", time.Now().Format("2006-01-02")) - } - - apiKey, err := neonApiKey.Plaintext(ctx) - if err != nil { - return "", err - } - - n, err := neon.NewClient(neon.Config{Key: apiKey}) - minComputeUnit := neon.ComputeUnit(1.0) - maxComputeUnit := neon.ComputeUnit(2.0) - createdBranch, err := n.CreateProjectBranch(project, &neon.BranchCreateRequest{ - Branch: &neon.BranchCreateRequestBranch{ - Name: &branch, - }, - Endpoints: &[]neon.BranchCreateRequestEndpointOptions{ - { - AutoscalingLimitMinCu: &minComputeUnit, - AutoscalingLimitMaxCu: &maxComputeUnit, - Type: neon.EndpointType("read_write"), - }, - }, - }) - if err != nil { - return "", err - } - - if c.Verbose { - fmt.Printf("CREATED_BRANCH: %+v\n", createdBranch) - } - - db := "changelog" - host := createdBranch.EndpointsResponse.Endpoints[0].Host - role := "changelog-2023-12-09" - rolePassword, err := n.GetProjectBranchRolePassword(project, createdBranch.Branch.ID, role) - if err != nil { - return "", err - } - - if c.Verbose { - fmt.Printf("PASS: %+v\n", rolePassword) - } - - appEnv := fmt.Sprintf(` -Before starting the app, run the following in order to use the new db branch: - -export DB_NAME='%s' -export DB_HOST='%s' -export DB_USER='%s' -export DB_PASS='%s'`, db, host, role, rolePassword.Password) - - return appEnv, nil -} diff --git a/changelog/envrc b/changelog/envrc deleted file mode 100644 index c8f1b4b9dd..0000000000 --- a/changelog/envrc +++ /dev/null @@ -1 +0,0 @@ -export _EXPERIMENTAL_DAGGER_RUNNER_HOST=tcp://dagger-engine-2024-03-28.internal:8080 diff --git a/envrc.secrets.op b/envrc.secrets.op index 435e0ea34f..1b330fee47 100644 --- a/envrc.secrets.op +++ b/envrc.secrets.op @@ -1,3 +1,4 @@ +# Required for Oban Pro to work locally export OBAN_KEY_FINGERPRINT="op://changelog/oban/key_fingerprint" export OBAN_LICENSE_KEY="op://changelog/oban/license_key" @@ -7,7 +8,10 @@ export FLY_API_TOKEN="$(flyctl auth token)" # Required for image publishing to work locally export GHCR_PASSWORD="op://changelog/ghcr/credential" -# Required for db sync to work locally +# Required for loading prod db data into the local dev database export DB_PROD_HOST="op://changelog/neon/server" export DB_PROD_USERNAME="op://changelog/neon/username" export DB_PROD_DBNAME="op://changelog/neon/database" + +# Required to branch production db +export NEON_PROJECT_ID="op://changelog/neon/project" diff --git a/fly.io/dagger-engine-2024-03-28/README.md b/fly.io/dagger-engine-2024-03-28/README.md deleted file mode 100644 index d5ceeaf366..0000000000 --- a/fly.io/dagger-engine-2024-03-28/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# Dagger Engine v0.10 on Fly.io - -## Deploy - -Follow these steps to deploy two Dagger Engines on Fly.io in `ord Chicago, -Illinois (US)`: - -1. Create the `fly.toml` -2. `flyctl apps create dagger-engine-2024-03-28 --org changelog` -3. `flyctl volumes create dagger_engine_2024_03_28 --size 100 --region ord` -4. `flyctl deploy --vm-size performance-2x --region ord` - -## Connect - -> [!NOTE] -> Skip if you already have a WireGuard Tunnel configured. - -Now connect to this Dagger Engine running on Fly.io: - -1. Create a Wireguard peer: `flyctl wireguard create changelog lhr gerhard-2024-03-27` -2. Save it to e.g. `~/Desktop/fly.io-changelog-lhr-gerhard-2024-03-27.conf` -3. **Import Tunnel(s) from File...** it in WireGuard - [install](https://www.wireguard.com/install/) if needed -4. Activate new Tunnel -5. Connect to this Dagger Engine via: -```console -export _EXPERIMENTAL_DAGGER_RUNNER_HOST=tcp://dagger-engine-2024-03-28.internal:8080 -`````` - -## Delete - -`flyctl machine stop --select` stops the machine. ๐Ÿ’ก There is a `restart` command. - -`flyctl machine destroy --select` deletes the machine. ๐Ÿ’ก As long as the volume -is not deleted, `flyctl deploy` will restore the machine with the same state. - -Delete the volume: `flyctl volume list` && `flyctl volume destroy `. -๐Ÿ’ก Even if all data gets wiped, it just means that subsequent builds will be -**slower**. After the first run, the build cache will get populated & -everything will continue being just as fast as when we had data on this volume. diff --git a/fly.io/dagger-engine-2024-03-28/fly.toml b/fly.io/dagger-engine-2024-03-28/fly.toml deleted file mode 100644 index f7388418bd..0000000000 --- a/fly.io/dagger-engine-2024-03-28/fly.toml +++ /dev/null @@ -1,25 +0,0 @@ -# https://fly.io/docs/reference/configuration/ - -app = "dagger-engine-2024-03-28" -primary_region = "ord" - -kill_signal = "SIGINT" -kill_timeout = 30 - -[build] - image = "registry.dagger.io/engine:v0.10.3" - -[mounts] - source = "dagger_engine_2024_03_28" - destination = "/var/lib/dagger" - -[processes] - dagger = "--addr unix:///var/run/buildkit/buildkitd.sock --addr tcp://0.0.0.0:8080" - -[checks] - [checks.grpc] - grace_period = "3s" - interval = "2s" - port = 8080 - timeout = "1s" - type = "tcp" diff --git a/justfile b/justfile index 00d8d00323..ce2e5eb7b3 100644 --- a/justfile +++ b/justfile @@ -11,9 +11,9 @@ fmt: [private] brew: @which brew >/dev/null \ - || (echo {{ GREEN }}๐Ÿบ Installing Homebrew...{{ RESET }} \ + || (echo {{ _MAGENTA }}๐Ÿบ Installing Homebrew...{{ _RESET }} \ && NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" \ - && echo {{ REDB }}{{ WHITE }} ๐Ÿ‘† You must follow NEXT STEPS above before continuing ๐Ÿ‘† {{ RESET }}) + && echo {{ _REDB }}{{ _WHITE }} ๐Ÿ‘† You must follow NEXT STEPS above before continuing ๐Ÿ‘† {{ _RESET }}) [private] brew-linux-shell: @@ -33,8 +33,6 @@ imagemagick: brew @[ -d $(brew --prefix)/opt/imagemagick ] \ || brew install imagemagick -export OP_ACCOUNT := "changelog.1password.com" - # Create .envrc.secrets with credentials from 1Password [group('team')] envrc-secrets: @@ -47,7 +45,7 @@ gpg: brew [private] icu4c: brew - @brew --prefix icu4c 1> /dev/null 2>&1 \ + @[ -d "$(brew --prefix icu4c)/lib/pkgconfig" ] \ || brew install icu4c pkg-config # https://tldp.org/LDP/abs/html/exitcodes.html @@ -55,7 +53,7 @@ icu4c: brew asdf: @which asdf >/dev/null \ || (brew install asdf \ - && echo {{ REDB }}{{ WHITE }} ๐Ÿ‘† You must follow CAVEATS above before continuing ๐Ÿ‘† {{ RESET }}) + && echo {{ _REDB }}{{ _WHITE }} ๐Ÿ‘† You must follow CAVEATS above before continuing ๐Ÿ‘† {{ _RESET }}) [private] asdf-shell: brew @@ -69,16 +67,16 @@ install: asdf brew imagemagick gpg icu4c export ELIXIR_ERL_OPTIONS := if os() == "linux" { "+fnu" } else { "" } -# Add Oban Pro repository +# Add Oban Pro hex repository [group('team')] -add-oban-pro-repo: +add-oban-pro-hex-repo: [ -n "$OBAN_LICENSE_KEY" ] \ && [ -n "$OBAN_KEY_FINGERPRINT" ] \ && mix hex.repo add oban https://getoban.pro/repo --fetch-public-key $OBAN_KEY_FINGERPRINT --auth-key $OBAN_LICENSE_KEY # Get app dependencies [group('contributor')] -deps: add-oban-pro-repo +deps: add-oban-pro-hex-repo mix local.hex --force mix deps.get --only dev mix deps.get --only test @@ -86,7 +84,7 @@ deps: add-oban-pro-repo [private] pg_ctl: @which pg_ctl >/dev/null \ - || (echo "{{ REDB }}{{ WHITE }}Postgres is not installed.{{ RESET }} To fix this, run: {{ GREENB }}{{ WHITE }}just install{{ RESET }}" && exit 127) + || (echo "{{ _REDB }}{{ _WHITE }}Postgres is not installed.{{ _RESET }} To fix this, run: {{ _GREENB }}just install{{ _RESET }}" && exit 127) # Start Postgres server [group('contributor')] @@ -103,32 +101,82 @@ postgres-db db: @(psql --list --quiet --tuples-only | grep -q {{ db }}) \ || createdb {{ db }} -export PGUSER := "postgres" -export DB_USER := PGUSER - # Delete & replace changelog_dev with a prod db dump [confirm("This DELETEs and REPLACEs changelog_dev with the prod db dump. Are you sure that you want to continue?")] [group('team')] restore-dev-db-from-prod format="c": changelog_dev - @echo "\n{{ GREEN }}๐Ÿ›ฌ Dumping prod db...{{ RESET }}" + @echo "\n{{ _MAGENTA }}๐Ÿ›ฌ Dumping prod db...{{ _RESET }}" [ -f $DB_PROD_DBNAME.{{ format }}.sql ] \ || time PGSSLMODE=require PGPASSWORD=$(op read op://changelog/neon/password) pg_dump \ --format={{ format }} --verbose \ --host=$DB_PROD_HOST \ --username=$DB_PROD_USERNAME \ --dbname=$DB_PROD_DBNAME > $DB_PROD_DBNAME.{{ format }}.sql - @echo "\n{{ GREEN }}๐Ÿ›ซ Recreating {{ CHANGELOG_DEV_DB }} from prod dump{{ RESET }}..." - dropdb {{ CHANGELOG_DEV_DB }} - createdb {{ CHANGELOG_DEV_DB }} + @echo "\n{{ _MAGENTA }}๐Ÿ›ซ Recreating {{ _CHANGELOG_DEV_DB }} from prod dump...{{ _RESET }}" + dropdb {{ _CHANGELOG_DEV_DB }} + createdb {{ _CHANGELOG_DEV_DB }} time pg_restore \ --format=c --verbose \ - --dbname={{ CHANGELOG_DEV_DB }} \ + --dbname={{ _CHANGELOG_DEV_DB }} \ --exit-on-error \ --no-owner \ --no-privileges < $DB_PROD_DBNAME.{{ format }}.sql - @echo "\n{{ GREEN }}โšก๏ธ Warm up the query planner...{{ RESET }} https://www.postgresql.org/docs/current/sql-analyze.html..." - time psql --dbname={{ CHANGELOG_DEV_DB }} --command "ANALYZE VERBOSE;" + @echo "\n{{ _MAGENTA }}โšก๏ธ Warm up the query planner...{{ _RESET }} https://www.postgresql.org/docs/current/sql-analyze.html" + time psql --dbname={{ _CHANGELOG_DEV_DB }} --command "ANALYZE VERBOSE;" + +[private] +neon *ARGS: npm + @which neonctl >/dev/null \ + || (echo {{ _MAGENTA }}๐Ÿงช Installing neonctl...{{ _RESET }} \ + && npm install -g neonctl && echo {{ _MAGENTA }}neonctl{{ _RESET }} && neonctl --version) + {{ if ARGS != "" { "neonctl " + ARGS } else { "neonctl" } }} + +[private] +npm: + @which npm >/dev/null \ + || (echo "{{ _REDB }}{{ _WHITE }}NPM is not installed.{{ _RESET }} To fix this, run: {{ _GREENB }}just install{{ _RESET }}" && exit 127) + +_NEON_DB_BRANCH := env_var("USER") + "-" + datetime("%Y-%m-%d") +# Create a new branch off the prod db +[group('team')] +neon-create-branch: + @echo "\n{{ _MAGENTA }}๐Ÿ”’ Checking Neon auth...{{ _RESET }}" + just neon projects get $NEON_PROJECT_ID || just neon auth + + @echo "\n{{ _MAGENTA }}๐ŸŒฒ Creating Neon prod db branch...{{ _RESET }}" + just neon branches get --project-id=$NEON_PROJECT_ID {{ _NEON_DB_BRANCH }} \ + || just neon branches create --project-id=$NEON_PROJECT_ID --name={{ _NEON_DB_BRANCH }} + + @echo "\n{{ _MAGENTA }}โšก๏ธ Warm up the query planner...{{ _RESET }} https://www.postgresql.org/docs/current/sql-analyze.html" + time psql "$(just neon-branch-connection-string {{ _NEON_DB_BRANCH }})" --command "ANALYZE VERBOSE;" + + @echo "\n{{ _MAGENTA }}๐Ÿ’ก To use this Neon db branch in with your local dev app, run: {{ _RESET }}{{ _GREENB }}just dev-with-neon-branch {{ _NEON_DB_BRANCH }}{{ _RESET }}" + +# Show $branch connection details +[group('team')] +neon-branch-connection branch *ARGS: + @just neon connection-string {{ branch }} --project-id=$NEON_PROJECT_ID \ + --role-name=$DB_PROD_USERNAME --database-name=$DB_PROD_DBNAME --extended --output=yaml {{ ARGS }} + +[private] +neon-branch-connection-string branch: + @just neon-branch-connection {{ branch }} \ + | awk '/connection_string:/ { print $2 }' + +# List prod db branches +[group('team')] +neon-branches: (neon "branches list --project-id=$NEON_PROJECT_ID") + +[private] +neon-connection-convert-to-env: + #!/usr/bin/env bash + awk ' + /^host:/ {gsub(/^host: /, ""); print "export DB_HOST=" $0} + /^role:/ {gsub(/^role: /, ""); print "export DB_USER=" $0} + /^password:/ {gsub(/^password: /, ""); print "export DB_PASS=" $0} + /^database:/ {gsub(/^database: /, ""); print "export DB_NAME=" $0} + ' [private] changelog_test: postgres-up (postgres-db "changelog_test") @@ -138,15 +186,16 @@ changelog_test: postgres-up (postgres-db "changelog_test") test: changelog_test mix test -CHANGELOG_DEV_DB := "changelog_dev" +_CHANGELOG_DEV_DB := env_var("CHANGELOG_DEV_DB") + [private] -changelog_dev: postgres-up (postgres-db CHANGELOG_DEV_DB) +changelog_dev: postgres-up (postgres-db _CHANGELOG_DEV_DB) mix ecto.setup [private] yarn: @which yarn >/dev/null \ - || (echo "{{ REDB }}{{ WHITE }}Yarn is not installed.{{ RESET }} To fix this, run: {{ GREENB }}{{ WHITE }}just install{{ RESET }}" && exit 127) + || (echo "{{ _REDB }}{{ _WHITE }}Yarn is not installed.{{ _RESET }} To fix this, run: {{ _GREENB }}just install{{ _RESET }}" && exit 127) [private] assets: yarn @@ -157,6 +206,14 @@ assets: yarn dev: changelog_dev assets mix phx.server +# Run app in dev mode with $branch +[group('team')] +dev-with-neon-branch branch: assets + #!/usr/bin/env bash + eval "$(just neon-branch-connection {{ branch }} \ + | just neon-connection-convert-to-env)" + mix phx.server + # Setup everything needed for your first contribution [group('contributor')] contribute: install @@ -198,24 +255,24 @@ tag-kaizen version episode discussion commit: # https://linux.101hacks.com/ps1-examples/prompt-color-using-tput/ -BOLD := "$(tput bold)" -RESET := "$(tput sgr0)" -BLACK := "$(tput bold)$(tput setaf 0)" -RED := "$(tput bold)$(tput setaf 1)" -GREEN := "$(tput bold)$(tput setaf 2)" -YELLOW := "$(tput bold)$(tput setaf 3)" -BLUE := "$(tput bold)$(tput setaf 4)" -MAGENTA := "$(tput bold)$(tput setaf 5)" -CYAN := "$(tput bold)$(tput setaf 6)" -WHITE := "$(tput bold)$(tput setaf 7)" -BLACKB := "$(tput bold)$(tput setab 0)" -REDB := "$(tput setab 1)$(tput setaf 0)" -GREENB := "$(tput setab 2)$(tput setaf 0)" -YELLOWB := "$(tput setab 3)$(tput setaf 0)" -BLUEB := "$(tput setab 4)$(tput setaf 0)" -MAGENTAB := "$(tput setab 5)$(tput setaf 0)" -CYANB := "$(tput setab 6)$(tput setaf 0)" -WHITEB := "$(tput setab 7)$(tput setaf 0)" +_BOLD := "$(tput bold)" +_RESET := "$(tput sgr0)" +_BLACK := "$(tput bold)$(tput setaf 0)" +_RED := "$(tput bold)$(tput setaf 1)" +_GREEN := "$(tput bold)$(tput setaf 2)" +_YELLOW := "$(tput bold)$(tput setaf 3)" +_BLUE := "$(tput bold)$(tput setaf 4)" +_MAGENTA := "$(tput bold)$(tput setaf 5)" +_CYAN := "$(tput bold)$(tput setaf 6)" +_WHITE := "$(tput bold)$(tput setaf 7)" +_BLACKB := "$(tput bold)$(tput setab 0)" +_REDB := "$(tput setab 1)$(tput setaf 0)" +_GREENB := "$(tput setab 2)$(tput setaf 0)" +_YELLOWB := "$(tput setab 3)$(tput setaf 0)" +_BLUEB := "$(tput setab 4)$(tput setaf 0)" +_MAGENTAB := "$(tput setab 5)$(tput setaf 0)" +_CYANB := "$(tput setab 6)$(tput setaf 0)" +_WHITEB := "$(tput setab 7)$(tput setaf 0)" # just actions-runner # DEBIAN_FRONTEND=noninteractive sudo apt install -y curl