diff --git a/.gitignore b/.gitignore index 387a3ff90..59ebdd433 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,4 @@ elvis emqx_dialyzer_*_plt */emqx_dashboard/priv/www dist.zip +scripts/git-token diff --git a/deploy/docker/Dockerfile b/deploy/docker/Dockerfile index 860446b8f..b3ca6f4c8 100644 --- a/deploy/docker/Dockerfile +++ b/deploy/docker/Dockerfile @@ -18,7 +18,8 @@ RUN apk add --no-cache \ bsd-compat-headers \ libc-dev \ libstdc++ \ - bash + bash \ + jq COPY . /emqx diff --git a/scripts/get-dashboard.sh b/scripts/get-dashboard.sh index c6fc9d448..a0f484d12 100755 --- a/scripts/get-dashboard.sh +++ b/scripts/get-dashboard.sh @@ -5,18 +5,17 @@ set -euo pipefail # ensure dir cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")/.." -if [[ "$1" == https://* ]]; then - VERSION='*' # alwyas download - DOWNLOAD_URL="$1" -else - VERSION="$1" - DOWNLOAD_URL="https://github.com/emqx/emqx-dashboard-frontend/releases/download/${VERSION}/emqx-dashboard.zip" -fi +VERSION="$1" +RELEASE_ASSET_FILE="emqx-dashboard.zip" if [ -f 'EMQX_ENTERPRISE' ]; then DASHBOARD_PATH='lib-ee/emqx_dashboard/priv' + DASHBOARD_REPO='emqx-enterprise-dashboard-frontend-src' + AUTH="Authorization: token $(cat scripts/git-token)" else DASHBOARD_PATH='lib-ce/emqx_dashboard/priv' + DASHBOARD_REPO='emqx-dashboard-frontend' + AUTH="" fi case $(uname) in @@ -32,8 +31,27 @@ if [ -d "$DASHBOARD_PATH/www" ] && [ "$(version)" = "$VERSION" ]; then exit 0 fi -curl -f -L "${DOWNLOAD_URL}" -o ./emqx-dashboard.zip -unzip -q ./emqx-dashboard.zip -d "$DASHBOARD_PATH" +get_assets(){ + # Get the download URL of our desired asset + download_url="$(curl --silent --show-error \ + --header "${AUTH}" \ + --header "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/emqx/${DASHBOARD_REPO}/releases/tags/${VERSION}" \ + | jq --raw-output ".assets[] | select(.name==\"${RELEASE_ASSET_FILE}\").url")" + # Get GitHub's S3 redirect URL + redirect_url=$(curl --silent --show-error \ + --header "${AUTH}" \ + --header "Accept: application/octet-stream" \ + --write-out "%{redirect_url}" \ + "$download_url") + curl --silent --show-error \ + --header "Accept: application/octet-stream" \ + --output "${RELEASE_ASSET_FILE}" \ + "$redirect_url" +} + +get_assets +unzip -q "$RELEASE_ASSET_FILE" -d "$DASHBOARD_PATH" rm -rf "$DASHBOARD_PATH/www" mv "$DASHBOARD_PATH/dist" "$DASHBOARD_PATH/www" -rm -rf emqx-dashboard.zip +rm -rf "$RELEASE_ASSET_FILE"