Skip to content

Commit

Permalink
third_party/wait-for-it: replace with a simple go program
Browse files Browse the repository at this point in the history
The program doesn't have all the features of wait-for-it, but it
implements the core functionality we need.

For golang/go#61399

Change-Id: Ia5498523e44b74dcd5af1c984521f1a46208d2c5
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/552295
kokoro-CI: kokoro <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Jonathan Amsterdam <[email protected]>
  • Loading branch information
matloob committed Dec 24, 2023
1 parent aba4657 commit 475d4c5
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 540 deletions.
66 changes: 66 additions & 0 deletions devtools/cmd/wait_available/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build unix

package main

import (
"context"
"net"
"os"
"os/exec"
"path/filepath"
"syscall"
"time"

"golang.org/x/pkgsite/internal/log"
)

var timeout = 15 * time.Second

func main() {
ctx := context.Background()

if len(os.Args) < 2 {
log.Fatalf(ctx, "expected at least one argument; got none")
}
hostport := os.Args[1]
var command []string

if len(os.Args) > 2 {
if os.Args[2] != "--" {
log.Fatalf(ctx, "expected second argument to be \"--\"; got %q", os.Args[2])
}
command = os.Args[3:]
}

start := time.Now()
for {
if time.Since(start) > timeout {
break
}
if conn, err := net.DialTimeout("tcp", hostport, 1*time.Second); err != nil {
time.Sleep(1 * time.Second)
continue
} else {
conn.Close()
break
}
}
var err error
binpath := command[0]
if !filepath.IsAbs(binpath) {
binpath, err = exec.LookPath(command[0])
if err != nil {
log.Fatalf(ctx, "looking up err: %v", err)
}
}
if len(command) > 0 {
err := syscall.Exec(binpath, command, os.Environ())
if err != nil {
log.Fatalf(ctx, "exec-ing binary: %v", err)
}
}
}
10 changes: 5 additions & 5 deletions devtools/docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ services:
# TERM is set to xterm-256color for use by devtools/lib.sh.
TERM: xterm-256color
WAITFORIT_TIMEOUT: 300
entrypoint: ./third_party/wait-for-it/wait-for-it.sh db:5432 -- ./all.bash
entrypoint: go run ./devtools/cmd/wait_available db:5432 -- ./all.bash
volumes:
- ../../:/pkgsite
working_dir: /pkgsite
Expand All @@ -49,7 +49,7 @@ services:
environment:
<<: [*database-variables, *go-variables]
WAITFORIT_TIMEOUT: 300
entrypoint: ./third_party/wait-for-it/wait-for-it.sh frontend:8080 -- go run
entrypoint: go run ./devtools/cmd/wait_available frontend:8080 -- go run
command: "tests/search/main.go -frontend http://frontend:8080"
volumes:
- ../../:/pkgsite
Expand All @@ -61,7 +61,7 @@ services:
environment:
<<: *go-variables
WAITFORIT_TIMEOUT: 300
entrypoint: ./third_party/wait-for-it/wait-for-it.sh frontend:8080 -- go run
entrypoint: go run ./devtools/cmd/wait_available frontend:8080 -- go run
command: "tests/api/main.go -frontend http://frontend:8080 -all compare "
volumes:
- ../../:/pkgsite
Expand All @@ -72,7 +72,7 @@ services:
depends_on:
- db
command: bash -c "
./third_party/wait-for-it/wait-for-it.sh db:5432 --
go run ./devtools/cmd/wait_available db:5432 --
go run ./devtools/cmd/db/main.go create &&
go run ./devtools/cmd/db/main.go migrate &&
go run ./cmd/frontend -host=0.0.0.0:8080"
Expand All @@ -94,7 +94,7 @@ services:
# time seeddb runs. If this ends up being flaky, we should add a check here.
command: bash -c "
echo GO_DISCOVERY_CONFIG_DYNAMIC=$GO_DISCOVERY_CONFIG_DYNAMIC &&
./third_party/wait-for-it/wait-for-it.sh db:5432 --
go run ./devtools/cmd/wait_available db:5432 --
go run ./devtools/cmd/db/main.go create &&
go run ./devtools/cmd/db/main.go migrate &&
go run ./devtools/cmd/seeddb/main.go -seed ${GO_DISCOVERY_SEED_DB_FILE:-seed.txt}"
Expand Down
2 changes: 1 addition & 1 deletion tests/screentest/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ main() {
dcompose run --rm --entrypoint bash go -c "
export WAITFORIT_TIMEOUT=120
go install golang.org/x/website/cmd/screentest@latest
./third_party/wait-for-it/wait-for-it.sh frontend:8080 --
go run ./devtools/cmd/wait_available frontend:8080 --
$(echo $cmd)"
elif [ "$env" = local ]; then
if ! nc -z localhost 9222; then
Expand Down
3 changes: 0 additions & 3 deletions third_party/wait-for-it/.gitignore

This file was deleted.

7 changes: 0 additions & 7 deletions third_party/wait-for-it/.travis.yml

This file was deleted.

20 changes: 0 additions & 20 deletions third_party/wait-for-it/LICENSE

This file was deleted.

78 changes: 0 additions & 78 deletions third_party/wait-for-it/README.md

This file was deleted.

7 changes: 0 additions & 7 deletions third_party/wait-for-it/composer.json

This file was deleted.

18 changes: 0 additions & 18 deletions third_party/wait-for-it/test/README.md

This file was deleted.

35 changes: 0 additions & 35 deletions third_party/wait-for-it/test/container-runners.py

This file was deleted.

2 changes: 0 additions & 2 deletions third_party/wait-for-it/test/requirements.txt

This file was deleted.

Loading

0 comments on commit 475d4c5

Please sign in to comment.