From 63b9091889c21a7af2e1a25a784a4afb200286d2 Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Wed, 22 Nov 2023 17:56:08 +0900 Subject: [PATCH 1/2] chore: separate the container for windows --- cmdx.yaml | 20 +++++++++++++------- scripts/check_image.sh | 4 +++- scripts/exist_container.sh | 6 ++++-- scripts/is_container_running.sh | 8 +++++--- scripts/remove_container.sh | 6 ++++-- scripts/rm.sh | 13 +++++++++++++ scripts/run.sh | 4 +++- scripts/scaffold.sh | 2 -- scripts/start.sh | 30 ++++++++++++++++-------------- scripts/stop.sh | 11 +++++++++++ scripts/test-windows.sh | 16 ++++++++++++++++ scripts/test.sh | 13 +++++++------ 12 files changed, 95 insertions(+), 38 deletions(-) create mode 100644 scripts/rm.sh create mode 100644 scripts/stop.sh create mode 100644 scripts/test-windows.sh diff --git a/cmdx.yaml b/cmdx.yaml index 83cdffed46d..27f5ea496eb 100644 --- a/cmdx.yaml +++ b/cmdx.yaml @@ -34,6 +34,9 @@ tasks: fi bash scripts/start.sh bash scripts/scaffold.sh "{{.package}}" "{{.cmd}}" "{{.limit}}" + bash scripts/test.sh "{{.package}}" + bash scripts/start.sh aqua-registry-windows + bash scripts/test-windows.sh "{{.package}}" args: - name: package usage: a package name. e.g. `cli/cli` @@ -70,6 +73,9 @@ tasks: fi bash scripts/start.sh bash scripts/test.sh "{{.package}}" + bash scripts/start.sh aqua-registry-windows + bash scripts/test-windows.sh "{{.package}}" + aqua exec -- aqua-registry gr - name: connect short: con @@ -107,7 +113,11 @@ tasks: aarch64) ARCH="arm64" ;; esac fi - docker exec -ti aqua-registry env AQUA_GOOS="$OS" AQUA_GOARCH="$ARCH" bash + container=aqua-registry + if [ "$OS" = windows ]; then + container=aqua-registry-windows + fi + docker exec -ti "$container" env AQUA_GOOS="$OS" AQUA_GOARCH="$ARCH" bash - name: generate-registry short: gr @@ -143,8 +153,7 @@ tasks: Stop the container. $ cmdx stop - script: | - docker stop -t 1 aqua-registry + script: bash scripts/stop.sh - name: remove short: rm @@ -153,10 +162,7 @@ tasks: Remove the container. $ cmdx rm - script: | - set -eux - docker stop -t 1 aqua-registry - docker rm aqua-registry + script: bash scripts/stop.sh - name: release short: r diff --git a/scripts/check_image.sh b/scripts/check_image.sh index a39598c22a7..26532a009cd 100644 --- a/scripts/check_image.sh +++ b/scripts/check_image.sh @@ -2,7 +2,9 @@ set -euo pipefail -container_image_id=$(docker inspect aqua-registry | aqua exec -- jq -r ".[].Image") +container_name=${1:-aqua-registry} + +container_image_id=$(docker inspect "$container_name" | aqua exec -- jq -r ".[].Image") image_id=$(docker inspect aquaproj/aqua-registry | aqua exec -- jq -r ".[].Id") [ "$container_image_id" = "$image_id" ] diff --git a/scripts/exist_container.sh b/scripts/exist_container.sh index ca8fced4593..554bbec08f8 100644 --- a/scripts/exist_container.sh +++ b/scripts/exist_container.sh @@ -2,5 +2,7 @@ set -euo pipefail -echo "[INFO] Checking if the container aqua-registry exists" >&2 -docker ps -a --filter "name=aqua-registry" --format "{{.Names}}" | grep -E "^aqua-registry$" >/dev/null +container_name=${1:-aqua-registry} + +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 diff --git a/scripts/is_container_running.sh b/scripts/is_container_running.sh index 963f3db7ad1..2a2b7226bf6 100644 --- a/scripts/is_container_running.sh +++ b/scripts/is_container_running.sh @@ -2,9 +2,11 @@ set -euo pipefail -echo "[INFO] Checking if the container aqua-registry is running" >&2 +container_name=${1:-aqua-registry} + +echo "[INFO] Checking if the container $container_name is running" >&2 docker ps -a \ - --filter "name=aqua-registry" \ + --filter "name=$container_name" \ --filter status=running \ --format "{{.Names}}" | - grep -E "^aqua-registry$" >/dev/null + grep -E "^$container_name$" >/dev/null diff --git a/scripts/remove_container.sh b/scripts/remove_container.sh index 01fdd27b07d..cf1d2c32251 100644 --- a/scripts/remove_container.sh +++ b/scripts/remove_container.sh @@ -2,5 +2,7 @@ set -eu -docker stop -t 3 aqua-registry -docker rm aqua-registry +container_name=${1:-aqua-registry} + +docker stop -t 3 "$container_name" +docker rm "$container_name" diff --git a/scripts/rm.sh b/scripts/rm.sh new file mode 100644 index 00000000000..336ac19ab6e --- /dev/null +++ b/scripts/rm.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -eu + +if bash scripts/exist_container.sh; then + docker stop -t 1 aqua-registry + docker rm aqua-registry +fi + +if bash scripts/exist_container.sh aqua-registry-windows; then + docker stop -t 1 aqua-registry-windows + docker rm aqua-registry-windows +fi diff --git a/scripts/run.sh b/scripts/run.sh index e836be99c07..d599a578ec1 100644 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -2,6 +2,8 @@ set -eu +container_name=${1:-aqua-registry} + token="${AQUA_GITHUB_TOKEN:-${GITHUB_TOKEN:-}}" envs="" if [ -n "$token" ]; then @@ -9,6 +11,6 @@ if [ -n "$token" ]; then fi # shellcheck disable=SC2086 -docker run -d --name aqua-registry \ +docker run -d --name "$container_name" \ -v "$PWD:/aqua-registry" $envs aquaproj/aqua-registry \ tail -f /dev/null diff --git a/scripts/scaffold.sh b/scripts/scaffold.sh index bcdf064bafb..0b8c1c723de 100644 --- a/scripts/scaffold.sh +++ b/scripts/scaffold.sh @@ -23,5 +23,3 @@ fi # shellcheck disable=SC2086 docker exec -ti -w /aqua-registry aqua-registry aqua-registry scaffold $opts "$pkg" - -bash scripts/test.sh "$pkg" diff --git a/scripts/start.sh b/scripts/start.sh index 1965084d99c..bb125be42de 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -2,35 +2,37 @@ set -euo pipefail +container_name=${1:-aqua-registry} + if ! bash scripts/is_build_image.sh; then echo "[INFO] Building the docker image aquaproj/aqua-registry" >&2 bash scripts/build_image.sh fi -if ! bash scripts/exist_container.sh; then - echo "[INFO] Creaing a container aqua-registry" >&2 - bash scripts/run.sh +if ! bash scripts/exist_container.sh "$container_name"; then + echo "[INFO] Creaing a container $container_name" >&2 + bash scripts/run.sh "$container_name" exit 0 fi -if bash scripts/is_container_running.sh; then - if bash scripts/check_image.sh; then +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 exit 0 fi - echo "[INFO] Dockerfile is updated, so the container aqua-registry is being recreated" >&2 - bash scripts/remove_container.sh - bash scripts/run.sh + echo "[INFO] Dockerfile is updated, so the container $container_name is being recreated" >&2 + bash scripts/remove_container.sh "$container_name" + bash scripts/run.sh "$container_name" exit 0 fi -if bash scripts/check_image.sh; then +if bash scripts/check_image.sh "$container_name"; then echo "[INFO] Dockerfile isn't updated" >&2 - echo "[INFO] Starting the container aqua-registry" >&2 - docker start aqua-registry + echo "[INFO] Starting the container $container_name" >&2 + docker start "$container_name" exit 0 fi -echo "[INFO] Dockerfile is updated, so the container aqua-registry is being recreated" >&2 -bash scripts/remove_container.sh -bash scripts/run.sh +echo "[INFO] Dockerfile is updated, so the container $container_name is being recreated" >&2 +bash scripts/remove_container.sh "$container_name" +bash scripts/run.sh "$container_name" diff --git a/scripts/stop.sh b/scripts/stop.sh new file mode 100644 index 00000000000..b8115650ef7 --- /dev/null +++ b/scripts/stop.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -eu + +if bash scripts/exist_container.sh; then + docker stop -t 1 aqua-registry +fi + +if bash scripts/exist_container.sh aqua-registry-windows; then + docker stop -t 1 aqua-registry-windows +fi diff --git a/scripts/test-windows.sh b/scripts/test-windows.sh new file mode 100644 index 00000000000..bca13ccb31e --- /dev/null +++ b/scripts/test-windows.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -euo pipefail + +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" + +for arch in amd64 arm64; do + if ! docker exec aqua-registry-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 + exit 1 + fi +done diff --git a/scripts/test.sh b/scripts/test.sh index 542d180da84..ff71da9fb46 100644 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,17 +1,18 @@ #!/usr/bin/env bash -set -euo pipefail +set -eu pkg=$1 +container_name=aqua-registry -docker cp "pkgs/$pkg/pkg.yaml" aqua-registry:/workspace/pkg.yaml -docker cp "pkgs/$pkg/registry.yaml" aqua-registry:/workspace/registry.yaml +docker cp "pkgs/$pkg/pkg.yaml" "$container_name:/workspace/pkg.yaml" +docker cp "pkgs/$pkg/registry.yaml" "$container_name:/workspace/registry.yaml" -for os in linux darwin windows; do +for os in linux darwin; do for arch in amd64 arm64; do - if ! docker exec aqua-registry env AQUA_GOOS="$os" AQUA_GOARCH="$arch" aqua i; then + if ! docker exec "$container_name" env AQUA_GOOS="$os" AQUA_GOARCH="$arch" aqua i; then echo "[ERROR] Build failed $os/$arch" >&2 - docker exec -ti aqua-registry env AQUA_GOOS="$os" AQUA_GOARCH="$arch" bash + docker exec -ti "$container_name" env AQUA_GOOS="$os" AQUA_GOARCH="$arch" bash exit 1 fi done From 1c9878169417c50813555e567078ceef0ca48aad Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Thu, 23 Nov 2023 10:18:17 +0900 Subject: [PATCH 2/2] chore: fix the task "remove" --- cmdx.yaml | 55 +++++++++++++++++++++++-------------- scripts/connect.sh | 17 ++++++++++++ scripts/remove_container.sh | 8 ++++-- scripts/stop.sh | 8 ++---- 4 files changed, 59 insertions(+), 29 deletions(-) create mode 100644 scripts/connect.sh diff --git a/cmdx.yaml b/cmdx.yaml index 27f5ea496eb..23a3004b09a 100644 --- a/cmdx.yaml +++ b/cmdx.yaml @@ -67,7 +67,7 @@ tasks: - "bash" - "-c" script: | - set -euxo pipefail + set -eu if [ "{{.recreate}}" = true ]; then cmdx rm fi @@ -104,20 +104,7 @@ tasks: shell: - "bash" - "-c" - script: | - set -eux - 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 - docker exec -ti "$container" env AQUA_GOOS="$OS" AQUA_GOARCH="$ARCH" bash + script: bash scripts/connect.sh - name: generate-registry short: gr @@ -148,21 +135,47 @@ tasks: usage: a package name. e.g. cli/cli - name: stop - usage: Stop the container + usage: Stop containers description: | - Stop the container. + Stop containers. $ cmdx stop - script: bash scripts/stop.sh + script: | + bash scripts/stop.sh + bash scripts/stop.sh aqua-registry-windows - name: remove short: rm - usage: Remove the container + usage: Remove containers description: | - Remove the container. + Remove containers. $ cmdx rm - script: bash scripts/stop.sh + script: | + bash scripts/remove_container.sh + bash scripts/remove_container.sh aqua-registry-windows + + - name: start + usage: Start containers + description: | + Start containers. + + $ cmdx start + flags: + - name: recreate + short: r + type: bool + usage: Recreate the container + shell: + - "bash" + - "-c" + script: | + set -eu + if [ "{{.recreate}}" = true ]; then + cmdx rm + fi + bash scripts/start.sh + bash scripts/start.sh aqua-registry-windows - name: release short: r diff --git a/scripts/connect.sh b/scripts/connect.sh new file mode 100644 index 00000000000..1f15742c049 --- /dev/null +++ b/scripts/connect.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -eu + +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 +docker exec -ti "$container" env AQUA_GOOS="$OS" AQUA_GOARCH="$ARCH" bash diff --git a/scripts/remove_container.sh b/scripts/remove_container.sh index cf1d2c32251..d6ccb1ba6fb 100644 --- a/scripts/remove_container.sh +++ b/scripts/remove_container.sh @@ -2,7 +2,9 @@ set -eu -container_name=${1:-aqua-registry} +container=${1:-aqua-registry} -docker stop -t 3 "$container_name" -docker rm "$container_name" +if bash scripts/exist_container.sh "$container"; then + docker stop -t 1 "$container" + docker rm "$container" +fi diff --git a/scripts/stop.sh b/scripts/stop.sh index b8115650ef7..491c427ffd9 100644 --- a/scripts/stop.sh +++ b/scripts/stop.sh @@ -2,10 +2,8 @@ set -eu -if bash scripts/exist_container.sh; then - docker stop -t 1 aqua-registry -fi +container=${1:-aqua-registry} -if bash scripts/exist_container.sh aqua-registry-windows; then - docker stop -t 1 aqua-registry-windows +if bash scripts/exist_container.sh "$container"; then + docker stop -t 1 "$container" fi