Commit Graph

932 Commits

Author SHA1 Message Date
Raúl Benencia d12d9f2a01 test_git.sh: declare restore_opts and assign separately
This avoids masking return values. Fixes SC2155. Part of #891.
2024-06-28 11:29:31 -07:00
Raúl Benencia 0e81260572 test_git.sh: use mapfile to split command output
Fixes SC2207. Part of #891.
2024-06-28 11:28:32 -07:00
Raúl Benencia 4f0dc5679b test_git.sh: add quotes to to prevent globbing and word splitting
Fixes SC2086. Part of #891.
2024-06-28 11:28:25 -07:00
Raúl Benencia 6716848f4b test_git.sh: add '-r' to 'read' to avoid mangling backslashes
Fixes SC2162. Part of #891.
2024-06-28 11:24:30 -07:00
Raúl Benencia ae368ba2f1 test_git.sh: use parameter expansion instead of sed
Fixes SC2001. Part of #891.
2024-06-28 11:21:22 -07:00
Raúl Benencia 2ee13eb2bc test_git.sh: quote literal {}
Fixes SC1083. Part of #891.
2024-06-28 10:56:31 -07:00
Raúl Benencia 99d693d647 test_git.sh: replace test regex for glob match
Don't quote rhs of =~, it'll match literally rather than as a
regex. Fixes SC2076. Part of #891.
2024-06-28 07:09:09 -07:00
Kubernetes Prow Robot de02f72cd7
Merge pull request #904 from VICIWUOHA/dev-viciwuoha-fix
Fix Slight Typos In Docs
2024-06-24 16:56:32 -07:00
Raúl Benencia c8089abf31 test_e2e.sh: disable SC2120 for 'caller' function 2024-06-24 16:45:51 -07:00
Raúl Benencia c97fb8ac36 test_e2e.sh: revert explicitly passing parameters to 'caller'
This reverts commit d67c7c6c93.
2024-06-24 16:45:51 -07:00
Raúl Benencia 27a325e9f3 test_e2e.sh: quote $expected_depth 2024-06-24 16:45:51 -07:00
Raúl Benencia 81a4409a04 test_e2e.sh: declare restore_opts and assign separately
This avoids masking return values. Fixes SC2155. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia 3200ee55f6 test_e2e.sh: replace test regex for glob match
Don't quote rhs of =~, it'll match literally rather than as a
regex. Fixes SC2076. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia 9b980c479b test_e2e.sh: use mapfile to split command output
Fixes SC2207. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia 81bb72f296 test_e2e.sh: add exceptions for SC2016
Fixes SC2016. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia 89d568d7d2 test_e2e.sh: Quote literal { }
Fixes SC1083. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia 1346a81e4d test_e2e.sh: Quote the rhs of != in [[ ]] to prevent glob matching
Fixes SC2053. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia 49310e18b6 test_e2e.sh: add '-r' to 'read' to avoid mangling backslashes
Fixes SC2162. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia f41adab119 test_e2e.sh: remove useless cats
Fixes SC2002. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia bfe0a0bc17 test_e2e.sh: add quotes to to prevent word splitting
Fixes SC2046. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia e7a8600806 test_e2e.sh: remove unnecessary $ on arithmetic variables
Fixes SC2004. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia 791aecfc17 test_e2e.sh: explicitly pass parameters to 'caller' function
Fixes SC2120. Part of #891.
2024-06-24 16:45:51 -07:00
VICIWUOHA 28cf42fdaa fix slight typo in v3-to-v4 docs 2024-06-24 23:12:15 +01:00
VICIWUOHA af8126a4a0 fix slight typo in README 2024-06-24 23:11:48 +01:00
Tim Hockin da2d7ca2f2 Shellcheck stage_binaries.sh 2024-06-21 19:52:27 -07:00
Kubernetes Prow Robot eab3f83458
Merge pull request #901 from rul/fix-sc2128
test_e2e.sh: Use index to expand FUNCNAME
2024-06-21 19:20:55 -07:00
Raúl Benencia c8eabb1213 test_e2e.sh: Use index to expand FUNCNAME
Fixes SC2128. Part of #891.
2024-06-21 17:51:23 -07:00
Kubernetes Prow Robot 9d32cb1fed
Merge pull request #900 from sdowell/debian-build-image
use debian build image and bash build scripts
2024-06-21 11:42:55 -07:00
Sam Dowell aece8508b1 ci: switch BUILD_IMAGE from alpine->debian
This is more consistent with the BASEIMAGE OS, and also ships with bash.
2024-06-21 11:24:27 -07:00
Sam Dowell 742b941a6d Reapply "consistently use bash shebang for shell scripts"
This reverts commit 9fac204a9c.
2024-06-21 11:24:27 -07:00
Sam Dowell fe77b4e0c6 Revert "Fix build scripts to be strict sh"
This reverts commit 8ed7195384.
2024-06-21 11:24:27 -07:00
Tim Hockin 1b5c314d00 Fix default-value bug in build.sh 2024-06-21 10:36:33 -07:00
Kubernetes Prow Robot 54491b2011
Merge pull request #896 from thockin/master
Revert 894, fix build scripts to be strict sh
2024-06-21 09:30:55 -07:00
Tim Hockin 8ed7195384
Fix build scripts to be strict sh 2024-06-21 08:59:01 -07:00
Tim Hockin 9fac204a9c
Revert "consistently use bash shebang for shell scripts"
This reverts commit 2c0d32b603.
2024-06-21 08:46:00 -07:00
Kubernetes Prow Robot 650be63833
Merge pull request #894 from sdowell/bash-shebang
consistently use bash shebang for shell scripts
2024-06-20 13:58:40 -07:00
Sam Dowell 2c0d32b603 consistently use bash shebang for shell scripts
This updates the build scripts to use a bash shebang for consistency
with other scripts as well as better portability. If using a non-alpine
BUILDIMAGE (e.g. debian) the build scripts are not valid sh syntax.
2024-06-20 13:23:15 -07:00
Tim Hockin efd8ecf490 Remove e2e debug code 2024-06-19 12:30:13 -07:00
Kubernetes Prow Robot faba6051f4
Merge pull request #892 from rul/fix-e2e-sc2086
test_e2e.sh: quote variables to prevent globbing and word splitting
2024-06-19 11:54:42 -07:00
Raúl Benencia 20c26145ce test_e2e.sh: quote variables to prevent globbing and word splitting
Fixes SC2086.
2024-06-19 10:24:29 -07:00
Raúl Benencia 390f63cc6e test_e2e.sh: fully quote string sent to assert functions
Fixes SC2086. Some strings don't require to be fully quoted, but doing
so anyway to keep code consistency.
2024-06-19 10:13:58 -07:00
Tim Hockin 189a690a5b Add -? to manual 2024-06-13 14:40:14 -07:00
Tim Hockin 28394608e8 Add the idea of "env-flags"
Env-flags are "flags" that can only be set by env var (see caveat below).
All of the real flags have a corresponding env-flag (kind of, but not
really).  The real goal was to deprecate `--password` but keep the env
var as a documented interface.

