diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cd36fd9ab..48600ba6b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -28,8 +28,8 @@ jobs: node --version npm --version - - name: Build Admin UI - run: make build-kinto-admin + - name: Pull Admin UI + run: make pull-kinto-admin - name: Install pypa/build run: python3 -m pip install build diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 696078a0e..b870b6531 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -229,8 +229,8 @@ jobs: which firefox firefox --version - - name: make build-kinto-admin - run: make build-kinto-admin + - name: make pull-kinto-admin + run: make pull-kinto-admin - name: Install dependencies run: make install-dev diff --git a/Dockerfile b/Dockerfile index d855cea9a..f6d491802 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,23 @@ # Mozilla Kinto server - -FROM node:lts-bullseye-slim as node-builder -RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl -COPY scripts/build-kinto-admin.sh . -COPY /kinto/plugins/admin ./kinto/plugins/admin -RUN bash build-kinto-admin.sh - -FROM python:3.10-slim-bullseye as python-builder +FROM python:3.10-bullseye as python-builder RUN python -m venv /opt/venv -RUN apt-get update && apt-get install -y --no-install-recommends build-essential libpq-dev ARG KINTO_VERSION=1 ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_KINTO=${KINTO_VERSION} \ PATH="/opt/venv/bin:$PATH" # At this stage we only fetch and build all dependencies. + +# Pull kinto-admin before building kinto so we can cache it +WORKDIR /kinto-admin +COPY kinto/plugins/admin kinto/plugins/admin +COPY scripts/pull-kinto-admin.sh . +RUN bash pull-kinto-admin.sh + WORKDIR /pkg-kinto -COPY constraints.txt . -COPY pyproject.toml . +COPY constraints.txt pyproject.toml ./ +RUN pip install --upgrade pip && pip install -r constraints.txt COPY kinto/ kinto/ -RUN pip install --upgrade pip && \ - pip install ".[postgresql,memcached,monitoring]" -c constraints.txt && \ - pip install kinto-attachment kinto-emailer httpie +RUN cp -r /kinto-admin/kinto/plugins/admin/build kinto/plugins/admin/ +RUN pip install ".[postgresql,memcached,monitoring]" -c constraints.txt && pip install kinto-attachment kinto-emailer httpie FROM python:3.10-slim-bullseye RUN apt-get update && apt-get install -y --no-install-recommends libpq-dev @@ -27,7 +25,6 @@ RUN groupadd --gid 10001 app && \ useradd --uid 10001 --gid 10001 --home /app --create-home app COPY --from=python-builder /opt/venv /opt/venv -COPY --from=node-builder /kinto/plugins/admin/build ./kinto/plugins/admin/build ENV KINTO_INI=/etc/kinto/kinto.ini \ PORT=8888 \ diff --git a/Makefile b/Makefile index 87610c854..c57ebbdbc 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ help: @echo " install-monitoring enable monitoring features like StatsD and Newrelic" @echo " install-postgres install postgresql support" @echo " install-dev install dependencies and everything needed to run tests" - @echo " build-kinto-admin build the Kinto admin UI plugin (requires npm)" + @echo " pull-kinto-admin pull the Kinto admin UI plugin (requires npm)" @echo " serve start the kinto server on default port" @echo " migrate run the kinto migrations" @echo " lint run the code linters" @@ -67,8 +67,8 @@ $(DOC_STAMP): $(PYTHON) docs/requirements.txt constraints.txt: constraints.in pip-compile -o constraints.txt constraints.in -build-kinto-admin: need-npm - scripts/build-kinto-admin.sh +pull-kinto-admin: + scripts/pull-kinto-admin.sh $(SERVER_CONFIG): $(VENV)/bin/kinto init --ini $(SERVER_CONFIG) @@ -105,9 +105,6 @@ format: install-dev tdd: install-dev $(VENV)/bin/ptw --runner $(VENV)/bin/py.test -need-npm: - @npm --version 2>/dev/null 1>&2 || (echo "The 'npm' command is required to build the Kinto Admin UI." && exit 1) - need-kinto-running: @curl http://localhost:8888/v0/ 2>/dev/null 1>&2 || (echo "Run 'make runkinto' before starting tests." && exit 1) diff --git a/docs/tutorials/install.rst b/docs/tutorials/install.rst index efaad1fc4..5d265652e 100644 --- a/docs/tutorials/install.rst +++ b/docs/tutorials/install.rst @@ -316,9 +316,9 @@ Kinto Admin ----------- In order to run a local `Kinto Admin UI `_ from a cloned -repo, the ``npm`` command must be available in order to build it with :: +repo, run :: - make build-kinto-admin + make pull-kinto-admin Go further diff --git a/kinto/plugins/admin/VERSION b/kinto/plugins/admin/VERSION index cb2b00e4f..75a22a26a 100644 --- a/kinto/plugins/admin/VERSION +++ b/kinto/plugins/admin/VERSION @@ -1 +1 @@ -3.0.1 +3.0.3 diff --git a/kinto/plugins/admin/public/help.html b/kinto/plugins/admin/public/help.html index 588f98228..6688223a4 100644 --- a/kinto/plugins/admin/public/help.html +++ b/kinto/plugins/admin/public/help.html @@ -11,7 +11,7 @@

