From 8cf1b0c3e44f481abd7e07d0e793bd444a81fe52 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 15 Apr 2022 12:36:49 +0200 Subject: [PATCH] Build image via Nix --- app/backup/build/backup-psql/.gitignore | 1 + app/backup/build/backup-psql/README.md | 8 ++++ .../{do_backup.py => backup-psql.py} | 0 app/backup/build/backup-psql/common.nix | 8 ++++ app/backup/build/backup-psql/default.nix | 39 +++++++++++++------ app/backup/build/backup-psql/docker.nix | 11 ++++++ 6 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 app/backup/build/backup-psql/.gitignore create mode 100644 app/backup/build/backup-psql/README.md rename app/backup/build/backup-psql/{do_backup.py => backup-psql.py} (100%) create mode 100644 app/backup/build/backup-psql/common.nix create mode 100644 app/backup/build/backup-psql/docker.nix diff --git a/app/backup/build/backup-psql/.gitignore b/app/backup/build/backup-psql/.gitignore new file mode 100644 index 0000000..b2be92b --- /dev/null +++ b/app/backup/build/backup-psql/.gitignore @@ -0,0 +1 @@ +result diff --git a/app/backup/build/backup-psql/README.md b/app/backup/build/backup-psql/README.md new file mode 100644 index 0000000..97929db --- /dev/null +++ b/app/backup/build/backup-psql/README.md @@ -0,0 +1,8 @@ +## Build + +```bash +docker load < $(nix-build docker.nix) +docker push superboum/backup-psql:??? +``` + + diff --git a/app/backup/build/backup-psql/do_backup.py b/app/backup/build/backup-psql/backup-psql.py similarity index 100% rename from app/backup/build/backup-psql/do_backup.py rename to app/backup/build/backup-psql/backup-psql.py diff --git a/app/backup/build/backup-psql/common.nix b/app/backup/build/backup-psql/common.nix new file mode 100644 index 0000000..639d9a1 --- /dev/null +++ b/app/backup/build/backup-psql/common.nix @@ -0,0 +1,8 @@ +{ + pkgsSrc = fetchTarball { + # Latest commit on https://github.com/NixOS/nixpkgs/tree/nixos-21.11 + # As of 2022-04-15 + url ="https://github.com/NixOS/nixpkgs/archive/2f06b87f64bc06229e05045853e0876666e1b023.tar.gz"; + sha256 = "sha256:1d7zg96xw4qsqh7c89pgha9wkq3rbi9as3k3d88jlxy2z0ns0cy2"; + }; +} diff --git a/app/backup/build/backup-psql/default.nix b/app/backup/build/backup-psql/default.nix index 94dd4e1..1ded395 100644 --- a/app/backup/build/backup-psql/default.nix +++ b/app/backup/build/backup-psql/default.nix @@ -1,16 +1,33 @@ -{ pkgs ? import {} }: let + common = import ./common.nix; + pkgs = import common.pkgsSrc {}; python-with-my-packages = pkgs.python3.withPackages (p: with p; [ minio ]); in -pkgs.mkShell { - buildInputs = [ - python-with-my-packages - pkgs.age - pkgs.postgresql_14 - ]; - shellHook = '' - PYTHONPATH=${python-with-my-packages}/${python-with-my-packages.sitePackages} - ''; -} + pkgs.stdenv.mkDerivation { + name = "backup-psql"; + src = pkgs.lib.sourceFilesBySuffices ./. [ ".py" ]; + + buildInputs = [ + python-with-my-packages + pkgs.age + pkgs.postgresql_14 + ]; + + buildPhase = '' + cat > backup-psql <