This does that (though --password still works) and updates the usage and
manual.

This allows some future work to follow the pattern.  We do not register
every CLI flag as an env-flag because the help text would be
duplicative.  This probably wants a wrapper API that allows declaring of
abstract flags, with CLI, env, or both sources.

Caveat:

ACTUALLY, these still have a flag, but the flag is specially named and
hidden.  This makes testing a little easier where passing flags is
handled well but env vars is not.
2024-06-13 14:40:14 -07:00
Tim Hockin aa0f015606 Fix e2e, broken by a docker update I think
github actions fails with an error about "--ip can only be used on
user-defined subnets".  It looks like `--ip` never worked properly, but
wasn't a hard error before.

This is a simpler alternative to
11f475229692da93dff4d8a9337c5fc9cc48e51a (included below), which tried
using docker networks.  It seems to work but is complicated and can leak
resources.  Needs more work.

Instead, this commit just swaps out the `nc` response script
on the fly, rather than restarting `nc` and trying to get the same IP.

```diff
commit 11f475229692da93dff4d8a9337c5fc9cc48e51a
Good "git" signature for thockin@google.com with ED25519 key SHA256:PfQ0rwNUgsu5aRmerT0vkihWn/S3MXY3uoCPUiMdPrg
Author: Tim Hockin <thockin@google.com>
Date:   Wed Jun 12 20:12:54 2024 -0700

    debug test fail

    github actions fails with an error about "--ip can only be used on
    user-defined subnets"

diff --git a/test_e2e.sh b/test_e2e.sh
index d6ad730..b10e895 100755
--- a/test_e2e.sh
+++ b/test_e2e.sh
@@ -117,7 +117,7 @@ function assert_file_lines_ge() {

 function assert_metric_eq() {
     local val
-    val="$(curl --silent "http://localhost:$HTTP_PORT/metrics" \
+    val="$(curl --silent "http://$GITSYNC_IP:$HTTP_PORT/metrics" \
         | grep "^$1 " \
         | awk '{print $NF}')"
     if [[ "${val}" == "$2" ]]; then
@@ -138,6 +138,9 @@ function assert_fail() {
     )
 }

+DOCKER_SUBNET="192.168.0.0/24"
+GITSYNC_IP="192.168.0.254"
+
 # Helper: run a docker container.
 function docker_run() {
     RM="--rm"
@@ -148,6 +151,7 @@ function docker_run() {
         -d \
         ${RM} \
         --label git-sync-e2e="$RUNID" \
+        --network "e2e_$RUNID" \
         "$@"
     sleep 2 # wait for it to come up
 }
@@ -158,7 +162,8 @@ function docker_ip() {
         echo "usage: $0 <id>"
         return 1
     fi
-    docker inspect "$1" | jq -r .[0].NetworkSettings.IPAddress
+    docker inspect "$1" \
+        | jq -r ".[0].NetworkSettings.Networks.e2e_$RUNID.IPAddress"
 }

 function docker_kill() {
@@ -278,7 +283,8 @@ function GIT_SYNC() {
         -i \
         ${RM} \
         --label git-sync-e2e="$RUNID" \
-        --network="host" \
+        --network "e2e_$RUNID" \
+        --ip "$GITSYNC_IP" \
         -u git-sync:$(id -g) `# rely on GID, triggering "dubious ownership"` \
         -v "$ROOT":"$ROOT":rw \
         -v "$REPO":"$REPO":ro \
