diff --git a/scripts/build-docker-image.sh b/scripts/build-docker-image.sh new file mode 100755 index 0000000..31fd1f1 --- /dev/null +++ b/scripts/build-docker-image.sh @@ -0,0 +1,123 @@ +#!/usr/bin/env bash + +# +# Copyright (c) 2020 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +ME=$(basename "$0") +ROOT_DIR=$(realpath $(dirname "$0")/..) +cd $ROOT_DIR + +DEFAULT_IMAGE=csa-certification-tool-frontend + + +GHCR_ORG="ghcr.io" +ORG=${DOCKER_BUILD_ORG:-project-chip} + +# Latest commit hash +GIT_SHA=$(git rev-parse --short HEAD) + +# If working copy has changes, append `-local` to hash +GIT_DIFF=$(git diff -s --exit-code || echo "-local") +if [[ $GIT_DIFF ]]; then + echo " 🔴 Git repo has changes. Please commit all changes before publishing." +fi +GIT_REV=$GIT_SHA$GIT_DIFF +echo "$GIT_REV" + + +IMAGE=${DOCKER_BUILD_IMAGE:-$DEFAULT_IMAGE} + +# version +VERSION=${DOCKER_BUILD_VERSION:-$GIT_REV} + +# verify that repo is clean +DIRTY=`git status --porcelain --untracked-files=no` + + +# help +[[ ${*/--help//} != "${*}" ]] && { + set +x + echo "Usage: $me + + Build and (optionally tag as latest, push) a docker image from Dockerfile in CWD + + Options: + --no-cache passed as a docker build argument + --latest update latest to the current built version (\"$VERSION\") + --push push image(s) to $GHCR_ORG (requires docker login for \"$ORG\") + --skip-build skip the build/prune step + --help get this message + --squash squash docker layers before push them to $GHCR_ORG (requires docker-squash python module) + --clear remove images after after publishing them + +" + exit 0 +} + +die() { + echo "$me: *** ERROR: $*" + exit 1 +} + +set -ex + +[[ -n $VERSION ]] || die "version cannot be empty" + +BUILD_ARGS=() +if [[ ${*/--no-cache//} != "${*}" ]]; then + BUILD_ARGS+=(--no-cache) +fi + +# Don't run `docker build` and `docker image prune` when `--skip-build` in arguments +[[ ${*/--skip-build//} != "${*}" ]] || { + docker build "${BUILD_ARGS[@]}" --build-arg TARGETPLATFORM="$TARGET_PLATFORM_TYPE" --build-arg GIT_SHA="$GIT_REV" --build-arg VERSION="$VERSION" -t "$GHCR_ORG"/"$ORG"/"$IMAGE":"$VERSION" . + docker image prune --force +} + +[[ ${*/--squash//} != "${*}" ]] && { + command -v docker-squash >/dev/null && + docker-squash "$GHCR_ORG"/"$ORG"/"$IMAGE":"$VERSION" -t "$GHCR_ORG"/"$ORG"/"$IMAGE":squashed +} + +[[ ${*/--latest//} != "${*}" ]] && { + if [[ ${*/--squash//} != "${*}" ]]; then + docker tag "$GHCR_ORG"/"$ORG"/"$IMAGE":squashed "$GHCR_ORG"/"$ORG"/"$IMAGE":latest + else + docker tag "$GHCR_ORG"/"$ORG"/"$IMAGE":"$VERSION" "$GHCR_ORG"/"$ORG"/"$IMAGE":latest + fi +} + +[[ ${*/--push//} != "${*}" ]] && { + if [[ $GIT_DIFF ]]; then + die "Don't push image with local changes" + fi + docker push "$GHCR_ORG"/"$ORG"/"$IMAGE":"$VERSION" + [[ ${*/--latest//} != "${*}" ]] && { + docker push "$GHCR_ORG"/"$ORG"/"$IMAGE":latest + } +} + +[[ ${*/--clear//} != "${*}" ]] && { + docker rmi -f "$GHCR_ORG"/"$ORG"/"$IMAGE":"$VERSION" + [[ ${*/--latest//} != "${*}" ]] && { + docker rmi -f "$GHCR_ORG"/"$ORG"/"$IMAGE":latest + } + [[ ${*/--squash//} != "${*}" ]] && { + docker rmi -f "$GHCR_ORG"/"$ORG"/"$IMAGE":squashed + } +} + +docker images --filter=reference="$GHCR_ORG/$ORG/*" \ No newline at end of file diff --git a/src/app/components/test/test-execution/test-execution.sandbox.ts b/src/app/components/test/test-execution/test-execution.sandbox.ts index 237eed2..1c4d66d 100644 --- a/src/app/components/test/test-execution/test-execution.sandbox.ts +++ b/src/app/components/test/test-execution/test-execution.sandbox.ts @@ -73,7 +73,7 @@ export class TestExecutionSandbox { ]; popupObject.inputItems = inputItems; popupObject.buttons = buttons; - } else if (promptData.payload.path) { // Displaying the file upload popup + } else if (promptType === 'file_upload_request') { // Displaying the file upload popup popupObject.popupId = 'FILE_UPLOAD_' + promptData.payload.message_id; const inputItems = [ { id: 1, @@ -82,6 +82,7 @@ export class TestExecutionSandbox { } ]; popupObject.inputItems = inputItems; + popupObject.buttons = buttons; } this.sharedAPI.setCustomPopupData(popupObject); this.sharedAPI.setShowCustomPopup(popupObject.popupId); @@ -133,4 +134,4 @@ export class TestExecutionSandbox { } return testData; } -} \ No newline at end of file +} diff --git a/src/app/shared/core_apis/websocket.ts b/src/app/shared/core_apis/websocket.ts index 8ca21de..a29fcbc 100644 --- a/src/app/shared/core_apis/websocket.ts +++ b/src/app/shared/core_apis/websocket.ts @@ -46,6 +46,7 @@ export class WebSocketAPI { } else if (dataObject.type === 'prompt_request' || dataObject.type === 'options_request' || dataObject.type === 'message_request' || + dataObject.type === 'file_upload_request' || dataObject.type === 'custom_upload') { this.testExecutionSandbox.showExecutionPrompt(dataObject); } else if (dataObject.type === 'time_out_notification') {