Build and run locally

In order to get a local Kinto Admin running at this address, just run the following command:

- make build-kinto-admin + make pull-kinto-admin

Restart the server and refresh!

@@ -22,4 +22,4 @@

...or use our online version!

and set the server address to http://localhost:8888/v1.
- \ No newline at end of file + diff --git a/kinto/plugins/admin/views.py b/kinto/plugins/admin/views.py index eb68e36ea..fba56f790 100644 --- a/kinto/plugins/admin/views.py +++ b/kinto/plugins/admin/views.py @@ -16,7 +16,7 @@ def admin_home_view(request): This requires the Admin UI to be built with ``ASSET_PATH="/v1/admin/"``. """ # Default location of the Admin UI is relative to this plugin source folder, - # as built with the ``make build-kinto-admin`` command. + # as pulled with the ``make pull-kinto-admin`` command. admin_assets_path = request.registry.settings["admin_assets_path"] or os.path.join( HERE, "build" ) diff --git a/pyproject.toml b/pyproject.toml index 838f76075..b21d218c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,7 +52,7 @@ main = "kinto:main" include = ["kinto*"] [tool.setuptools.package-data] -"*" = ["*.tpl", "*.sql", "*.html", "VERSION"] +"*" = ["*.tpl", "*.sql", "plugins/admin/build/**", "VERSION"] [tool.setuptools.dynamic] readme = {file = ["README.rst", "CONTRIBUTORS.rst"]} diff --git a/scripts/build-kinto-admin.sh b/scripts/build-kinto-admin.sh deleted file mode 100755 index 1ee0e914d..000000000 --- a/scripts/build-kinto-admin.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -set -euo pipefail - -VERSION=$(cat kinto/plugins/admin/VERSION) -TAG="v${VERSION}" -TARBALL_NAME="${TAG}.tar.gz" -SRC_DIR="kinto-admin-${VERSION}" - -# download and unzip release -cd kinto/plugins/admin/ -curl -OL "https://github.com/Kinto/kinto-admin/archive/refs/tags/${TAG}.tar.gz" -tar -xf "${TARBALL_NAME}" && rm "${TARBALL_NAME}" - -# build kinto-admin bundle -pushd "${SRC_DIR}" -npm ci -export ASSET_PATH="/v1/admin/" -# kinto-admin <= 2.1.1 -export SINGLE_SERVER=1 -# kinto-admin >= 2.1.2 -export KINTO_ADMIN_SINGLE_SERVER=1 -npm run build -popd - -# move build and delete source -TARGET_DIR=./build -rm -rf "${TARGET_DIR}" -mv "${SRC_DIR}/build" "${TARGET_DIR}" -rm -rf "${SRC_DIR}" diff --git a/scripts/pull-kinto-admin.sh b/scripts/pull-kinto-admin.sh new file mode 100755 index 000000000..dd8f931ae --- /dev/null +++ b/scripts/pull-kinto-admin.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -euo pipefail + +VERSION=$(cat kinto/plugins/admin/VERSION) +TAG="v${VERSION}" + +# download and unzip release +curl -OL "https://github.com/Kinto/kinto-admin/releases/download/${TAG}/kinto-admin-release.tar" +rm -r ./kinto/plugins/admin/build || echo "admin/build folder doesn't exist yet" +mkdir ./kinto/plugins/admin/build +tar -xf kinto-admin-release.tar -C ./kinto/plugins/admin/build && rm kinto-admin-release.tar +echo "$VERSION" > ./kinto/plugins/admin/build/VERSION # will not be needed after kinto-admin@8400176 (version 3.0.4?)