set dotenv-load kubectl := "bazel run --config=quiet //hack/tools:kubectl --" database_username := "${DATABASE_USERNAME:-edge-user}" database_host := "${DATABASE_HOST:-localhost}" database_port := "${DATABASE_PORT:-5432}" database_name := "${DATABASE_NAME:-edge-db}" database_password := "${DATABASE_PASSWORD:-Pa55word}" # Creates a postgres docker container to be used for L2 integration tests up: docker run \ --name postgres \ --restart unless-stopped \ -p "{{ database_port }}:5432" \ -e "POSTGRES_PASSWORD={{ database_password }}" \ -e "POSTGRES_USER={{ database_username }}" \ -e "POSTGRES_DB={{ database_name }}" \ -d \ postgres # Updates your test/config.json with appropriate connection details for the postgres container update-config: #!/usr/bin/env bash set -euo pipefail # jq does not support update file in place, mimick this behaviour using a # temp file and move tempfile=$(mktemp) # - Generate the expected configuration from the supplied env var ($want jq var) # - Check if this will overwrite any existing config in config.json # - (. + $want) != ($want + .) (addition is not commutative in jq, so the resulting dicts will be different if addition is done in a different order when overwriting data) # - Return error and leave file unchanged if existing data will be overwrittend # - Otherwise populate temp file and move into place # # Want to update file in place if it is present, otherwise create new file ( cat ../../test/config.json 2>/dev/null || echo '{}' ) | \ jq \ --argjson level 2 \ --arg username "{{ database_username }}" \ --argjson port "{{ database_port }}" \ --arg name "{{ database_name }}" \ --arg host "{{ database_host }}" \ --arg password "{{ database_password }}" \ '{ "integration-level": $level, "postgres-database": $name, "postgres-user": $username, "postgres-pass": $password, "postgres-port": $port, "postgres-host": $host, "postgres-k8s-host": "postgres.dockerhost.svc.cluster.local." } as $want | if (. + $want) != ($want + .) then "\nERROR: This will overwrite existing config.json values. Please manually update your config.json with the following contents\n\n" + ($want | tostring) + "\n" | halt_error else (. + $want) end' - > $tempfile && mv $tempfile ../../test/config.json || rm $tempfile # The following uses https://github.com/kubernetes-sigs/kind/issues/1200#issuecomment-1304855791 # k8s gives access to the host's docker from within the k8s cluster. k8s: @just {{ if os() == "linux" { "_k8s-linux" } else if os() == "macos" { "_k8s-macos" } else { '_k8s-unsupported' } }} _k8s-unsupported: echo currently this platform ({{ os() }}) is unsupported && exit 1 _k8s-linux: #!/usr/bin/env bash just ../kind/ensure-kind dockerip="$(docker network inspect bridge | jq -r '.[0].IPAM.Config | .[0].Gateway')" sed -e 's/DOCKERIP/'"$dockerip"'/g' -e 's/DATABASE_PORT/'"{{ database_port }}"'/g' service-linux.yaml | kubectl apply -f - _k8s-macos: #!/usr/bin/env bash just ../kind/ensure-kind sed 's/DATABASE_PORT/'"{{ database_port }}"'/g' service-macos.yaml | kubectl apply -f -