Initial commit
This commit is contained in:
commit
1242422d8d
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.direnv
|
||||
result
|
93
flake.lock
Normal file
93
flake.lock
Normal file
|
@ -0,0 +1,93 @@
|
|||
{
|
||||
"nodes": {
|
||||
"devshell": {
|
||||
"locked": {
|
||||
"lastModified": 1642188268,
|
||||
"narHash": "sha256-DNz4xScpXIn7rSDohdayBpPR9H9OWCMDOgTYegX081k=",
|
||||
"owner": "numtide",
|
||||
"repo": "devshell",
|
||||
"rev": "696acc29668b644df1740b69e1601119bf6da83b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "devshell",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"locked": {
|
||||
"lastModified": 1642700792,
|
||||
"narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "846b2ae0fc4cc943637d3d1def4454213e203cba",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1642768189,
|
||||
"narHash": "sha256-XuUHXFzJWuSDo7dzpjTbHrjk37lAdTyk05sypXsqv1g=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "e31e42dfdee3922a618b37c6d5f55603c24d86a0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "release-21.11",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs20-09": {
|
||||
"locked": {
|
||||
"lastModified": 1636935165,
|
||||
"narHash": "sha256-J4smKTYTp8wJ57znUerWlS/QRgp0jcm/StcfIhsa5eA=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "f7949198dcff52265b322ca8abf7450610e7e49e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "release-20.09",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgsFork": {
|
||||
"locked": {
|
||||
"lastModified": 1642702126,
|
||||
"narHash": "sha256-HCrmCGLevYgpUM3isFC3iZqZnU5XMeML0pXN6jvV8ig=",
|
||||
"owner": "teutat3s",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "5215a609d5b08e33b9f431a6d8475078e3758de0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "teutat3s",
|
||||
"ref": "feature/triton-completion",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"devshell": "devshell",
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"nixpkgs20-09": "nixpkgs20-09",
|
||||
"nixpkgsFork": "nixpkgsFork"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
130
flake.nix
Normal file
130
flake.nix
Normal file
|
@ -0,0 +1,130 @@
|
|||
{
|
||||
description = "Development environment for nix'ing with triton";
|
||||
|
||||
inputs.devshell.url = "github:numtide/devshell";
|
||||
inputs.flake-utils.url = "github:numtide/flake-utils";
|
||||
inputs.nixpkgs.url = "github:nixos/nixpkgs/release-21.11";
|
||||
inputs.nixpkgsFork.url = "github:teutat3s/nixpkgs/feature/triton-completion";
|
||||
inputs.nixpkgs20-09.url = "github:nixos/nixpkgs/release-20.09";
|
||||
|
||||
outputs = { self, flake-utils, devshell, nixpkgs, nixpkgsFork, nixpkgs20-09 }:
|
||||
flake-utils.lib.eachDefaultSystem (system: {
|
||||
packages.triton-utils =
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
};
|
||||
in
|
||||
pkgs.stdenv.mkDerivation {
|
||||
pname = "triton-utils";
|
||||
version = "0.0.1";
|
||||
src = pkgs.lib.cleanSource ./.;
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin $out/share/certs
|
||||
cd ./utils
|
||||
cp ./cacert-2021-10-26.pem $out/share/certs
|
||||
cp ./triton-docker.env.sh $out/bin
|
||||
cp ./ttp.sh $out/bin
|
||||
cp ./unset-env.sh $out/bin
|
||||
'';
|
||||
};
|
||||
devShell =
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
|
||||
overlays = [ devshell.overlay ];
|
||||
};
|
||||
pkgsFork = import nixpkgsFork {
|
||||
inherit system;
|
||||
|
||||
overlays = [ devshell.overlay ];
|
||||
};
|
||||
pkgs20-09 = import nixpkgs20-09 {
|
||||
inherit system;
|
||||
|
||||
overlays = [ devshell.overlay ];
|
||||
};
|
||||
in
|
||||
pkgs.devshell.mkShell {
|
||||
name = "tritonshell";
|
||||
|
||||
devshell.interactive = {
|
||||
PS1_util = pkgs.lib.noDepEntry ''
|
||||
if [[ -n "''${PRJ_ROOT:-}" ]]; then
|
||||
# Print the path relative to $PRJ_ROOT
|
||||
rel_root() {
|
||||
local path
|
||||
path=$(${pkgs.coreutils}/bin/realpath --relative-to "$PRJ_ROOT" "$PWD")
|
||||
if [[ $path != . ]]; then
|
||||
echo " $path "
|
||||
fi
|
||||
}
|
||||
else
|
||||
# If PRJ_ROOT is unset, print only the current directory name
|
||||
rel_root() {
|
||||
echo " \W "
|
||||
}
|
||||
fi
|
||||
'';
|
||||
PS1.text = ''
|
||||
PS1='\[\033[38;5;202m\][$TRITON_PROFILE@tritonshell]$(rel_root)\$ \[\033[0m\]'
|
||||
'';
|
||||
};
|
||||
|
||||
commands = [
|
||||
{
|
||||
package = pkgs.devshell.cli;
|
||||
help = "Per project developer environments";
|
||||
}
|
||||
{
|
||||
package = pkgsFork.nodePackages.triton;
|
||||
category = "triton & manta tools";
|
||||
name = "triton";
|
||||
help = "Triton DC CLI (https://docs.joyent.com/public-cloud/api/triton-cli)";
|
||||
}
|
||||
{
|
||||
package = pkgsFork.nodePackages.manta;
|
||||
category = "triton & manta tools";
|
||||
name = "manta";
|
||||
help = "Manta CLI (https://apidocs.joyent.com/manta/index.html#cli)";
|
||||
}
|
||||
];
|
||||
|
||||
devshell.packages = [
|
||||
pkgs.bash-completion
|
||||
# use docker-compose version 1.26.2 for best triton API compatibility
|
||||
pkgs20-09.docker-compose
|
||||
# used in ./utils/triton-docker.env.sh
|
||||
pkgs.nodePackages.json
|
||||
self.packages.${system}.triton-utils
|
||||
];
|
||||
|
||||
env = [
|
||||
# workaround for TLS certs bug in docker-compose, CERTIFICATE_VERIFY_FAILED
|
||||
# see: https://github.com/joyent/triton-docker-cli/issues/17
|
||||
{
|
||||
name = "CURL_CA_BUNDLE";
|
||||
value = "${self.packages.${system}.triton-utils}/share/certs/cacert-2021-10-26.pem";
|
||||
}
|
||||
{
|
||||
name = "NOMAD_ADDR";
|
||||
value = "https://nomad.service.consul:4646";
|
||||
}
|
||||
{
|
||||
name = "VAULT_ADDR";
|
||||
value = "https://nomad.service.consul:8200";
|
||||
}
|
||||
];
|
||||
|
||||
bash = {
|
||||
extra = ''
|
||||
source ${self.packages.${system}.triton-utils}/bin/triton-docker.env.sh
|
||||
source ${self.packages.${system}.triton-utils}/bin/ttp.sh
|
||||
source ${pkgsFork.nodePackages.manta}/share/bash-completion/completions/manta
|
||||
'';
|
||||
};
|
||||
};
|
||||
});
|
||||
}
|
3232
utils/cacert-2021-10-26.pem
Normal file
3232
utils/cacert-2021-10-26.pem
Normal file
File diff suppressed because it is too large
Load diff
24
utils/triton-docker.env.sh
Normal file
24
utils/triton-docker.env.sh
Normal file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env bash
|
||||
# script to set the docker, triton, manta and CNS env vars for the current triton profile
|
||||
|
||||
# set triton and docker host environment variables
|
||||
eval "$(triton env)"
|
||||
|
||||
# get the user's UUID
|
||||
triton_account_uuid="$(triton account get --json | json id)"
|
||||
|
||||
# set the CNS (container name service) base for auto-generated DNS records
|
||||
# in public and private networks
|
||||
# note, this makes assumptions that only work with Greenbaum's public cloud
|
||||
if env | grep -q "SDC_URL=https://api.greenbaum.cloud"; then
|
||||
export TRITON_CNS_SEARCH_DOMAIN_PUBLIC="${triton_account_uuid}.cgn-1.greenbaum.zone"
|
||||
export TRITON_CNS_SEARCH_DOMAIN_PRIVATE="${triton_account_uuid}.cgn-1.int.greenbaum.zone"
|
||||
fi
|
||||
if env | grep -q "SDC_URL=https://lev-1.api.greenbaum.cloud"; then
|
||||
export TRITON_CNS_SEARCH_DOMAIN_PUBLIC="${triton_account_uuid}.lev-1.greenbaum.zone"
|
||||
export TRITON_CNS_SEARCH_DOMAIN_PRIVATE="${triton_account_uuid}.lev-1.int.greenbaum.zone"
|
||||
fi
|
||||
|
||||
export MANTA_URL=https://eu-central.manta.greenbaum.cloud
|
||||
export MANTA_USER=$SDC_ACCOUNT
|
||||
export MANTA_KEY_ID=$SDC_KEY_ID
|
30
utils/ttp.sh
Normal file
30
utils/ttp.sh
Normal file
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env bash
|
||||
# helper function to set the docker, triton, manta and CNS env vars for the current triton profile
|
||||
ttp() {
|
||||
if [[ "$1" == "set" ]]; then
|
||||
if [[ -n "$2" ]]; then
|
||||
source unset-env.sh
|
||||
triton profile set "$2"
|
||||
fi
|
||||
source triton-docker.env.sh
|
||||
elif [[ "$1" == "unset" ]]; then
|
||||
source unset-env.sh
|
||||
elif [[ "$1" == "env" ]]; then
|
||||
env | grep "DOCKER\|MANTA\|SDC\|TRITON" | sort
|
||||
else
|
||||
echo "this is a helper function to quickly switch triton profiles"
|
||||
echo "and setup the required environment variables"
|
||||
echo "for triton, manta and the remote docker host (API)"
|
||||
echo
|
||||
echo 'use "ttp set your-profile" to switch to a profile'
|
||||
echo
|
||||
echo 'use "ttp unset" to clear all environment variables used by these CLIs'
|
||||
echo "useful if you'd like to run a docker command against the"
|
||||
echo "local docker host"
|
||||
echo
|
||||
echo 'use "ttp env" to view the currently set environment variables'
|
||||
echo "used by the triton & manta CLIs"
|
||||
echo
|
||||
echo 'use "ttp help" to view this help'
|
||||
fi
|
||||
}
|
9
utils/unset-env.sh
Normal file
9
utils/unset-env.sh
Normal file
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
# script to unset the docker, triton, manta and CNS env vars for the current triton profile
|
||||
|
||||
# make sure we're starting in a "clean" environment
|
||||
unset TRITON_PROFILE
|
||||
unset DOCKER_CERT_PATH DOCKER_HOST DOCKER_TLS_VERIFY COMPOSE_HTTP_TIMEOUT
|
||||
unset SDC_URL SDC_ACCOUNT SDC_KEY_ID
|
||||
unset TRITON_CNS_SEARCH_DOMAIN_PUBLIC TRITON_CNS_SEARCH_DOMAIN_PRIVATE
|
||||
unset MANTA_URL MANTA_USER MANTA_KEY_ID
|
Loading…
Reference in a new issue