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: separate the container for windows #17598

Merged
merged 2 commits into from
Nov 23, 2023
Merged
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
57 changes: 38 additions & 19 deletions cmdx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -64,12 +67,15 @@ tasks:
- "bash"
- "-c"
script: |
set -euxo pipefail
set -eu
if [ "{{.recreate}}" = true ]; then
cmdx rm
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
Expand Down Expand Up @@ -98,16 +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
docker exec -ti aqua-registry env AQUA_GOOS="$OS" AQUA_GOARCH="$ARCH" bash
script: bash scripts/connect.sh

- name: generate-registry
short: gr
Expand Down Expand Up @@ -138,25 +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: |
docker stop -t 1 aqua-registry
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: |
set -eux
docker stop -t 1 aqua-registry
docker rm aqua-registry
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
Expand Down
4 changes: 3 additions & 1 deletion scripts/check_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
17 changes: 17 additions & 0 deletions scripts/connect.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions scripts/exist_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 5 additions & 3 deletions scripts/is_container_running.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions scripts/remove_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@

set -eu

docker stop -t 3 aqua-registry
docker rm aqua-registry
container=${1:-aqua-registry}

if bash scripts/exist_container.sh "$container"; then
docker stop -t 1 "$container"
docker rm "$container"
fi
13 changes: 13 additions & 0 deletions scripts/rm.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

set -eu

container_name=${1:-aqua-registry}

token="${AQUA_GITHUB_TOKEN:-${GITHUB_TOKEN:-}}"
envs=""
if [ -n "$token" ]; then
envs="-e GITHUB_TOKEN=$token"
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
2 changes: 0 additions & 2 deletions scripts/scaffold.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
30 changes: 16 additions & 14 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
9 changes: 9 additions & 0 deletions scripts/stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -eu

container=${1:-aqua-registry}

if bash scripts/exist_container.sh "$container"; then
docker stop -t 1 "$container"
fi
16 changes: 16 additions & 0 deletions scripts/test-windows.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 7 additions & 6 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down