From 75170c2b0ac46c8c3fc93cb6db09e08075c953ff Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Sat, 26 Oct 2024 06:41:52 +0900 Subject: [PATCH 1/2] chore: fix scripts to create private registries --- cmdx.yaml | 15 +++++++-------- scripts/build_image.sh | 4 +++- scripts/check_image.sh | 5 +++-- scripts/checkout.sh | 4 +++- scripts/connect.sh | 10 ++++++---- scripts/exist_container.sh | 5 +++-- scripts/get_pkg_from_branch.sh | 2 +- scripts/is_build_image.sh | 4 +++- scripts/is_container_running.sh | 3 ++- scripts/new.sh | 9 +++++++++ scripts/remove_container.sh | 5 ++++- scripts/rm.sh | 11 ++++++----- scripts/run.sh | 5 +++-- scripts/scaffold.sh | 10 ++++++---- scripts/start.sh | 24 ++++++++++++++++-------- scripts/stop.sh | 6 +++++- scripts/test-windows.sh | 10 ++++++---- scripts/test.sh | 11 ++++++----- scripts/var.sh | 9 +++++++++ 19 files changed, 101 insertions(+), 51 deletions(-) create mode 100644 scripts/new.sh create mode 100644 scripts/var.sh diff --git a/cmdx.yaml b/cmdx.yaml index ca284688841..d2593cda22e 100644 --- a/cmdx.yaml +++ b/cmdx.yaml @@ -57,7 +57,7 @@ tasks: aqua exec -- cmdx gr bash scripts/commit.sh "$PACKAGE" bash scripts/test.sh "$PACKAGE" - bash scripts/start.sh aqua-registry-windows + bash scripts/start.sh windows bash scripts/test-windows.sh "$PACKAGE" args: - name: package @@ -101,7 +101,7 @@ tasks: fi bash scripts/start.sh bash scripts/test.sh "$PACKAGE" - bash scripts/start.sh aqua-registry-windows + bash scripts/start.sh windows bash scripts/test-windows.sh "$PACKAGE" aqua exec -- aqua-registry gr @@ -158,9 +158,8 @@ tasks: $ cmdx new cli/cli script: | set -eu - bash scripts/check_diff_package.sh - pkg=$(bash scripts/get_pkg_from_branch.sh "$PACKAGE") - aqua exec -- aqua-registry create-pr-new-pkg "$pkg" + + bash scripts/new.sh args: - name: package usage: a package name. e.g. cli/cli @@ -176,7 +175,7 @@ tasks: script: | set -eu bash scripts/stop.sh - bash scripts/stop.sh aqua-registry-windows + bash scripts/stop.sh windows - name: remove short: rm @@ -188,7 +187,7 @@ tasks: script: | set -eu bash scripts/remove_container.sh - bash scripts/remove_container.sh aqua-registry-windows + bash scripts/remove_container.sh windows - name: start usage: Start containers @@ -212,7 +211,7 @@ tasks: cmdx rm fi bash scripts/start.sh - bash scripts/start.sh aqua-registry-windows + bash scripts/start.sh windows - name: release short: r diff --git a/scripts/build_image.sh b/scripts/build_image.sh index 27c3db8071a..6c96ca4e089 100644 --- a/scripts/build_image.sh +++ b/scripts/build_image.sh @@ -2,7 +2,9 @@ set -eu +. "$(dirname "$0")/var.sh" + cp aqua-policy.yaml docker -docker build -t aquaproj/aqua-registry docker +docker build -t "$image" docker mkdir -p .build cp docker/Dockerfile .build diff --git a/scripts/check_image.sh b/scripts/check_image.sh index 26532a009cd..2247f6078e1 100644 --- a/scripts/check_image.sh +++ b/scripts/check_image.sh @@ -2,9 +2,10 @@ set -euo pipefail -container_name=${1:-aqua-registry} +. "$(dirname "$0")/var.sh" +container_name=${1:-$container} container_image_id=$(docker inspect "$container_name" | aqua exec -- jq -r ".[].Image") -image_id=$(docker inspect aquaproj/aqua-registry | aqua exec -- jq -r ".[].Id") +image_id=$(docker inspect "$image" | aqua exec -- jq -r ".[].Id") [ "$container_image_id" = "$image_id" ] diff --git a/scripts/checkout.sh b/scripts/checkout.sh index a6eb7139d5c..c8ab9ade6dc 100644 --- a/scripts/checkout.sh +++ b/scripts/checkout.sh @@ -2,6 +2,8 @@ set -eu +. "$(dirname "$0")/var.sh" + if [ "$NO_CREATE_BRANCH" = true ]; then exit 0 fi @@ -16,7 +18,7 @@ fi temp_remote="temp-remote-$(date +%Y%m%d%H%M%S)" -git remote add "$temp_remote" https://github.com/aquaproj/aqua-registry +git remote add "$temp_remote" "$upstream" git fetch "$temp_remote" main git checkout -b "feat/$pkg" "$temp_remote/main" git remote remove "$temp_remote" diff --git a/scripts/connect.sh b/scripts/connect.sh index ca7e0d7165a..70d23a9165f 100644 --- a/scripts/connect.sh +++ b/scripts/connect.sh @@ -2,6 +2,11 @@ set -eu +. "$(dirname "$0")/var.sh" +if [ "$OS" = windows ]; then + container=$container_windows +fi + if [ -z "${ARCH:-}" ]; then ARCH=$(uname -m) case $ARCH in @@ -9,10 +14,7 @@ if [ -z "${ARCH:-}" ]; then aarch64) ARCH="arm64" ;; esac fi -container=aqua-registry -if [ "$OS" = windows ]; then - container=aqua-registry-windows -fi + echo "[INFO] Connecting to the container $container ($OS/$ARCH)" >&2 # Workaround to fix the symbolic link to aqua-proxy diff --git a/scripts/exist_container.sh b/scripts/exist_container.sh index 554bbec08f8..24ce7224fb9 100644 --- a/scripts/exist_container.sh +++ b/scripts/exist_container.sh @@ -2,7 +2,8 @@ set -euo pipefail -container_name=${1:-aqua-registry} +. "$(dirname "$0")/var.sh" echo "[INFO] Checking if the container $container_name exists" >&2 -docker ps -a --filter "name=$container_name" --format "{{.Names}}" | grep -E "^$container_name$" >/dev/null +docker ps -a --filter "name=$container_name" --format "{{.Names}}" | + grep -E "^$container_name$" >/dev/null diff --git a/scripts/get_pkg_from_branch.sh b/scripts/get_pkg_from_branch.sh index 0a8a88a1887..5791cb1e497 100644 --- a/scripts/get_pkg_from_branch.sh +++ b/scripts/get_pkg_from_branch.sh @@ -21,4 +21,4 @@ if [ -n "$pkg" ]; then exit 0 fi -echo ${current_branch#feat/} +echo "${current_branch#feat/}" diff --git a/scripts/is_build_image.sh b/scripts/is_build_image.sh index c335a12e28a..17ea25427ac 100644 --- a/scripts/is_build_image.sh +++ b/scripts/is_build_image.sh @@ -2,7 +2,9 @@ set -eu -if ! docker inspect aquaproj/aqua-registry >/dev/null; then +. "$(dirname "$0")/var.sh" + +if ! docker inspect "$image" >/dev/null; then # image doesn't exist exit 1 fi diff --git a/scripts/is_container_running.sh b/scripts/is_container_running.sh index 2a2b7226bf6..3f3144d2735 100644 --- a/scripts/is_container_running.sh +++ b/scripts/is_container_running.sh @@ -2,7 +2,8 @@ set -euo pipefail -container_name=${1:-aqua-registry} +. "$(dirname "$0")/var.sh" +container_name=${1:-$container} echo "[INFO] Checking if the container $container_name is running" >&2 docker ps -a \ diff --git a/scripts/new.sh b/scripts/new.sh new file mode 100644 index 00000000000..6be167ec8bd --- /dev/null +++ b/scripts/new.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -eu + +. "$(dirname "$0")/var.sh" + +bash scripts/check_diff_package.sh +pkg=$(bash scripts/get_pkg_from_branch.sh "$PACKAGE") +aqua exec -- "$container" create-pr-new-pkg "$pkg" diff --git a/scripts/remove_container.sh b/scripts/remove_container.sh index d6ccb1ba6fb..4d08c171c4a 100644 --- a/scripts/remove_container.sh +++ b/scripts/remove_container.sh @@ -2,7 +2,10 @@ set -eu -container=${1:-aqua-registry} +. "$(dirname "$0")/var.sh" +if [ "${1:-}" = windows ]; then + container=$container_windows +fi if bash scripts/exist_container.sh "$container"; then docker stop -t 1 "$container" diff --git a/scripts/rm.sh b/scripts/rm.sh index 336ac19ab6e..a7a242d4196 100644 --- a/scripts/rm.sh +++ b/scripts/rm.sh @@ -2,12 +2,13 @@ set -eu +. "$(dirname "$0")/var.sh" if bash scripts/exist_container.sh; then - docker stop -t 1 aqua-registry - docker rm aqua-registry + docker stop -t 1 "$container" + docker rm "$container" fi -if bash scripts/exist_container.sh aqua-registry-windows; then - docker stop -t 1 aqua-registry-windows - docker rm aqua-registry-windows +if bash scripts/exist_container.sh "$container_windows"; then + docker stop -t 1 "$container_windows" + docker rm "$container_windows" fi diff --git a/scripts/run.sh b/scripts/run.sh index fa84c55a217..bc9f7a4270c 100644 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -2,7 +2,8 @@ set -euo pipefail -container_name=${1:-aqua-registry} +. "$(dirname "$0")/var.sh" +container_name=${1:-$container} token="${AQUA_GITHUB_TOKEN:-${GITHUB_TOKEN:-}}" if [ -z "$token" ]; then @@ -23,5 +24,5 @@ fi # shellcheck disable=SC2086 docker run $opts -d --name "$container_name" \ - $envs aquaproj/aqua-registry \ + $envs "$image" \ tail -f /dev/null diff --git a/scripts/scaffold.sh b/scripts/scaffold.sh index 76ad2e8a6ce..54895cd38ef 100644 --- a/scripts/scaffold.sh +++ b/scripts/scaffold.sh @@ -2,6 +2,8 @@ set -eu +. "$(dirname "$0")/var.sh" + pkg=$1 cmd=$2 limit=$3 @@ -15,8 +17,8 @@ if [ -n "$limit" ]; then fi # shellcheck disable=SC2086 -docker exec -ti -w /workspace aqua-registry bash -c "rm pkg.yaml 2>/dev/null || :" -docker exec -ti -w /workspace aqua-registry bash -c "aqua gr $opts --out-testdata pkg.yaml \"$pkg\" > registry.yaml" +docker exec -ti -w /workspace "$container" bash -c "rm pkg.yaml 2>/dev/null || :" +docker exec -ti -w /workspace "$container" bash -c "aqua gr $opts --out-testdata pkg.yaml \"$pkg\" > registry.yaml" mkdir -p "pkgs/$pkg" -docker cp "aqua-registry:/workspace/pkg.yaml" "pkgs/$pkg/pkg.yaml" -docker cp "aqua-registry:/workspace/registry.yaml" "pkgs/$pkg/registry.yaml" +docker cp "$container:/workspace/pkg.yaml" "pkgs/$pkg/pkg.yaml" +docker cp "$container:/workspace/registry.yaml" "pkgs/$pkg/registry.yaml" diff --git a/scripts/start.sh b/scripts/start.sh index bb125be42de..ab60c3e613e 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -2,37 +2,45 @@ set -euo pipefail -container_name=${1:-aqua-registry} +. "$(dirname "$0")/var.sh" +container_name=$container +if [ "${1:-}" = windows ]; then + container_name=$container_windows +fi + +info() { + echo "[INFO] $*" >&2 +} if ! bash scripts/is_build_image.sh; then - echo "[INFO] Building the docker image aquaproj/aqua-registry" >&2 + info "Building the docker image $image" bash scripts/build_image.sh fi if ! bash scripts/exist_container.sh "$container_name"; then - echo "[INFO] Creaing a container $container_name" >&2 + info "Creating a container $container_name" bash scripts/run.sh "$container_name" exit 0 fi if bash scripts/is_container_running.sh "$container_name"; then if bash scripts/check_image.sh "$container_name"; then - echo "[INFO] Dockerfile isn't updated" >&2 + info "Dockerfile isn't updated" exit 0 fi - echo "[INFO] Dockerfile is updated, so the container $container_name is being recreated" >&2 + info "Dockerfile is updated, so the container $container_name is being recreated" bash scripts/remove_container.sh "$container_name" bash scripts/run.sh "$container_name" exit 0 fi if bash scripts/check_image.sh "$container_name"; then - echo "[INFO] Dockerfile isn't updated" >&2 - echo "[INFO] Starting the container $container_name" >&2 + info "Dockerfile isn't updated" + info "Starting the container $container_name" docker start "$container_name" exit 0 fi -echo "[INFO] Dockerfile is updated, so the container $container_name is being recreated" >&2 +info "Dockerfile is updated, so the container $container_name is being recreated" bash scripts/remove_container.sh "$container_name" bash scripts/run.sh "$container_name" diff --git a/scripts/stop.sh b/scripts/stop.sh index 491c427ffd9..f560600e5eb 100644 --- a/scripts/stop.sh +++ b/scripts/stop.sh @@ -2,7 +2,11 @@ set -eu -container=${1:-aqua-registry} +. "$(dirname "$0")/var.sh" +container_name=$container +if [ "${1:-}" = windows ]; then + container_name=$container_windows +fi if bash scripts/exist_container.sh "$container"; then docker stop -t 1 "$container" diff --git a/scripts/test-windows.sh b/scripts/test-windows.sh index bca13ccb31e..63c5df14a0f 100644 --- a/scripts/test-windows.sh +++ b/scripts/test-windows.sh @@ -2,15 +2,17 @@ set -euo pipefail +. "$(dirname "$0")/var.sh" + pkg=$1 -docker cp "pkgs/$pkg/pkg.yaml" "aqua-registry-windows:/workspace/pkg.yaml" -docker cp "pkgs/$pkg/registry.yaml" "aqua-registry-windows:/workspace/registry.yaml" +docker cp "pkgs/$pkg/pkg.yaml" "$container_windows:/workspace/pkg.yaml" +docker cp "pkgs/$pkg/registry.yaml" "$container_windows:/workspace/registry.yaml" for arch in amd64 arm64; do - if ! docker exec aqua-registry-windows env AQUA_GOOS="windows" AQUA_GOARCH="$arch" aqua i; then + if ! docker exec "$container_windows" env AQUA_GOOS="windows" AQUA_GOARCH="$arch" aqua i; then echo "[ERROR] Build failed windows/$arch" >&2 - docker exec -ti aqua-registry-windows env AQUA_GOOS="windows" AQUA_GOARCH="$arch" bash + docker exec -ti "$container_windows" env AQUA_GOOS="windows" AQUA_GOARCH="$arch" bash exit 1 fi done diff --git a/scripts/test.sh b/scripts/test.sh index 73ca7488348..12c90e97503 100644 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -2,16 +2,17 @@ set -eu +. "$(dirname "$0")/var.sh" + pkg=$1 -container_name=aqua-registry -docker cp "pkgs/$pkg/pkg.yaml" "$container_name:/workspace/pkg.yaml" -docker cp "pkgs/$pkg/registry.yaml" "$container_name:/workspace/registry.yaml" +docker cp "pkgs/$pkg/pkg.yaml" "$container:/workspace/pkg.yaml" +docker cp "pkgs/$pkg/registry.yaml" "$container:/workspace/registry.yaml" for os in linux darwin; do for arch in amd64 arm64; do - docker exec "$container_name" bash -c "rm aqua-checksums.json 2>/dev/null || :" - if ! docker exec "$container_name" env AQUA_GOOS="$os" AQUA_GOARCH="$arch" aqua i; then + docker exec "$container" bash -c "rm aqua-checksums.json 2>/dev/null || :" + if ! docker exec "$container" env AQUA_GOOS="$os" AQUA_GOARCH="$arch" aqua i; then echo "[ERROR] Build failed $os/$arch" >&2 echo " If you want to look into the container, please run 'cmdx con $os $arch'" >&2 exit 1 diff --git a/scripts/var.sh b/scripts/var.sh new file mode 100644 index 00000000000..9fb52f974e2 --- /dev/null +++ b/scripts/var.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -eu + +# Please update these variables if you build a private registry. +container=aqua-registry +container_windows=${container}-windows +image=aquaproj/aqua-registry +upstream=https://github.com/aquaproj/aqua-registry From 09587c58a7c5f0f47165dad89ae49ed7baff4aa2 Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Sat, 26 Oct 2024 06:45:58 +0900 Subject: [PATCH 2/2] chore: fix a script --- scripts/exist_container.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/exist_container.sh b/scripts/exist_container.sh index 24ce7224fb9..39d7878c27b 100644 --- a/scripts/exist_container.sh +++ b/scripts/exist_container.sh @@ -3,6 +3,7 @@ set -euo pipefail . "$(dirname "$0")/var.sh" +container_name=${1:-$container} echo "[INFO] Checking if the container $container_name exists" >&2 docker ps -a --filter "name=$container_name" --format "{{.Names}}" |