Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix scripts to create private registries based on this repository #28160

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions cmdx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion scripts/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions scripts/check_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
4 changes: 3 additions & 1 deletion scripts/checkout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -eu

. "$(dirname "$0")/var.sh"

if [ "$NO_CREATE_BRANCH" = true ]; then
exit 0
fi
Expand All @@ -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"
10 changes: 6 additions & 4 deletions scripts/connect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

set -eu

. "$(dirname "$0")/var.sh"
if [ "$OS" = windows ]; then
container=$container_windows
fi

if [ -z "${ARCH:-}" ]; then
ARCH=$(uname -m)
case $ARCH in
x86_64) ARCH="amd64" ;;
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
Expand Down
6 changes: 4 additions & 2 deletions scripts/exist_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

set -euo pipefail

container_name=${1:-aqua-registry}
. "$(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}}" | grep -E "^$container_name$" >/dev/null
docker ps -a --filter "name=$container_name" --format "{{.Names}}" |
grep -E "^$container_name$" >/dev/null
2 changes: 1 addition & 1 deletion scripts/get_pkg_from_branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ if [ -n "$pkg" ]; then
exit 0
fi

echo ${current_branch#feat/}
echo "${current_branch#feat/}"
4 changes: 3 additions & 1 deletion scripts/is_build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion scripts/is_container_running.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
9 changes: 9 additions & 0 deletions scripts/new.sh
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 4 additions & 1 deletion scripts/remove_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 6 additions & 5 deletions scripts/rm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
10 changes: 6 additions & 4 deletions scripts/scaffold.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -eu

. "$(dirname "$0")/var.sh"

pkg=$1
cmd=$2
limit=$3
Expand All @@ -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"
24 changes: 16 additions & 8 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 5 additions & 1 deletion scripts/stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 6 additions & 4 deletions scripts/test-windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 6 additions & 5 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions scripts/var.sh
Original file line number Diff line number Diff line change
@@ -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