From f111ab64e20af8d3d66eee14ed46c40a4b4ad163 Mon Sep 17 00:00:00 2001 From: Jean-Francois Labonte Date: Fri, 7 Jun 2024 22:58:51 -0400 Subject: [PATCH 01/12] Add gitignore for devenv --- .gitignore | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.gitignore b/.gitignore index 777cad7b1..120303d67 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,12 @@ e2e/playwright-report/ e2e/playwright/.cache/ /backend/build_info/version.txt /backend/dist +# Devenv +.devenv* +devenv.local.nix + +# direnv +.direnv + +# pre-commit +.pre-commit-config.yaml From 7573cb7a225c80e5e8c2b2fe6fb2d92905ecdf93 Mon Sep 17 00:00:00 2001 From: Jean-Francois Labonte Date: Fri, 7 Jun 2024 22:59:32 -0400 Subject: [PATCH 02/12] Add .env to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 120303d67..7ae286560 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ devenv.local.nix # pre-commit .pre-commit-config.yaml +.env From 84cea8c81d36f2d3b6e7d1a953d661df4a15b7b1 Mon Sep 17 00:00:00 2001 From: Jean-Francois Labonte Date: Fri, 7 Jun 2024 23:02:24 -0400 Subject: [PATCH 03/12] Add .env.template --- .env.template | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .env.template diff --git a/.env.template b/.env.template new file mode 100644 index 000000000..e69de29bb From e4de215731b7de4e2dea3431b868e9d6668d40ca Mon Sep 17 00:00:00 2001 From: Jean-Francois Labonte Date: Fri, 7 Jun 2024 23:03:01 -0400 Subject: [PATCH 04/12] Add devenv to repository --- .envrc | 3 +++ devenv.nix | 29 +++++++++++++++++++++++++++++ devenv.yaml | 15 +++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 .envrc create mode 100644 devenv.nix create mode 100644 devenv.yaml diff --git a/.envrc b/.envrc new file mode 100644 index 000000000..5bf8fc159 --- /dev/null +++ b/.envrc @@ -0,0 +1,3 @@ +source_url "https://raw.githubusercontent.com/cachix/devenv/95f329d49a8a5289d31e0982652f7058a189bfca/direnvrc" "sha256-d+8cBpDfDBj41inrADaJt+bDWhOktwslgoP5YiGJ1v0=" + +use devenv \ No newline at end of file diff --git a/devenv.nix b/devenv.nix new file mode 100644 index 000000000..2950f29f3 --- /dev/null +++ b/devenv.nix @@ -0,0 +1,29 @@ +{ pkgs, lib, config, inputs, ... }: +let + goPkgs = import (builtins.fetchGit { + name = "go-1.20 Nixpkgs Version"; + url = "https://github.com/NixOS/nixpkgs/"; + ref = "refs/heads/nixpkgs-unstable"; + rev = "336eda0d07dc5e2be1f923990ad9fdb6bc8e28e3"; + }) {}; +in +{ + dotenv.enable = true; + name = "hanko"; + + languages = { + go.enable = true; + go.package = goPkgs.go_1_20; + }; + + processes.serveBackend = { + exec = "cd backend && ${pkgs.go_1_20}/bin/go"; + }; + + containers = { + "hanko" = { + copyToRoot = ./backend; + name = config.IMAGE_NAME; + }; + }; +} diff --git a/devenv.yaml b/devenv.yaml new file mode 100644 index 000000000..116a2adb3 --- /dev/null +++ b/devenv.yaml @@ -0,0 +1,15 @@ +# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json +inputs: + nixpkgs: + url: github:cachix/devenv-nixpkgs/rolling + +# If you're using non-OSS software, you can set allowUnfree to true. +# allowUnfree: true + +# If you're willing to use a package that's vulnerable +# permittedInsecurePackages: +# - "openssl-1.1.1w" + +# If you have more than one devenv you can merge them +#imports: +# - ./backend From 066ff18b22c730459ed43e21d087c485c18d4788 Mon Sep 17 00:00:00 2001 From: Jean-Francois Labonte Date: Fri, 7 Jun 2024 23:52:49 -0400 Subject: [PATCH 05/12] Add temporary variable --- .env.template | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.template b/.env.template index e69de29bb..1be73136d 100644 --- a/.env.template +++ b/.env.template @@ -0,0 +1 @@ +IMAGE_NAME=Change_me \ No newline at end of file From d28f93fe7de3b03508eba5edf58892a643c97f35 Mon Sep 17 00:00:00 2001 From: Jean-Francois Labonte Date: Sat, 8 Jun 2024 00:21:48 -0400 Subject: [PATCH 06/12] Update devenv --- devenv.lock | 210 ++++++++++++++++++++++++++++++++++++++++++++++++++++ devenv.nix | 39 +++++++--- devenv.yaml | 21 +++--- 3 files changed, 246 insertions(+), 24 deletions(-) create mode 100644 devenv.lock diff --git a/devenv.lock b/devenv.lock new file mode 100644 index 000000000..f55928c44 --- /dev/null +++ b/devenv.lock @@ -0,0 +1,210 @@ +{ + "nodes": { + "devenv": { + "locked": { + "dir": "src/modules", + "lastModified": 1717698746, + "owner": "cachix", + "repo": "devenv", + "rev": "866ecadab5d92cdbb296723f67fa464d01401d9a", + "treeHash": "9d43a86d5c69469287da4740c8627624e9b7076c", + "type": "github" + }, + "original": { + "dir": "src/modules", + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "treeHash": "2addb7b71a20a25ea74feeaf5c2f6a6b30898ecb", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "treeHash": "bd263f021e345cb4a39d80c126ab650bebc3c10c", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "treeHash": "ca14199cabdfe1a06a7b1654c76ed49100a689f9", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "go_1_20_revision": { + "locked": { + "lastModified": 1708814358, + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "336eda0d07dc5e2be1f923990ad9fdb6bc8e28e3", + "treeHash": "277a62f1f87f693e5e82230315ea9d814ae55561", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "336eda0d07dc5e2be1f923990ad9fdb6bc8e28e3", + "type": "github" + } + }, + "mk-shell-bin": { + "locked": { + "lastModified": 1677004959, + "owner": "rrbutani", + "repo": "nix-mk-shell-bin", + "rev": "ff5d8bd4d68a347be5042e2f16caee391cd75887", + "treeHash": "496327dabdc787353a29987f492dd4939151baad", + "type": "github" + }, + "original": { + "owner": "rrbutani", + "repo": "nix-mk-shell-bin", + "type": "github" + } + }, + "nix2container": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1712990762, + "owner": "nlewo", + "repo": "nix2container", + "rev": "20aad300c925639d5d6cbe30013c8357ce9f2a2e", + "treeHash": "f9359d4b4e79c4e798a3018ae0ce3cb4317d4612", + "type": "github" + }, + "original": { + "owner": "nlewo", + "repo": "nix2container", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1716977621, + "owner": "cachix", + "repo": "devenv-nixpkgs", + "rev": "4267e705586473d3e5c8d50299e71503f16a6fb6", + "treeHash": "6d9f1f7ca0faf1bc2eeb397c78a49623260d3412", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "rolling", + "repo": "devenv-nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1717530100, + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a2e1d0414259a144ebdc048408a807e69e0565af", + "treeHash": "d1a59f4c20789566e0ef4b5471521a4fc58963a1", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1717664902, + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "cc4d466cb1254af050ff7bdf47f6d404a7c646d1", + "treeHash": "def977583217aad11744d144c1f7fc216ce450bf", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "go_1_20_revision": "go_1_20_revision", + "mk-shell-bin": "mk-shell-bin", + "nix2container": "nix2container", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "treeHash": "cce81f2a0f0743b2eb61bc2eb6c7adbe2f2c6beb", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/devenv.nix b/devenv.nix index 2950f29f3..03c6a5128 100644 --- a/devenv.nix +++ b/devenv.nix @@ -1,29 +1,44 @@ { pkgs, lib, config, inputs, ... }: let - goPkgs = import (builtins.fetchGit { - name = "go-1.20 Nixpkgs Version"; - url = "https://github.com/NixOS/nixpkgs/"; - ref = "refs/heads/nixpkgs-unstable"; - rev = "336eda0d07dc5e2be1f923990ad9fdb6bc8e28e3"; - }) {}; + goPkgs = pkgs.callPackage inputs.go_1_20_revision { }; in { dotenv.enable = true; + dotenv.filename = ".env"; + name = "hanko"; - languages = { - go.enable = true; - go.package = goPkgs.go_1_20; - }; + packages = [ + goPkgs.go_1_20 + pkgs.cacert + ] ++ lib.optionals ( !config.container.isBuilding) [ + pkgs.docker + pkgs.docker-compose + ]; + + enterShell = '' + if [[ ! -f .env ]]; then + cp .env.template .env + echo "Created a new .env file from .env.example" + fi + ''; processes.serveBackend = { - exec = "cd backend && ${pkgs.go_1_20}/bin/go"; + exec = "cd backend && ${goPkgs.go_1_20}/bin/go"; }; containers = { "hanko" = { copyToRoot = ./backend; - name = config.IMAGE_NAME; + name = config.env.IMAGE_NAME; + startupCommand = '' + export SSL_CERT_DIR="${pkgs.cacert}/certs/" + echo "This is a the DIR" + echo $SSL_CERT_DIR + ${goPkgs.go_1_20}/bin/go generate ./... + CGO_ENABLED=0 GOOS=linux GOARCH="$TARGETARCH" ${goPkgs.go_1_20}/bin/go build -a -o hanko main.go + ./hanko + ''; }; }; } diff --git a/devenv.yaml b/devenv.yaml index 116a2adb3..57fa40be1 100644 --- a/devenv.yaml +++ b/devenv.yaml @@ -1,15 +1,12 @@ -# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json inputs: + nix2container: + url: github:nlewo/nix2container + inputs: + nixpkgs: + follows: nixpkgs + mk-shell-bin: + url: github:rrbutani/nix-mk-shell-bin nixpkgs: url: github:cachix/devenv-nixpkgs/rolling - -# If you're using non-OSS software, you can set allowUnfree to true. -# allowUnfree: true - -# If you're willing to use a package that's vulnerable -# permittedInsecurePackages: -# - "openssl-1.1.1w" - -# If you have more than one devenv you can merge them -#imports: -# - ./backend + go_1_20_revision: + url: github:NixOS/nixpkgs?rev=336eda0d07dc5e2be1f923990ad9fdb6bc8e28e3 From a5484556beebd12ec93a313c948b9a36d3d90d15 Mon Sep 17 00:00:00 2001 From: Jean-Francois Labonte Date: Sun, 9 Jun 2024 22:15:57 -0400 Subject: [PATCH 07/12] Add the right variable to give access to SSL Certificates --- devenv.nix | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/devenv.nix b/devenv.nix index 03c6a5128..5436c2acd 100644 --- a/devenv.nix +++ b/devenv.nix @@ -14,6 +14,7 @@ in ] ++ lib.optionals ( !config.container.isBuilding) [ pkgs.docker pkgs.docker-compose + pkgs.git ]; enterShell = '' @@ -32,9 +33,7 @@ in copyToRoot = ./backend; name = config.env.IMAGE_NAME; startupCommand = '' - export SSL_CERT_DIR="${pkgs.cacert}/certs/" - echo "This is a the DIR" - echo $SSL_CERT_DIR + export SSL_CERT_DIR=${pkgs.cacert}/etc/ssl/certs/ ${goPkgs.go_1_20}/bin/go generate ./... CGO_ENABLED=0 GOOS=linux GOARCH="$TARGETARCH" ${goPkgs.go_1_20}/bin/go build -a -o hanko main.go ./hanko From 965832e758d0372feb89579b8ab7f948da03cc66 Mon Sep 17 00:00:00 2001 From: Jean-Francois Labonte Date: Mon, 10 Jun 2024 00:13:04 -0400 Subject: [PATCH 08/12] Change of strategy devenv is not working as expected with containers --- devenv.nix | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/devenv.nix b/devenv.nix index 5436c2acd..e942ed86d 100644 --- a/devenv.nix +++ b/devenv.nix @@ -11,33 +11,26 @@ in packages = [ goPkgs.go_1_20 pkgs.cacert - ] ++ lib.optionals ( !config.container.isBuilding) [ + pkgs.git pkgs.docker pkgs.docker-compose - pkgs.git + pkgs.nixpacks ]; enterShell = '' + export SSL_CERT_DIR=${pkgs.cacert}/etc/ssl/certs/ + if [[ ! -f .env ]]; then cp .env.template .env echo "Created a new .env file from .env.example" fi ''; - processes.serveBackend = { - exec = "cd backend && ${goPkgs.go_1_20}/bin/go"; - }; - - containers = { - "hanko" = { - copyToRoot = ./backend; - name = config.env.IMAGE_NAME; - startupCommand = '' - export SSL_CERT_DIR=${pkgs.cacert}/etc/ssl/certs/ - ${goPkgs.go_1_20}/bin/go generate ./... - CGO_ENABLED=0 GOOS=linux GOARCH="$TARGETARCH" ${goPkgs.go_1_20}/bin/go build -a -o hanko main.go - ./hanko - ''; - }; + scripts = { + build_image.exec = '' + nixpacks build ./backend \ + --name ${config.env.IMAGE_NAME} + ''; + push_image.exec = "devenv container --registry docker:// copy hanko"; }; } From 1fbbba36c36a037cab2d0095a2549d63a75040ec Mon Sep 17 00:00:00 2001 From: Jean-Francois Labonte Date: Mon, 10 Jun 2024 00:13:20 -0400 Subject: [PATCH 09/12] Configure nixpacks to generate the docker image --- nixpacks.toml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 nixpacks.toml diff --git a/nixpacks.toml b/nixpacks.toml new file mode 100644 index 000000000..38b1d7d62 --- /dev/null +++ b/nixpacks.toml @@ -0,0 +1,6 @@ +[phases.setup] + nixpkgsArchive = '336eda0d07dc5e2be1f923990ad9fdb6bc8e28e3' + nixPkgs = [ "go_1_20" ] + +[phases.build] + cmd = "go enerate ./... && CGO_ENABLED=0 GOOS=linux GOARCH='$TARGETARCH' go build -a -o hanko main.go" From c1255c33059b6bb6f346f1d4bd94ebe6e0608993 Mon Sep 17 00:00:00 2001 From: Jean-Francois Labonte Date: Mon, 10 Jun 2024 00:15:24 -0400 Subject: [PATCH 10/12] Create a script to build then push image --- devenv.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devenv.nix b/devenv.nix index e942ed86d..9c6eea5c0 100644 --- a/devenv.nix +++ b/devenv.nix @@ -31,6 +31,6 @@ in nixpacks build ./backend \ --name ${config.env.IMAGE_NAME} ''; - push_image.exec = "devenv container --registry docker:// copy hanko"; + build_push_image.exec = "build_image && docker push ${config.env.IMAGE_NAME}"; }; } From 926bd1d5d6ee3e025043377f12e7eda3f4a28fa9 Mon Sep 17 00:00:00 2001 From: Jean-Francois Labonte Date: Mon, 10 Jun 2024 09:06:31 -0400 Subject: [PATCH 11/12] Remove unecessary code --- devenv.nix | 5 ----- 1 file changed, 5 deletions(-) diff --git a/devenv.nix b/devenv.nix index 9c6eea5c0..7f3ea36cd 100644 --- a/devenv.nix +++ b/devenv.nix @@ -10,16 +10,11 @@ in packages = [ goPkgs.go_1_20 - pkgs.cacert pkgs.git - pkgs.docker - pkgs.docker-compose pkgs.nixpacks ]; enterShell = '' - export SSL_CERT_DIR=${pkgs.cacert}/etc/ssl/certs/ - if [[ ! -f .env ]]; then cp .env.template .env echo "Created a new .env file from .env.example" From 5e1aeefbcec422a379a383048bfb86dcbc679334 Mon Sep 17 00:00:00 2001 From: Jeff Labonte Date: Mon, 10 Jun 2024 12:45:49 -0400 Subject: [PATCH 12/12] Update nixpacks.toml --- nixpacks.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixpacks.toml b/nixpacks.toml index 38b1d7d62..b55ea6703 100644 --- a/nixpacks.toml +++ b/nixpacks.toml @@ -3,4 +3,4 @@ nixPkgs = [ "go_1_20" ] [phases.build] - cmd = "go enerate ./... && CGO_ENABLED=0 GOOS=linux GOARCH='$TARGETARCH' go build -a -o hanko main.go" + cmd = "go generate ./... && CGO_ENABLED=0 GOOS=linux GOARCH='$TARGETARCH' go build -a -o hanko main.go"