Skip to content

Commit

Permalink
Fixes #3380 - UI asset files not properly copied to container (#3381)
Browse files Browse the repository at this point in the history
* fixing UI builds, pulling pre-built files, groundwork for python playwright test
* improved Dockerfile so it can cache things for faster repeated builds
  • Loading branch information
alexcottner authored Feb 2, 2024
1 parent b67c6c3 commit 039d3e3
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 61 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 12 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
# 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
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 \
Expand Down
9 changes: 3 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ Kinto Admin
-----------

In order to run a local `Kinto Admin UI <https://github.com/Kinto/kinto-admin>`_ 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
Expand Down
2 changes: 1 addition & 1 deletion kinto/plugins/admin/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.1
3.0.3
4 changes: 2 additions & 2 deletions kinto/plugins/admin/public/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h2>Build and run locally</h2>
<p>In order to get a local Kinto Admin running at this address, just run the
following command:
</p>
<code>make build-kinto-admin</code>
<code>make pull-kinto-admin</code>
<p>Restart the server and refresh!</p>
</section>
<section>
Expand All @@ -22,4 +22,4 @@ <h2>...or use our online version!</h2>
and set the server address to <em>http://localhost:8888/v1</em>.
</section>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion kinto/plugins/admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}
Expand Down
29 changes: 0 additions & 29 deletions scripts/build-kinto-admin.sh

This file was deleted.

12 changes: 12 additions & 0 deletions scripts/pull-kinto-admin.sh
Original file line number Diff line number Diff line change
@@ -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?)

0 comments on commit 039d3e3

Please sign in to comment.