diff --git a/hacks/build_image.sh b/hacks/build_image.sh index 80f10366..0ab88928 100755 --- a/hacks/build_image.sh +++ b/hacks/build_image.sh @@ -1,24 +1,40 @@ #!/usr/bin/env bash set -e +DOCKERFILE="./Dockerfile" +REACT_APP_BUILD_MODE="" + usage() { - echo "Usage: $0 [ single-cluster ]" 1>&2 +cat << EOF +This command must be executed from the root of the repository +Usage: $0 [-f ] [-s|--single-cluster] +EOF } parse_args() { - while getopts ":h" opt; do + while getopts ":f:sh" opt; do case $opt in h) usage exit 0 ;; + s) + REACT_APP_BUILD_MODE="single-cluster" + ;; + f) + DOCKERFILE="$OPTARG" + ;; \?) - echo "Invalid option: -$OPTARG" >&2 + echo "Invalid option: -${opt}" >&2 usage exit 1 ;; :) - echo "Option -$OPTARG requires an argument." >&2 + echo "Option -$opt requires an argument." >&2 + usage + exit 1 + ;; + *) usage exit 1 ;; @@ -33,12 +49,23 @@ find_tool() { main() { parse_args "$@" PODMAN=$(find_tool) + + pushd ../assisted-ui-lib + REACT_APP_GIT_SHA="$(git rev-parse --short HEAD)" + popd + REACT_APP_VERSION="$(git rev-parse --short HEAD)" + + if [ "$DOCKERFILE" != './Dockerfile' ]; then + yarn build + fi + ${PODMAN} build \ + -f "$DOCKERFILE" \ --force-rm \ - --tag assisted-installer-ui:"${1:-local}" \ - --build-arg=REACT_APP_BUILD_MODE="$1" \ - --build-arg=REACT_APP_GIT_SHA="$(git rev-parse HEAD)" \ - --build-arg=REACT_APP_VERSION=latest \ + --tag quay.io/"$(whoami)"/assisted-installer-ui:"$REACT_APP_GIT_SHA" \ + --build-arg=REACT_APP_BUILD_MODE="$REACT_APP_BUILD_MODE" \ + --build-arg=REACT_APP_GIT_SHA="$REACT_APP_GIT_SHA" \ + --build-arg=REACT_APP_VERSION="$REACT_APP_VERSION" \ . } diff --git a/hacks/custom.Dockerfile b/hacks/custom.Dockerfile new file mode 100644 index 00000000..3b330a67 --- /dev/null +++ b/hacks/custom.Dockerfile @@ -0,0 +1,18 @@ +FROM registry.access.redhat.com/ubi8/nginx-120 as app + +# persist these on the final image for later inspection +ARG REACT_APP_BUILD_MODE +ENV BUILD_MODE=$REACT_APP_BUILD_MODE +ARG REACT_APP_GIT_SHA +ENV GIT_SHA=$REACT_APP_GIT_SHA +ARG REACT_APP_VERSION +ENV VERSION=$REACT_APP_VERSION + +COPY ../deploy/deploy_config.sh /deploy/ +COPY ../deploy/ui-deployment-template.yaml /deploy/ +COPY ../deploy/nginx.conf /deploy/ +COPY ../deploy/start.sh /deploy/ + +COPY --chown=1001:0 /build/ "${NGINX_APP_ROOT}/src/" + +CMD [ "/deploy/start.sh" ]