diff --git a/.env-dist b/.env-dist new file mode 100644 index 0000000..948b856 --- /dev/null +++ b/.env-dist @@ -0,0 +1,13 @@ +POSTGRES_APP_HOST=localhost +POSTGRES_APP_USER=app +POSTGRES_APP_PASSWORD=app123 +POSTGRES_APP_DB=app_db +POSTGRES_APP_PORT=5432 + +POSTGRES_DW_HOST=localhost +POSTGRES_DW_USER=dw +POSTGRES_DW_PASSWORD=dw123 +POSTGRES_DW_DB=dw_db +POSTGRES_DW_PORT=5444 + + diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..fe7c01a --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +dotenv diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..96f1ee2 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +APP_DB_VOLUME=app-db-data +DW_DB_VOLUME=dw-db-data +COMPOSE_FILE=docker-compose.yml + +.PHONY: start stop reset + +start: + docker compose -f $(COMPOSE_FILE) up -d + +stop: + docker compose -f $(COMPOSE_FILE) down + +reset: stop + @echo "Removing volumes..." + docker volume rm -f $(APP_DB_VOLUME) $(DW_DB_VOLUME) + @echo "Volumes removed. You can now start fresh with 'make start'" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7a34cd5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,30 @@ +version: '3.8' + +services: + app-db: + image: postgres:17 + container_name: app-db + environment: + POSTGRES_USER: ${POSTGRES_APP_USER} + POSTGRES_PASSWORD: ${POSTGRES_APP_PASSWORD} + POSTGRES_DB: ${POSTGRES_APP_DB} + ports: + - "${POSTGRES_APP_PORT}:5432" + volumes: + - app-db-data:/var/lib/postgresql/data + + dw-db: + image: postgres:17 + container_name: dw-db + environment: + POSTGRES_USER: ${POSTGRES_DW_USER} + POSTGRES_PASSWORD: ${POSTGRES_DW_PASSWORD} + POSTGRES_DB: ${POSTGRES_DW_DB} + ports: + - "${POSTGRES_DW_PORT}:5432" + volumes: + - dw-db-data:/var/lib/postgresql/data + +volumes: + app-db-data: + dw-db-data: diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..2468070 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1735563628, + "narHash": "sha256-OnSAY7XDSx7CtDoqNh8jwVwh4xNL/2HaJxGjryLWzX8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b134951a4c9f3c995fd7be05f3243f8ecd65d798", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8051303 --- /dev/null +++ b/flake.nix @@ -0,0 +1,30 @@ +{ + description = "Rust dev env for Meltano toy project"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + in { + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ + rustup + pkg-config + openssl + postgresql + sqlx-cli + ]; + + shellHook = '' + export DATABASE_URL="postgres://${POSTGRES_APP_USER}:${POSTGRES_APP_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_APP_PORT}/${POSTGRES_APP_DB}" + export DW_DATABASE_URL="postgres://${POSTGRES_DW_USER}:${POSTGRES_DW_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_DW_PORT}/${POSTGRES_DW_DB}" + echo "✅ Rust + PostgreSQL dev env ready" + ''; + }; + }); +}