@@ -308,6 +314,9 @@ function remove_containers() {
         | while read CTR; do
             docker kill "$CTR" >/dev/null
         done
+    docker network prune -f \
+        --filter label=git-sync-e2e \
+        >/dev/null
 }

 #
@@ -2515,7 +2524,7 @@ function e2e::expose_http() {
     # do nothing, just wait for the HTTP to come up
     for i in $(seq 1 5); do
         sleep 1
-        if curl --silent --output /dev/null http://localhost:$HTTP_PORT; then
+        if curl --silent --output /dev/null "http://$GITSYNC_IP:$HTTP_PORT"; then
             break
         fi
         if [[ "$i" == 5 ]]; then
@@ -2524,23 +2533,23 @@ function e2e::expose_http() {
     done

     # check that health endpoint fails
-    if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$HTTP_PORT) -ne 503 ]] ; then
-        fail "health endpoint should have failed: $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$HTTP_PORT)"
+    if [[ $(curl --write-out %{http_code} --silent --output /dev/null "http://$GITSYNC_IP:$HTTP_PORT") -ne 503 ]] ; then
+        fail "health endpoint should have failed: $(curl --write-out %{http_code} --silent --output /dev/null http://$GITSYNC_IP:$HTTP_PORT)"
     fi
     wait_for_sync "${MAXWAIT}"

     # check that health endpoint is alive
-    if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$HTTP_PORT) -ne 200 ]] ; then
+    if [[ $(curl --write-out %{http_code} --silent --output /dev/null "http://$GITSYNC_IP:$HTTP_PORT") -ne 200 ]] ; then
         fail "health endpoint failed"
     fi

     # check that the metrics endpoint exists
-    if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$HTTP_PORT/metrics) -ne 200 ]] ; then
+    if [[ $(curl --write-out %{http_code} --silent --output /dev/null "http://$GITSYNC_IP:$HTTP_PORT/metrics") -ne 200 ]] ; then
         fail "metrics endpoint failed"
     fi

     # check that the pprof endpoint exists
-    if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$HTTP_PORT/debug/pprof/) -ne 200 ]] ; then
+    if [[ $(curl --write-out %{http_code} --silent --output /dev/null "http://$GITSYNC_IP:$HTTP_PORT/debug/pprof/") -ne 200 ]] ; then
         fail "pprof endpoint failed"
     fi
 }
@@ -2568,7 +2577,7 @@ function e2e::expose_http_after_restart() {
     # do nothing, just wait for the HTTP to come up
     for i in $(seq 1 5); do
         sleep 1
-        if curl --silent --output /dev/null http://localhost:$HTTP_PORT; then
+        if curl --silent --output /dev/null "http://$GITSYNC_IP:$HTTP_PORT"; then
             break
         fi
         if [[ "$i" == 5 ]]; then
@@ -2579,7 +2588,7 @@ function e2e::expose_http_after_restart() {
     sleep 2 # wait for first loop to confirm synced

     # check that health endpoint is alive
-    if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$HTTP_PORT) -ne 200 ]] ; then
+    if [[ $(curl --write-out %{http_code} --silent --output /dev/null "http://$GITSYNC_IP:$HTTP_PORT") -ne 200 ]] ; then
         fail "health endpoint failed"
     fi
     assert_link_exists "$ROOT/link"
@@ -3503,6 +3512,12 @@ function run_test() {
         set -o errexit
         set -o nounset
         set -o pipefail
+        docker network prune -f \
+            --filter label=git-sync-e2e \
+            >/dev/null
+        docker network create "e2e_$RUNID" \
+            --subnet "$DOCKER_SUBNET" \
+            --label git-sync-e2e="$RUNID"
         "$@"
     )
     eval "$retvar=$?"
```
2024-06-13 12:30:11 -07:00
Tim Hockin 6ef292034e Log tool versions in e2e 2024-06-13 12:30:11 -07:00
Tim Hockin aa230f92f8 Retool the demo
Rather than hugo, which I really don't know much about and don't care to
maintain, it now is just a trivial HTTP server (python) serving content
from this repo.
2024-06-12 19:13:13 -07:00
Kubernetes Prow Robot e027ef64ac
Merge pull request #883 from thockin/master
Clean up flag-related messages
2024-06-10 14:14:46 -07:00
Tim Hockin 9535f4fe7e Add curl to the image
This allows exechooks to call curl.
2024-06-09 11:24:03 -07:00
Tim Hockin fbc717e620
Clean up flag-related messages 2024-06-09 10:54:19 -07:00
Tim Hockin 750e20e6da Set git `safe.directory` in tool containers
Otherwise it hit the "dubious ownership" case.
2024-06-09 00:57:47 -07:00