diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..4cd5916 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,116 @@ +# Our desired pipeline using only a Nix shell environment +name: Check and build Kardinal + +on: + push: + branches: + - main + - "demo-*" + tags: + - "v*.*.*" + pull_request: + branches: + - main + - "demo-*" +env: + MAIN_BRANCH: ${{ 'refs/heads/main' }} + +jobs: + check_nix: + name: Basic Check + runs-on: ubuntu-22.04 + steps: + - name: git checkout + uses: actions/checkout@v3 + + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + + - name: Magic cache + uses: DeterminateSystems/magic-nix-cache-action@main + + - name: Check Nixpkgs inputs + uses: DeterminateSystems/flake-checker-action@main + with: + fail-mode: true + + # Nix-specific logic begins here + - name: Nix Check + run: | + nix flake check + + - name: Check Go tidiness + run: | + git reset --hard + git clean -f + nix develop --command go-tidy-all + export changed_files=$(git diff-files --name-only | grep -cv ".toml$") + if [[ $changed_files != 0 ]]; then + echo "Go modules are not so tidy (run 'go-tidy-all' to fix it):" + git diff-files --name-only + exit 1 + fi + + - name: Check Go formatting + run: | + git reset --hard + git clean -f + nix develop --command gofmt -l . + nix develop --command test -z $(gofmt -l .) + + build_images: + name: Test, build and publish images + needs: check_nix + runs-on: ubuntu-22.04 + steps: + - name: git checkout + uses: actions/checkout@v3 + + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + + - name: Magic cache + uses: DeterminateSystems/magic-nix-cache-action@main + + - name: Build cartservice images + run: | + nix build ./#containers.x86_64-linux.cartservice.arm64 --no-link --print-out-paths + nix build ./#containers.x86_64-linux.cartservice.amd64 --no-link --print-out-paths + + - name: Build currencyexternalapi images + run: | + nix build ./#containers.x86_64-linux.currencyexternalapi.arm64 --no-link --print-out-paths + nix build ./#containers.x86_64-linux.currencyexternalapi.amd64 --no-link --print-out-paths + + - name: Build frontend images + run: | + nix build ./#containers.x86_64-linux.frontend.arm64 --no-link --print-out-paths + nix build ./#containers.x86_64-linux.frontend.amd64 --no-link --print-out-paths + + - name: Build productcatalogservice images + run: | + nix build ./#containers.x86_64-linux.productcatalogservice.arm64 --no-link --print-out-paths + nix build ./#containers.x86_64-linux.productcatalogservice.amd64 --no-link --print-out-paths + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Publish images + if: github.ref == env.MAIN_BRANCH + run: | + # Set tag to be the branch name and version + nix develop --command tag-branch-version + nix run ./#publish-cartservice-container + nix run ./#publish-currencyexternalapi-container + nix run ./#publish-frontend-container + nix run ./#publish-productcatalogservice-container + + # Set tag to be the branch name + nix develop --command tag-branch + nix run ./#publish-cartservice-container + nix run ./#publish-currencyexternalapi-container + nix run ./#publish-frontend-container + nix run ./#publish-productcatalogservice-container diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0c0f984 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.direnv +branch-name.nix diff --git a/branch-name.nix b/branch-name.nix new file mode 100644 index 0000000..19765bd --- /dev/null +++ b/branch-name.nix @@ -0,0 +1 @@ +null diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..cd20290 --- /dev/null +++ b/flake.lock @@ -0,0 +1,102 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gomod2nix": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1722589758, + "narHash": "sha256-sbbA8b6Q2vB/t/r1znHawoXLysCyD4L/6n6/RykiSnA=", + "owner": "nix-community", + "repo": "gomod2nix", + "rev": "4e08ca09253ef996bd4c03afa383b23e35fe28a1", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "gomod2nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1722987190, + "narHash": "sha256-68hmex5efCiM2aZlAAEcQgmFI4ZwWt8a80vOeB/5w3A=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "21cc704b5e918c5fbf4f9fff22b4ac2681706d90", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "gomod2nix": "gomod2nix", + "nixpkgs": "nixpkgs", + "unstable": "unstable" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "unstable": { + "locked": { + "lastModified": 1722813957, + "narHash": "sha256-IAoYyYnED7P8zrBFMnmp7ydaJfwTnwcnqxUElC1I26Y=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "cb9a96f23c491c081b38eab96d22fa958043c9fa", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6e9d3f8 --- /dev/null +++ b/flake.nix @@ -0,0 +1,259 @@ +{ + description = "Go development environment"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; + flake-utils.url = "github:numtide/flake-utils"; + unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; + gomod2nix.url = "github:nix-community/gomod2nix"; + gomod2nix.inputs.nixpkgs.follows = "nixpkgs"; + gomod2nix.inputs.flake-utils.follows = "flake-utils"; + }; + outputs = { + self, + nixpkgs, + flake-utils, + unstable, + gomod2nix, + ... + }: + flake-utils.lib.eachDefaultSystem + ( + system: let + pkgs = import nixpkgs { + inherit system; + overlays = [ + (import "${gomod2nix}/overlay.nix") + ]; + }; + + version = toString (self.ref or self.shortRev or self.dirtyShortRev or self.lastModified or "unknown"); + tag-name = let + branch-name = import ./branch-name.nix; + tag = toString ( + if isNull branch-name + then "${version}" + else "${toString branch-name}" + ); + in + builtins.replaceStrings ["/"] ["_"] tag; + + service_names = [ + "cartservice" + "currencyexternalapi" + "frontend" + "productcatalogservice" + ]; + architectures = ["amd64" "arm64"]; + imageRegistry = "kurtosistech"; + + matchingContainerArch = + if builtins.match "aarch64-.*" system != null + then "arm64" + else if builtins.match "x86_64-.*" system != null + then "amd64" + else throw "Unsupported system type: ${system}"; + + mergeContainerPackages = acc: service: + pkgs.lib.recursiveUpdate acc { + packages."${service}-container" = self.containers.${system}.${service}.${matchingContainerArch}; + }; + + multiPlatformDockerPusher = acc: service: + pkgs.lib.recursiveUpdate acc { + packages."publish-${service}-container" = let + name = "${imageRegistry}/${service}"; + tagBase = tag-name; + images = + map ( + arch: rec { + inherit arch; + image = self.containers.${system}.${service}.${arch}; + tag = "${tagBase}-${arch}"; + } + ) + architectures; + loadAndPush = builtins.concatStringsSep "\n" (pkgs.lib.concatMap + ({ + arch, + image, + tag, + }: [ + "$docker load -i ${image}" + "$docker push ${name}:${tag}" + ]) + images); + imageNames = + builtins.concatStringsSep " " + (map ({ + arch, + image, + tag, + }: "${name}:${tag}") + images); + in + pkgs.writeTextFile { + inherit name; + text = '' + #!${pkgs.stdenv.shell} + set -euxo pipefail + docker=${pkgs.docker}/bin/docker + ${loadAndPush} + $docker manifest create --amend ${name}:${tagBase} ${imageNames} + $docker manifest push ${name}:${tagBase} + ''; + executable = true; + destination = "/bin/push"; + }; + }; + + systemOutput = rec { + devShells.default = let + go-tidy-all = pkgs.writeShellApplication { + name = "go-tidy-all"; + runtimeInputs = with pkgs; [go git gomod2nix]; + text = '' + root_dirpath=$(git rev-parse --show-toplevel) + find "$root_dirpath" -type f -name 'go.mod' -exec sh -c 'dir=$(dirname "$1") && cd "$dir" && echo "$dir" && go mod tidy && gomod2nix' shell {} \; + ''; + }; + + tag-branch = pkgs.writeShellApplication { + name = "tag-branch"; + runtimeInputs = with pkgs; [git]; + text = '' + GIT_ROOT=$(git rev-parse --show-toplevel 2>/dev/null) + CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + echo "\"$CURRENT_BRANCH\"" >"$GIT_ROOT/branch-name.nix" + echo "Branch name \"$CURRENT_BRANCH\" written to $GIT_ROOT/branch-name.nix" + ''; + }; + + tag-branch-version = pkgs.writeShellApplication { + name = "tag-branch-version"; + runtimeInputs = with pkgs; [git]; + text = '' + GIT_ROOT=$(git rev-parse --show-toplevel 2>/dev/null) + CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + SHORT_COMMIT_HASH=$(git rev-parse --short HEAD) + echo "\"$CURRENT_BRANCH-$SHORT_COMMIT_HASH\"" >"$GIT_ROOT/branch-name.nix" + echo "Branch name \"$CURRENT_BRANCH-$SHORT_COMMIT_HASH\" written to $GIT_ROOT/branch-name.nix" + ''; + }; + in + pkgs.mkShell { + buildInputs = with pkgs; [ + go + gopls + go-tools + golangci-lint + pkgs.gomod2nix + skaffold + go-tidy-all + tag-branch + tag-branch-version + ]; + + shellHook = '' + echo "Go development environment loaded" + go version + ''; + }; + + packages.cartservice = pkgs.callPackage ./src/cartservice { + inherit pkgs; + }; + + packages.currencyexternalapi = pkgs.callPackage ./src/currencyexternalapi { + inherit pkgs; + }; + + packages.frontend = pkgs.callPackage ./src/frontend { + inherit pkgs; + }; + + packages.productcatalogservice = pkgs.callPackage ./src/productcatalogservice { + inherit pkgs; + }; + + containers = let + os = "linux"; + all = + pkgs.lib.mapCartesianProduct ({ + arch, + service_name, + }: { + "${service_name}" = { + "${toString arch}" = let + nix_arch = + builtins.replaceStrings + ["arm64" "amd64"] ["aarch64" "x86_64"] + arch; + + container_pkgs = import nixpkgs { + system = "${nix_arch}-${os}"; + }; + + # if running from linux no cross-compilation is needed to palce the service in a container + needsCrossCompilation = + "${nix_arch}-${os}" + != system; + + service = + if !needsCrossCompilation + then + packages.${service_name}.overrideAttrs + (old: old // {doCheck = false;}) + else + packages.${service_name}.overrideAttrs (old: + old + // { + GOOS = os; + GOARCH = arch; + # CGO_ENABLED = disabled breaks the CLI compilation + # CGO_ENABLED = 0; + doCheck = false; + }); + in + builtins.trace "${service}/bin" pkgs.dockerTools.buildImage { + name = "${imageRegistry}/${service_name}"; + tag = "${tag-name}-${arch}"; + # tag = commit_hash; + created = "now"; + copyToRoot = pkgs.buildEnv { + name = "image-root"; + paths = [ + service + container_pkgs.bashInteractive + container_pkgs.nettools + container_pkgs.gnugrep + container_pkgs.coreutils + container_pkgs.cacert + ]; + pathsToLink = ["/bin"]; + }; + architecture = arch; + config.Cmd = + if !needsCrossCompilation + then ["${service}/bin/${service.name}"] + else ["${service}/bin/${os}_${arch}/${service.name}"]; + config.Env = ["SSL_CERT_FILE=${container_pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"]; + }; + }; + }) { + arch = architectures; + service_name = service_names; + }; + in + pkgs.lib.foldl' (set: acc: pkgs.lib.recursiveUpdate acc set) {} + all; + }; + # Add containers matching architecture with local system as toplevel packages + # this means calling `nix build .#-container` will build the container matching the local system. + # For cross-compilation use the containers attribute directly: `nix build .containers...` + outputWithContaniers = pkgs.lib.foldl' mergeContainerPackages systemOutput service_names; + outputWithContainersAndPushers = pkgs.lib.foldl' multiPlatformDockerPusher outputWithContaniers service_names; + in + outputWithContainersAndPushers + ); +} diff --git a/src/cartservice/consts/consts.go b/src/cartservice/consts/consts.go index 4b1a7be..8ee3f38 100644 --- a/src/cartservice/consts/consts.go +++ b/src/cartservice/consts/consts.go @@ -3,4 +3,3 @@ package consts const ( KardinalTraceIdHeaderKey = "X-Kardinal-Trace-Id" ) - diff --git a/src/cartservice/default.nix b/src/cartservice/default.nix new file mode 100644 index 0000000..cf61431 --- /dev/null +++ b/src/cartservice/default.nix @@ -0,0 +1,14 @@ +{pkgs}: let + pname = "cartservice"; +in + pkgs.buildGoApplication { + # pname has to match the location (folder) where the main function is or use + # subPackges to specify the file (e.g. subPackages = ["some/folder/main.go"];) + inherit pname; + name = "${pname}"; + pwd = ./.; + src = ./.; + modules = ./gomod2nix.toml; + doCheck = false; + CGO_ENABLED = 0; + } diff --git a/src/cartservice/gomod2nix.toml b/src/cartservice/gomod2nix.toml new file mode 100644 index 0000000..70c702d --- /dev/null +++ b/src/cartservice/gomod2nix.toml @@ -0,0 +1,120 @@ +schema = 3 + +[mod] + [mod."github.com/apapsch/go-jsonmerge/v2"] + version = "v2.0.0" + hash = "sha256-xp/1B6XUN2EbddBfoUkTV3oTk+34m4kOZP+66HhfLg4=" + [mod."github.com/deepmap/oapi-codegen/v2"] + version = "v2.2.1-0.20240604070534-2f0ff757704b" + hash = "sha256-xexjMUdpXoOS9i8dA3MD4mBFHcXSnk9y6iKZfeSXjHg=" + [mod."github.com/getkin/kin-openapi"] + version = "v0.124.0" + hash = "sha256-KHkZXKqtjqAiABE2VGQzOgSxz4imHJeDtXFaePrt5hI=" + [mod."github.com/go-openapi/jsonpointer"] + version = "v0.20.2" + hash = "sha256-z9IZxP+JvJ1WvrHE7qbAZQqJ3XMx1uD0S611shTMna8=" + [mod."github.com/go-openapi/swag"] + version = "v0.22.8" + hash = "sha256-YMJpCbWT9ABlCmuLjxQRwhddlYYqDBWcyDIdnV8bAMc=" + [mod."github.com/golang-jwt/jwt"] + version = "v3.2.2+incompatible" + hash = "sha256-LOkpuXhWrFayvVf1GOaOmZI5YKEsgqVSb22aF8LnCEM=" + [mod."github.com/google/uuid"] + version = "v1.5.0" + hash = "sha256-DasOte4xANR1VND5XEHKGhpGiyYq74TJmNrgWeIRX4U=" + [mod."github.com/invopop/yaml"] + version = "v0.2.0" + hash = "sha256-RxeDuvwOSWYaLc8Q7T39rfFT3bZX3g9Bu0RFwxH6sLw=" + [mod."github.com/jackc/pgpassfile"] + version = "v1.0.0" + hash = "sha256-H0nFbC34/3pZUFnuiQk9W7yvAMh6qJDrqvHp+akBPLM=" + [mod."github.com/jackc/pgservicefile"] + version = "v0.0.0-20221227161230-091c0ba34f0a" + hash = "sha256-rBtUw15WPPDp2eulHXH5e2zCIed1OPFYwlCpgDOnGRM=" + [mod."github.com/jackc/pgx/v5"] + version = "v5.5.5" + hash = "sha256-Uy9f1EVJwwf5eZtx/JuacqYMe7m/iOx/jHI81hRWqv8=" + [mod."github.com/jackc/puddle/v2"] + version = "v2.2.1" + hash = "sha256-Edf8SLT/8l+xfHm9IjUGxs1MHtic2VgRyfqb6OzGA9k=" + [mod."github.com/jinzhu/inflection"] + version = "v1.0.0" + hash = "sha256-3h3pHib5MaCXKyKLIMyQnSptDJ16kPjCOQPoEBoQsZg=" + [mod."github.com/jinzhu/now"] + version = "v1.1.5" + hash = "sha256-NNLqoFx9FczBBDpD0O0aSHnC/YDZ9E/xQ340o7u63IM=" + [mod."github.com/josharian/intern"] + version = "v1.0.0" + hash = "sha256-LJR0QE2vOQ2/2shBbO5Yl8cVPq+NFrE3ers0vu9FRP0=" + [mod."github.com/labstack/echo/v4"] + version = "v4.12.0" + hash = "sha256-TPXJv/6C53bnmcEYxa9g5Mft8u/rLT96q64tQ9+RtKU=" + [mod."github.com/labstack/gommon"] + version = "v0.4.2" + hash = "sha256-395+BETDpv15L2lsCiEccwakXgEQxKHlYBAU0Ot3qhY=" + [mod."github.com/mailru/easyjson"] + version = "v0.7.7" + hash = "sha256-NVCz8MURpxgOjHXqxOZExqV4bnpHggpeAOyZDArjcy4=" + [mod."github.com/mattn/go-colorable"] + version = "v0.1.13" + hash = "sha256-qb3Qbo0CELGRIzvw7NVM1g/aayaz4Tguppk9MD2/OI8=" + [mod."github.com/mattn/go-isatty"] + version = "v0.0.20" + hash = "sha256-qhw9hWtU5wnyFyuMbKx+7RB8ckQaFQ8D+8GKPkN3HHQ=" + [mod."github.com/mohae/deepcopy"] + version = "v0.0.0-20170929034955-c48cc78d4826" + hash = "sha256-TQMmKqIYwVhmMVh4RYQkAui97Eyj7poLmcAuDcHXsEk=" + [mod."github.com/oapi-codegen/runtime"] + version = "v1.1.1" + hash = "sha256-GRvzpQngQPAy59KvvcwhjYqjx4gttIhOtQKjqfQcNvI=" + [mod."github.com/perimeterx/marshmallow"] + version = "v1.1.5" + hash = "sha256-fFWjg0FNohDSV0/wUjQ8fBq1g8h6yIqTrHkxqL2Tt0s=" + [mod."github.com/pkg/errors"] + version = "v0.9.1" + hash = "sha256-mNfQtcrQmu3sNg/7IwiieKWOgFQOVVe2yXgKBpe/wZw=" + [mod."github.com/sirupsen/logrus"] + version = "v1.8.1" + hash = "sha256-vUIDlLXYBD74+JqdoSx+W3J6r5cOk63heo0ElsHizoM=" + [mod."github.com/valyala/bytebufferpool"] + version = "v1.0.0" + hash = "sha256-I9FPZ3kCNRB+o0dpMwBnwZ35Fj9+ThvITn8a3Jr8mAY=" + [mod."github.com/valyala/fasttemplate"] + version = "v1.2.2" + hash = "sha256-gp+lNXE8zjO+qJDM/YbS6V43HFsYP6PKn4ux1qa5lZ0=" + [mod."golang.org/x/crypto"] + version = "v0.23.0" + hash = "sha256-6hZjb/OazWFBef0C/aH63l49YQnzCh2vpIduzyfSSG8=" + [mod."golang.org/x/mod"] + version = "v0.17.0" + hash = "sha256-CLaPeF6uTFuRDv4oHwOQE6MCMvrzkUjWN3NuyywZjKU=" + [mod."golang.org/x/net"] + version = "v0.25.0" + hash = "sha256-IjFfXLYNj27WLF7vpkZ6mfFXBnp+7QER3OQ0RgjxN54=" + [mod."golang.org/x/sync"] + version = "v0.7.0" + hash = "sha256-2ETllEu2GDWoOd/yMkOkLC2hWBpKzbVZ8LhjLu0d2A8=" + [mod."golang.org/x/sys"] + version = "v0.20.0" + hash = "sha256-mowlaoG2k4n1c1rApWef5EMiXd3I77CsUi8jPh6pTYA=" + [mod."golang.org/x/text"] + version = "v0.15.0" + hash = "sha256-pBnj0AEkfkvZf+3bN7h6epCD2kurw59clDP7yWvxKlk=" + [mod."golang.org/x/time"] + version = "v0.5.0" + hash = "sha256-W6RgwgdYTO3byIPOFxrP2IpAZdgaGowAaVfYby7AULU=" + [mod."golang.org/x/tools"] + version = "v0.21.0" + hash = "sha256-TU0gAxUX410AYc/nMxxZiaqXeORih1cXbKh3sxKufVg=" + [mod."gopkg.in/yaml.v2"] + version = "v2.4.0" + hash = "sha256-uVEGglIedjOIGZzHW4YwN1VoRSTK8o0eGZqzd+TNdd0=" + [mod."gopkg.in/yaml.v3"] + version = "v3.0.1" + hash = "sha256-FqL9TKYJ0XkNwJFnq9j0VvJ5ZUU1RvH/52h/f5bkYAU=" + [mod."gorm.io/driver/postgres"] + version = "v1.5.9" + hash = "sha256-C/ieKeHEsR0sS8kG4YZaMCkWCBRfcRC4RH5nIyWQGX4=" + [mod."gorm.io/gorm"] + version = "v1.25.11" + hash = "sha256-cR0jsCCR0CpqSA0Ci5Uq0/1YDONj3dl6lRuRYcu4HpQ=" diff --git a/src/currencyexternalapi/default.nix b/src/currencyexternalapi/default.nix new file mode 100644 index 0000000..f2b4107 --- /dev/null +++ b/src/currencyexternalapi/default.nix @@ -0,0 +1,14 @@ +{pkgs}: let + pname = "currencyexternalapi"; +in + pkgs.buildGoApplication { + # pname has to match the location (folder) where the main function is or use + # subPackges to specify the file (e.g. subPackages = ["some/folder/main.go"];) + inherit pname; + name = "${pname}"; + pwd = ./.; + src = ./.; + modules = ./gomod2nix.toml; + doCheck = false; + CGO_ENABLED = 0; + } diff --git a/src/currencyexternalapi/gomod2nix.toml b/src/currencyexternalapi/gomod2nix.toml new file mode 100644 index 0000000..9b3e632 --- /dev/null +++ b/src/currencyexternalapi/gomod2nix.toml @@ -0,0 +1,33 @@ +schema = 3 + +[mod] + [mod."github.com/davecgh/go-spew"] + version = "v1.1.1" + hash = "sha256-nhzSUrE1fCkN0+RL04N4h8jWmRFPPPWbCuDc7Ss0akI=" + [mod."github.com/golang/protobuf"] + version = "v1.4.3" + hash = "sha256-GoytLjWoBKfZq3eBDa4rGQNP2la2IrpkFSWjsH/sPBI=" + [mod."github.com/pmezard/go-difflib"] + version = "v1.0.0" + hash = "sha256-/FtmHnaGjdvEIKAJtrUfEhV7EVo5A/eYrtdnUkuxLDA=" + [mod."github.com/sirupsen/logrus"] + version = "v1.7.0" + hash = "sha256-VClDP4DJDdMFTMGWR7I8L4hQRMU7cOphLRyUfxCvnNY=" + [mod."github.com/stretchr/testify"] + version = "v1.8.0" + hash = "sha256-LDxBAebK+A06y4vbH7cd1sVBOameIY81Xm8/9OPZh7o=" + [mod."golang.org/x/sys"] + version = "v0.0.0-20200323222414-85ca7c5b95cd" + hash = "sha256-Eg/nZTMQdH2BDWEd6YzQTybn8F6wNuWkQB5ZWJnjDtI=" + [mod."google.golang.org/genproto"] + version = "v0.0.0-20200526211855-cb27e3aa2013" + hash = "sha256-wFVFmWkQLFRBBNTt3C0Dy3GChkYEYnaDLVbQhyq2K1g=" + [mod."google.golang.org/grpc"] + version = "v1.42.0" + hash = "sha256-p97BCecu+L1Lk2/Yj0JEVJP8YVxikOxGw+IbNCsA/go=" + [mod."google.golang.org/protobuf"] + version = "v1.25.0" + hash = "sha256-3sf57K5A0nmA1UmDe+6FUNJI6UR+SfVyZWNv+2TGHT4=" + [mod."gopkg.in/yaml.v3"] + version = "v3.0.1" + hash = "sha256-FqL9TKYJ0XkNwJFnq9j0VvJ5ZUU1RvH/52h/f5bkYAU=" diff --git a/src/frontend/consts/consts.go b/src/frontend/consts/consts.go index 4b1a7be..8ee3f38 100644 --- a/src/frontend/consts/consts.go +++ b/src/frontend/consts/consts.go @@ -3,4 +3,3 @@ package consts const ( KardinalTraceIdHeaderKey = "X-Kardinal-Trace-Id" ) - diff --git a/src/frontend/default.nix b/src/frontend/default.nix new file mode 100644 index 0000000..b88afaf --- /dev/null +++ b/src/frontend/default.nix @@ -0,0 +1,40 @@ +{pkgs}: let + pname = "frontend"; + staticFiles = pkgs.stdenv.mkDerivation { + name = "${pname}-static"; + src = ./static; + installPhase = '' + mkdir -p $out/static + cp -r * $out/static/ + ''; + }; + templateFiles = pkgs.stdenv.mkDerivation { + name = "${pname}-static"; + src = ./templates; + installPhase = '' + mkdir -p $out/templates + cp -r * $out/templates/ + ''; + }; + app = pkgs.buildGoApplication { + # pname has to match the location (folder) where the main function is or use + # subPackges to specify the file (e.g. subPackages = ["some/folder/main.go"];) + inherit pname; + name = "${pname}-app"; + pwd = ./.; + src = ./.; + modules = ./gomod2nix.toml; + doCheck = false; + CGO_ENABLED = 0; + }; +in + pkgs.stdenv.mkDerivation { + name = "${pname}"; + phases = ["installPhase"]; + installPhase = '' + mkdir -p $out + ln -s ${staticFiles}/static $out/static + ln -s ${templateFiles}/templates $out/templates + ln -s ${app}/bin/${pname} $out/${pname} + ''; + } diff --git a/src/frontend/go.mod b/src/frontend/go.mod index ef52952..d020422 100644 --- a/src/frontend/go.mod +++ b/src/frontend/go.mod @@ -4,55 +4,30 @@ go 1.21.9 toolchain go1.22.4 -replace github.com/kurtosis-tech/new-obd/src/currencyexternalapi => ../currencyexternalapi +replace ( + github.com/kurtosis-tech/new-obd/src/cartservice => ../cartservice + github.com/kurtosis-tech/new-obd/src/currencyexternalapi => ../currencyexternalapi + github.com/kurtosis-tech/new-obd/src/productcatalogservice => ../productcatalogservice + +) require ( github.com/google/uuid v1.5.0 github.com/gorilla/mux v1.8.1 - github.com/kurtosis-tech/new-obd/src/cartservice v0.0.0-20240801144151-c12fae1940c6 - github.com/kurtosis-tech/new-obd/src/currencyexternalapi v0.0.0-20240731052808-7a2597c080ba - github.com/kurtosis-tech/new-obd/src/productcatalogservice v0.0.0-20240731052808-7a2597c080ba + github.com/kurtosis-tech/new-obd/src/cartservice v0.0.0 + github.com/kurtosis-tech/new-obd/src/currencyexternalapi v0.0.0 + github.com/kurtosis-tech/new-obd/src/productcatalogservice v0.0.0 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.8.1 ) require ( github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect - github.com/getkin/kin-openapi v0.124.0 // indirect - github.com/go-openapi/jsonpointer v0.20.2 // indirect - github.com/go-openapi/swag v0.22.8 // indirect - github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/golang/protobuf v1.5.0 // indirect github.com/google/go-cmp v0.5.8 // indirect - github.com/invopop/yaml v0.2.0 // indirect - github.com/jackc/pgpassfile v1.0.0 // indirect - github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect - github.com/jackc/pgx/v5 v5.5.5 // indirect - github.com/jackc/puddle/v2 v2.2.1 // indirect - github.com/jinzhu/inflection v1.0.0 // indirect - github.com/jinzhu/now v1.1.5 // indirect - github.com/josharian/intern v1.0.0 // indirect - github.com/kurtosis-tech/online-boutique-demo/src/currencyexternalapi v0.0.0-20240730171234-cd7da1f8a45f // indirect - github.com/labstack/echo/v4 v4.12.0 // indirect - github.com/labstack/gommon v0.4.2 // indirect - github.com/mailru/easyjson v0.7.7 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/oapi-codegen/runtime v1.1.1 // indirect - github.com/perimeterx/marshmallow v1.1.5 // indirect - github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasttemplate v1.2.2 // indirect - golang.org/x/crypto v0.23.0 // indirect - golang.org/x/net v0.25.0 // indirect - golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.20.0 // indirect - golang.org/x/text v0.15.0 // indirect - golang.org/x/time v0.5.0 // indirect google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect google.golang.org/grpc v1.42.0 // indirect google.golang.org/protobuf v1.31.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect - gorm.io/driver/postgres v1.5.9 // indirect - gorm.io/gorm v1.25.11 // indirect ) diff --git a/src/frontend/go.sum b/src/frontend/go.sum index 727a264..e410746 100644 --- a/src/frontend/go.sum +++ b/src/frontend/go.sum @@ -24,15 +24,7 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/getkin/kin-openapi v0.124.0 h1:VSFNMB9C9rTKBnQ/fpyDU8ytMTr4dWI9QovSKj9kz/M= -github.com/getkin/kin-openapi v0.124.0/go.mod h1:wb1aSZA/iWmorQP9KTAS/phLj/t17B5jT7+fS8ed9NM= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-openapi/jsonpointer v0.20.2 h1:mQc3nmndL8ZBzStEo3JYF8wzmeWffDH4VbXz58sAx6Q= -github.com/go-openapi/jsonpointer v0.20.2/go.mod h1:bHen+N0u1KEO3YlmqOjTT9Adn1RfD91Ar825/PuiRVs= -github.com/go-openapi/swag v0.22.8 h1:/9RjDSQ0vbFR+NyjGMkFTsA1IA0fmhKSThmfGZjicbw= -github.com/go-openapi/swag v0.22.8/go.mod h1:6QT22icPLEqAM/z/TChgb4WAveCHF92+2gF0CNjHpPI= -github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= -github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -62,52 +54,9 @@ github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/invopop/yaml v0.2.0 h1:7zky/qH+O0DwAyoobXUqvVBwgBFRxKoQ/3FjcVpjTMY= -github.com/invopop/yaml v0.2.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q= -github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= -github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= -github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= -github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw= -github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A= -github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= -github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= -github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= -github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= -github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= -github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= -github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= -github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE= -github.com/kurtosis-tech/new-obd/src/cartservice v0.0.0-20240731034219-680be220772b h1:aVwiduwK9Ftf4eUt6opv2JPDHQ/31S18FpPdzRdMjp0= -github.com/kurtosis-tech/new-obd/src/cartservice v0.0.0-20240731034219-680be220772b/go.mod h1:XtjDbz/OuRoYbStiAXkZOTZrLbXl4G1EqIM8O/zdI7M= -github.com/kurtosis-tech/new-obd/src/cartservice v0.0.0-20240801133943-e3d868ed94ae h1:AblHB+q/qsiGMCnoy9U2Fp8X2M+GUvhmob6Zaqi5oh0= -github.com/kurtosis-tech/new-obd/src/cartservice v0.0.0-20240801133943-e3d868ed94ae/go.mod h1:XtjDbz/OuRoYbStiAXkZOTZrLbXl4G1EqIM8O/zdI7M= -github.com/kurtosis-tech/new-obd/src/cartservice v0.0.0-20240801144151-c12fae1940c6 h1:zzpvEq7XW722L4eBxOVzpP+wsIchGTpSVLcvWyYHqhQ= -github.com/kurtosis-tech/new-obd/src/cartservice v0.0.0-20240801144151-c12fae1940c6/go.mod h1:XtjDbz/OuRoYbStiAXkZOTZrLbXl4G1EqIM8O/zdI7M= -github.com/kurtosis-tech/new-obd/src/currencyexternalapi v0.0.0-20240731052808-7a2597c080ba h1:O2higo0m5rY8ZI0v1ioyF2XSaVPLVX7Z3FiC0IDzKPk= -github.com/kurtosis-tech/new-obd/src/currencyexternalapi v0.0.0-20240731052808-7a2597c080ba/go.mod h1:RofAgi1WBxLMEGQvNe0grFm0NSOFtHaeWtccTWh7Fss= -github.com/kurtosis-tech/new-obd/src/productcatalogservice v0.0.0-20240731052808-7a2597c080ba h1:oppbrUS9NXh+OyuZmoRanCuiJjJNqApXxxA3GtfNQvE= -github.com/kurtosis-tech/new-obd/src/productcatalogservice v0.0.0-20240731052808-7a2597c080ba/go.mod h1:qt4+YX81O61HhJJcfvGyQvlhXvf+I6p4+OwUI/AVYzY= -github.com/kurtosis-tech/online-boutique-demo/src/currencyexternalapi v0.0.0-20240730171234-cd7da1f8a45f h1:yVGwdnpw3fUvPU2nxrAfT5G57w6UcT4jtWRADmkYW8g= -github.com/kurtosis-tech/online-boutique-demo/src/currencyexternalapi v0.0.0-20240730171234-cd7da1f8a45f/go.mod h1:jlse/HBfIBPlNt1zfsSU2PJ757iC9Y4zB3H1s3xL1e8= -github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0= -github.com/labstack/echo/v4 v4.12.0/go.mod h1:UP9Cr2DJXbOK3Kr9ONYzNowSh7HP0aG0ShAyycHSJvM= -github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= -github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU= -github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= -github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= -github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= -github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro= github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg= -github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s= -github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -124,15 +73,9 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= -github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= -github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= -golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -152,22 +95,16 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= -golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= @@ -205,12 +142,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8= -gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= -gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg= -gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/src/frontend/gomod2nix.toml b/src/frontend/gomod2nix.toml new file mode 100644 index 0000000..4f80fc3 --- /dev/null +++ b/src/frontend/gomod2nix.toml @@ -0,0 +1,39 @@ +schema = 3 + +[mod] + [mod."github.com/apapsch/go-jsonmerge/v2"] + version = "v2.0.0" + hash = "sha256-xp/1B6XUN2EbddBfoUkTV3oTk+34m4kOZP+66HhfLg4=" + [mod."github.com/golang/protobuf"] + version = "v1.5.0" + hash = "sha256-UbjypOyvcr3GwutjMR6Y3kUYcc4F7SjhCrak2PSxRPE=" + [mod."github.com/google/go-cmp"] + version = "v0.5.8" + hash = "sha256-8zkIo+Sr1NXMnj3PNmvjX2sZKnAKWXOFvmnX7D9bwxQ=" + [mod."github.com/google/uuid"] + version = "v1.5.0" + hash = "sha256-DasOte4xANR1VND5XEHKGhpGiyYq74TJmNrgWeIRX4U=" + [mod."github.com/gorilla/mux"] + version = "v1.8.1" + hash = "sha256-nDABvAhlYgxUW2N/brrep7NkQXoSGcHhA+XI4+tK0F0=" + [mod."github.com/oapi-codegen/runtime"] + version = "v1.1.1" + hash = "sha256-GRvzpQngQPAy59KvvcwhjYqjx4gttIhOtQKjqfQcNvI=" + [mod."github.com/pkg/errors"] + version = "v0.9.1" + hash = "sha256-mNfQtcrQmu3sNg/7IwiieKWOgFQOVVe2yXgKBpe/wZw=" + [mod."github.com/sirupsen/logrus"] + version = "v1.8.1" + hash = "sha256-vUIDlLXYBD74+JqdoSx+W3J6r5cOk63heo0ElsHizoM=" + [mod."golang.org/x/sys"] + version = "v0.20.0" + hash = "sha256-mowlaoG2k4n1c1rApWef5EMiXd3I77CsUi8jPh6pTYA=" + [mod."google.golang.org/genproto"] + version = "v0.0.0-20200526211855-cb27e3aa2013" + hash = "sha256-wFVFmWkQLFRBBNTt3C0Dy3GChkYEYnaDLVbQhyq2K1g=" + [mod."google.golang.org/grpc"] + version = "v1.42.0" + hash = "sha256-p97BCecu+L1Lk2/Yj0JEVJP8YVxikOxGw+IbNCsA/go=" + [mod."google.golang.org/protobuf"] + version = "v1.31.0" + hash = "sha256-UdIk+xRaMfdhVICvKRk1THe3R1VU+lWD8hqoW/y8jT0=" diff --git a/src/frontend/handlers.go b/src/frontend/handlers.go index 5d8f5a4..ee9da94 100644 --- a/src/frontend/handlers.go +++ b/src/frontend/handlers.go @@ -17,21 +17,21 @@ package main import ( "context" "fmt" - "github.com/gorilla/mux" - cartservice_rest_types "github.com/kurtosis-tech/new-obd/src/cartservice/api/http_rest/types" - "github.com/kurtosis-tech/new-obd/src/frontend/consts" - "github.com/kurtosis-tech/new-obd/src/frontend/money" - productcatalogservice_rest_types "github.com/kurtosis-tech/new-obd/src/productcatalogservice/api/http_rest/types" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" "html/template" "log" "net/http" "os" "strconv" + "strings" "time" - "strings" + "github.com/gorilla/mux" + cartservice_rest_types "github.com/kurtosis-tech/new-obd/src/cartservice/api/http_rest/types" + "github.com/kurtosis-tech/new-obd/src/frontend/consts" + "github.com/kurtosis-tech/new-obd/src/frontend/money" + productcatalogservice_rest_types "github.com/kurtosis-tech/new-obd/src/productcatalogservice/api/http_rest/types" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) type platformDetails struct { @@ -54,7 +54,6 @@ const ( ) func (fe *frontendServer) homeHandler(w http.ResponseWriter, r *http.Request) { - currencies, err := fe.currencyService.GetSupportedCurrencies(r.Context()) if err != nil { renderHTTPError(r, w, errors.Wrapf(err, "error retrieving currencies"), http.StatusInternalServerError) @@ -151,15 +150,6 @@ func (fe *frontendServer) productHandler(w http.ResponseWriter, r *http.Request) return } - var isPresentFeature bool - experimentalFeaturesResponse, err := fe.cartService.GetExperimentalFeaturesWithResponse(r.Context()) - if err != nil { - logrus.Debugf("It was not possible to get the experimental features from cart service. Error: %s", err.Error()) - } else if experimentalFeaturesResponse.StatusCode() == 200 { - experimentalFeatures := experimentalFeaturesResponse.JSON200 - isPresentFeature = *experimentalFeatures.ProductsPresent - } - product := struct { Item productcatalogservice_rest_types.Product Price *productcatalogservice_rest_types.Money @@ -178,7 +168,7 @@ func (fe *frontendServer) productHandler(w http.ResponseWriter, r *http.Request) "platform_css": plat.css, "platform_name": plat.provider, "is_cymbal_brand": isCymbalBrand, - "is_present_feature": isPresentFeature, + "is_present_feature": false, //"deploymentDetails": deploymentDetailsMap, }); err != nil { log.Println(err) @@ -188,7 +178,6 @@ func (fe *frontendServer) productHandler(w http.ResponseWriter, r *http.Request) func (fe *frontendServer) addToCartHandler(w http.ResponseWriter, r *http.Request) { quantity, _ := strconv.ParseUint(r.FormValue("quantity"), 10, 32) productID := r.FormValue("product_id") - isAPresent := r.FormValue("present") if productID == "" || quantity == 0 { renderHTTPError(r, w, errors.New("invalid form input"), http.StatusBadRequest) return @@ -206,16 +195,10 @@ func (fe *frontendServer) addToCartHandler(w http.ResponseWriter, r *http.Reques quantityInt32 := int32(quantity) userId := userID - var isAPresentBool bool - if isAPresent == "on" { - isAPresentBool = true - } - body := cartservice_rest_types.AddItemRequest{ Item: &cartservice_rest_types.CartItem{ - ProductId: p.Id, - Quantity: &quantityInt32, - IsAPresent: &isAPresentBool, + ProductId: p.Id, + Quantity: &quantityInt32, }, UserId: &userId, } @@ -277,15 +260,6 @@ func (fe *frontendServer) viewCartHandler(w http.ResponseWriter, r *http.Request cartItems := *cart.Items - var isPresentFeature bool - experimentalFeaturesResponse, err := fe.cartService.GetExperimentalFeaturesWithResponse(r.Context()) - if err != nil { - logrus.Debugf("It was not possible to get the experimental features from cart service. Error: %s", err.Error()) - } else if experimentalFeaturesResponse.StatusCode() == 200 { - experimentalFeatures := experimentalFeaturesResponse.JSON200 - isPresentFeature = *experimentalFeatures.ProductsPresent - } - for i, item := range cartItems { productResponse, err := fe.productCatalogService.GetProductsIdWithResponse(r.Context(), *item.ProductId, setKardinalReqEditorFcn) if err != nil { @@ -312,11 +286,6 @@ func (fe *frontendServer) viewCartHandler(w http.ResponseWriter, r *http.Request Price: multPrice, } - if isPresentFeature { - isAPresent := *item.IsAPresent - items[i].IsAPresent = isAPresent - } - totalPrice = money.Must(money.Sum(totalPrice, multPrice)) } @@ -418,7 +387,7 @@ func renderCurrencyLogo(currencyCode string) string { "GBP": "£", } - logo := "$" //default + logo := "$" // default if val, ok := logos[currencyCode]; ok { logo = val } @@ -452,10 +421,9 @@ func cartSize(c []cartservice_rest_types.CartItem) int { } func getSetTraceIdHeaderRequestEditorFcn(upsTreamRequest *http.Request) func(ctx context.Context, req *http.Request) error { - traceID := upsTreamRequest.Header.Get(consts.KardinalTraceIdHeaderKey) - var setKardinalReqEditorFcn = func(ctx context.Context, req *http.Request) error { + setKardinalReqEditorFcn := func(ctx context.Context, req *http.Request) error { req.Header.Set(consts.KardinalTraceIdHeaderKey, traceID) return nil } diff --git a/src/frontend/main.go b/src/frontend/main.go index 8e60bd9..c407993 100644 --- a/src/frontend/main.go +++ b/src/frontend/main.go @@ -2,13 +2,14 @@ package main import ( "fmt" - cartservice_rest_client "github.com/kurtosis-tech/new-obd/src/cartservice/api/http_rest/client" - "github.com/kurtosis-tech/new-obd/src/frontend/currencyexternalservice" - productcatalogservice_rest_client "github.com/kurtosis-tech/new-obd/src/productcatalogservice/api/http_rest/client" "net/http" "os" "time" + cartservice_rest_client "github.com/kurtosis-tech/new-obd/src/cartservice/api/http_rest/client" + "github.com/kurtosis-tech/new-obd/src/frontend/currencyexternalservice" + productcatalogservice_rest_client "github.com/kurtosis-tech/new-obd/src/productcatalogservice/api/http_rest/client" + "github.com/gorilla/mux" "github.com/sirupsen/logrus" ) @@ -24,16 +25,14 @@ const ( cookieCurrency = cookiePrefix + "currency" ) -var ( - whitelistedCurrencies = map[string]bool{ - "USD": true, - "EUR": true, - "CAD": true, - "JPY": true, - "GBP": true, - "TRY": true, - } -) +var whitelistedCurrencies = map[string]bool{ + "USD": true, + "EUR": true, + "CAD": true, + "JPY": true, + "GBP": true, + "TRY": true, +} type ctxKeySessionID struct{} @@ -44,7 +43,6 @@ type frontendServer struct { } func main() { - log := logrus.New() log.Level = logrus.DebugLevel log.Formatter = &logrus.JSONFormatter{ @@ -102,12 +100,11 @@ func main() { handler = &logHandler{log: log, next: handler} // add logging handler = ensureSessionID(handler) // add session ID // handler = tracing(handler) // add opentelemetry instrumentation - //r.Use(otelmux.Middleware(name)) + // r.Use(otelmux.Middleware(name)) r.Use(KardinalTracingContextWrapper) // Start the server http.Handle("/", r) fmt.Println("Server starting on port 8080...") http.ListenAndServe(":8080", handler) - } diff --git a/src/productcatalogservice/consts/consts.go b/src/productcatalogservice/consts/consts.go index 4b1a7be..8ee3f38 100644 --- a/src/productcatalogservice/consts/consts.go +++ b/src/productcatalogservice/consts/consts.go @@ -3,4 +3,3 @@ package consts const ( KardinalTraceIdHeaderKey = "X-Kardinal-Trace-Id" ) - diff --git a/src/productcatalogservice/default.nix b/src/productcatalogservice/default.nix new file mode 100644 index 0000000..7a5b7c1 --- /dev/null +++ b/src/productcatalogservice/default.nix @@ -0,0 +1,14 @@ +{pkgs}: let + pname = "productcatalogservice"; +in + pkgs.buildGoApplication { + # pname has to match the location (folder) where the main function is or use + # subPackges to specify the file (e.g. subPackages = ["some/folder/main.go"];) + inherit pname; + name = "${pname}"; + pwd = ./.; + src = ./.; + modules = ./gomod2nix.toml; + doCheck = false; + CGO_ENABLED = 0; + } diff --git a/src/productcatalogservice/gomod2nix.toml b/src/productcatalogservice/gomod2nix.toml new file mode 100644 index 0000000..76162e0 --- /dev/null +++ b/src/productcatalogservice/gomod2nix.toml @@ -0,0 +1,90 @@ +schema = 3 + +[mod] + [mod."github.com/apapsch/go-jsonmerge/v2"] + version = "v2.0.0" + hash = "sha256-xp/1B6XUN2EbddBfoUkTV3oTk+34m4kOZP+66HhfLg4=" + [mod."github.com/deepmap/oapi-codegen/v2"] + version = "v2.2.1-0.20240604070534-2f0ff757704b" + hash = "sha256-xexjMUdpXoOS9i8dA3MD4mBFHcXSnk9y6iKZfeSXjHg=" + [mod."github.com/getkin/kin-openapi"] + version = "v0.124.0" + hash = "sha256-KHkZXKqtjqAiABE2VGQzOgSxz4imHJeDtXFaePrt5hI=" + [mod."github.com/go-openapi/jsonpointer"] + version = "v0.20.2" + hash = "sha256-z9IZxP+JvJ1WvrHE7qbAZQqJ3XMx1uD0S611shTMna8=" + [mod."github.com/go-openapi/swag"] + version = "v0.22.8" + hash = "sha256-YMJpCbWT9ABlCmuLjxQRwhddlYYqDBWcyDIdnV8bAMc=" + [mod."github.com/golang-jwt/jwt"] + version = "v3.2.2+incompatible" + hash = "sha256-LOkpuXhWrFayvVf1GOaOmZI5YKEsgqVSb22aF8LnCEM=" + [mod."github.com/google/uuid"] + version = "v1.5.0" + hash = "sha256-DasOte4xANR1VND5XEHKGhpGiyYq74TJmNrgWeIRX4U=" + [mod."github.com/invopop/yaml"] + version = "v0.2.0" + hash = "sha256-RxeDuvwOSWYaLc8Q7T39rfFT3bZX3g9Bu0RFwxH6sLw=" + [mod."github.com/josharian/intern"] + version = "v1.0.0" + hash = "sha256-LJR0QE2vOQ2/2shBbO5Yl8cVPq+NFrE3ers0vu9FRP0=" + [mod."github.com/labstack/echo/v4"] + version = "v4.12.0" + hash = "sha256-TPXJv/6C53bnmcEYxa9g5Mft8u/rLT96q64tQ9+RtKU=" + [mod."github.com/labstack/gommon"] + version = "v0.4.2" + hash = "sha256-395+BETDpv15L2lsCiEccwakXgEQxKHlYBAU0Ot3qhY=" + [mod."github.com/mailru/easyjson"] + version = "v0.7.7" + hash = "sha256-NVCz8MURpxgOjHXqxOZExqV4bnpHggpeAOyZDArjcy4=" + [mod."github.com/mattn/go-colorable"] + version = "v0.1.13" + hash = "sha256-qb3Qbo0CELGRIzvw7NVM1g/aayaz4Tguppk9MD2/OI8=" + [mod."github.com/mattn/go-isatty"] + version = "v0.0.20" + hash = "sha256-qhw9hWtU5wnyFyuMbKx+7RB8ckQaFQ8D+8GKPkN3HHQ=" + [mod."github.com/mohae/deepcopy"] + version = "v0.0.0-20170929034955-c48cc78d4826" + hash = "sha256-TQMmKqIYwVhmMVh4RYQkAui97Eyj7poLmcAuDcHXsEk=" + [mod."github.com/oapi-codegen/runtime"] + version = "v1.1.1" + hash = "sha256-GRvzpQngQPAy59KvvcwhjYqjx4gttIhOtQKjqfQcNvI=" + [mod."github.com/perimeterx/marshmallow"] + version = "v1.1.5" + hash = "sha256-fFWjg0FNohDSV0/wUjQ8fBq1g8h6yIqTrHkxqL2Tt0s=" + [mod."github.com/sirupsen/logrus"] + version = "v1.8.1" + hash = "sha256-vUIDlLXYBD74+JqdoSx+W3J6r5cOk63heo0ElsHizoM=" + [mod."github.com/valyala/bytebufferpool"] + version = "v1.0.0" + hash = "sha256-I9FPZ3kCNRB+o0dpMwBnwZ35Fj9+ThvITn8a3Jr8mAY=" + [mod."github.com/valyala/fasttemplate"] + version = "v1.2.2" + hash = "sha256-gp+lNXE8zjO+qJDM/YbS6V43HFsYP6PKn4ux1qa5lZ0=" + [mod."golang.org/x/crypto"] + version = "v0.23.0" + hash = "sha256-6hZjb/OazWFBef0C/aH63l49YQnzCh2vpIduzyfSSG8=" + [mod."golang.org/x/mod"] + version = "v0.17.0" + hash = "sha256-CLaPeF6uTFuRDv4oHwOQE6MCMvrzkUjWN3NuyywZjKU=" + [mod."golang.org/x/net"] + version = "v0.25.0" + hash = "sha256-IjFfXLYNj27WLF7vpkZ6mfFXBnp+7QER3OQ0RgjxN54=" + [mod."golang.org/x/sys"] + version = "v0.20.0" + hash = "sha256-mowlaoG2k4n1c1rApWef5EMiXd3I77CsUi8jPh6pTYA=" + [mod."golang.org/x/text"] + version = "v0.15.0" + hash = "sha256-pBnj0AEkfkvZf+3bN7h6epCD2kurw59clDP7yWvxKlk=" + [mod."golang.org/x/time"] + version = "v0.5.0" + hash = "sha256-W6RgwgdYTO3byIPOFxrP2IpAZdgaGowAaVfYby7AULU=" + [mod."golang.org/x/tools"] + version = "v0.21.0" + hash = "sha256-TU0gAxUX410AYc/nMxxZiaqXeORih1cXbKh3sxKufVg=" + [mod."gopkg.in/yaml.v2"] + version = "v2.4.0" + hash = "sha256-uVEGglIedjOIGZzHW4YwN1VoRSTK8o0eGZqzd+TNdd0=" + [mod."gopkg.in/yaml.v3"] + version = "v3.0.1" + hash = "sha256-FqL9TKYJ0XkNwJFnq9j0VvJ5ZUU1RvH/52h/f5bkYAU="