diff --git a/stdlib/.dagger/env/http/values.yaml b/stdlib/.dagger/env/http/values.yaml index 76b6c328..7ef0dfa9 100644 --- a/stdlib/.dagger/env/http/values.yaml +++ b/stdlib/.dagger/env/http/values.yaml @@ -1,6 +1,10 @@ plan: package: ./http/tests name: http +inputs: + TestDockersocket: + socket: + unix: /var/run/docker.sock sops: kms: [] gcp_kms: [] @@ -16,8 +20,8 @@ sops: NHkxc1VXWHBwZFN5WFNxamdPaGZLM3MKaZra2gWvKl7+pXSihV70/mQYel9697z2 eBSMuRPuZSjrg3JCBLhXTdIgUYxbMgWhILLpN5UqhTBVboUlRsURQA== -----END AGE ENCRYPTED FILE----- - lastmodified: "2021-10-19T11:50:42Z" - mac: ENC[AES256_GCM,data:iG/JWnCk8UpThscQBqd9l7R7k1Xae1ED7WbYqPQmK5GRXhb7hIZGENnjn1aARnFjlCtEob6WvutWaZe7q1P90ZCirwXVBGewAeHchHqFA0KmUORRdtjMkZjnlRLMDKYu6CeNkaVK1al+B87CPlCBKz5UMeL9gnvug0k298AxWLY=,iv:RZEtSdbkxwgq5xEucnC+qyD2RCMk1DuaShjCh5Ihe5M=,tag:swW4R7ni0zoxOrc9lrV9Ww==,type:str] + lastmodified: "2021-11-23T17:30:31Z" + mac: ENC[AES256_GCM,data:R82VFQG+vtFoH/H4R3TGfFzcmEBLRWv81/pfbYIoWGTH3iFmVgfiCXuqF2O4suhG6mlmiGVDCFBBGPfFvOIBPSwbAqOoNQrM+pXPk3nrm3KY6RLSiByZX3yS1G2HHzGSbQVDuxlTBGyXhpJZs1ZgysZguHUqtunbrjSpD4+iWE8=,iv:LhTwB1QKXCXz9tu03d5NHIv/Jwrgg3LXQYafXykFz/o=,tag:h0mgHTyfxflAuv/uYuRibw==,type:str] pgp: [] encrypted_suffix: secret version: 3.7.1 diff --git a/stdlib/cue.mod/pkg/.gitignore b/stdlib/cue.mod/pkg/.gitignore index a572e9ee..2d4dc1ae 100644 --- a/stdlib/cue.mod/pkg/.gitignore +++ b/stdlib/cue.mod/pkg/.gitignore @@ -1,2 +1,3 @@ -# dagger universe +# generated by dagger alpha.dagger.io +dagger.lock diff --git a/stdlib/http/http.cue b/stdlib/http/http.cue index d5b99145..b7b7f898 100644 --- a/stdlib/http/http.cue +++ b/stdlib/http/http.cue @@ -6,6 +6,7 @@ import ( "alpha.dagger.io/alpine" "alpha.dagger.io/dagger" + "alpha.dagger.io/dagger/op" "alpha.dagger.io/os" ) @@ -84,3 +85,70 @@ import ( "statusCode": strconv.Atoi(statusCode) } } + +// URL listener +// Creates a dependency on URL +#Wait: { + // URL to listen + url: string + + // Waiting time between checks (sec.) + interval: int | *30 + + // Max amount of retries + retries: int | *3 + + // Max initialization time (sec.) + startPeriod: int | *0 + + // Time until timeout (sec.) + timeout: int | *30 + + #up: [ + op.#Load & { + from: alpine.#Image & { + package: bash: "=~5.1" + package: curl: true + } + }, + op.#Exec & { + args: ["/bin/bash", "-c", + #""" + # (f: str -> int) + nb_retries=$(($NB_RETRIES+0)) + starting_period=$(($START_PERIOD+0)) + + status="0" + SECONDS=0 + # START_PERIOD implementation + while [ $SECONDS -lt $starting_period ]; do + status="$(curl --connect-timeout 1 -s -o /dev/null -w ''%{http_code}'' $HEALTH_URL)" + if [ "$status" == "200" ]; then + exit 0; + fi + sleep 1; + done + + # TIMEOUT, INTERVAL, INTERVAL implementation + for ((i=0;i/dev/null test "$STATUS" = "200" """# +} \ No newline at end of file diff --git a/stdlib/universe.bats b/stdlib/universe.bats index 86dbeec2..acac71eb 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -24,7 +24,9 @@ setup() { } @test "http" { - dagger -e http up + dagger -e http up + CONTAINER=$(docker container ls -q --filter "name=daggerci-test-wait-*") + docker stop "$CONTAINER" && docker rm "$CONTAINER" } @test "js/yarn" {