From 8216895325ecba13bd6d92a2766ef96bcc5279f4 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 12 Aug 2024 11:32:23 +0100 Subject: [PATCH 01/13] :wrench: Change to dynamic version for conda-store --- conda-store/conda_store/__init__.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/conda-store/conda_store/__init__.py b/conda-store/conda_store/__init__.py index f37ece379..299290e8f 100644 --- a/conda-store/conda_store/__init__.py +++ b/conda-store/conda_store/__init__.py @@ -1 +1,19 @@ -__version__ = "2024.6.1" +# Define the variable '__version__': +try: + # If setuptools_scm is installed (e.g. in a development environment with + # an editable install), then use it to determine the version dynamically. + from setuptools_scm import get_version + + # This will fail with LookupError if the package is not installed in + # editable mode or if Git is not installed. + __version__ = get_version(root="../..", relative_to=__file__) +except (ImportError, LookupError): + # As a fallback, use the version that is hard-coded in the file. + try: + from conda_store._version import __version__ # noqa: F401 + except ModuleNotFoundError: + # The user is probably trying to run this without having installed + # the package, so complain. + raise RuntimeError( + "conda-store is not correctly installed. " "Please install it with pip." + ) From cee18a7c671a56a9413cf3538b4bf68cd7173e1f Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 12 Aug 2024 11:33:17 +0100 Subject: [PATCH 02/13] Update pyproject - conda-store --- conda-store/pyproject.toml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/conda-store/pyproject.toml b/conda-store/pyproject.toml index 4b1b2743b..0b9d81e2f 100644 --- a/conda-store/pyproject.toml +++ b/conda-store/pyproject.toml @@ -58,7 +58,12 @@ Source = "https://github.com/conda-incubator/conda-store" Issues = "https://github.com/conda-incubator/conda-store/issues" [tool.hatch.version] -path = "conda_store/__init__.py" +source = "vcs" +# need to specify root as .git is one level up +raw-options = { root = "../", relative_to = "pyproject.toml", local_scheme = "node-and-date" } + +[tool.hatch.build.hooks.vcs] +version-file = "conda_store/_version.py" [project.optional-dependencies] dev = ["build", "twine"] @@ -70,6 +75,7 @@ dependencies = [ "pytest", "twine>=5.0.0", "pkginfo >= 1.10", # Needed to support metadata 2.3 + "setuptools-scm>=6.4.0" ] [tool.hatch.envs.lint] @@ -91,6 +97,7 @@ target-version = ['py38', 'py39', 'py310'] [tool.ruff] ignore = [ "E501", # line-length + ] [tool.isort] From a3c37006dd548da5a375ef89c1950341733cb9e8 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 12 Aug 2024 11:34:09 +0100 Subject: [PATCH 03/13] :wrench: Change to dynamic version - conda-store-server --- .../conda_store_server/__init__.py | 24 ++++++++++++++++--- conda-store-server/pyproject.toml | 15 ++++++++---- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/conda-store-server/conda_store_server/__init__.py b/conda-store-server/conda_store_server/__init__.py index f3fd2cf8f..7ac7561c8 100644 --- a/conda-store-server/conda_store_server/__init__.py +++ b/conda-store-server/conda_store_server/__init__.py @@ -5,11 +5,29 @@ import platformdirs -__version__ = "2024.6.1" - - CONDA_STORE_DIR = platformdirs.user_data_path(appname="conda-store") +# Define the variable '__version__': +try: + # If setuptools_scm is installed (e.g. in a development environment with + # an editable install), then use it to determine the version dynamically. + from setuptools_scm import get_version + + # This will fail with LookupError if the package is not installed in + # editable mode or if Git is not installed. + __version__ = get_version(root="../..", relative_to=__file__) +except (ImportError, LookupError): + # As a fallback, use the version that is hard-coded in the file. + try: + from conda_store_server._version import __version__ # noqa: F401 + except ModuleNotFoundError: + # The user is probably trying to run this without having installed + # the package, so complain. + raise RuntimeError( + "conda-store-server is not correctly installed. " + "Please install it with pip." + ) + class BuildKey: """ diff --git a/conda-store-server/pyproject.toml b/conda-store-server/pyproject.toml index d91869754..12f14003b 100644 --- a/conda-store-server/pyproject.toml +++ b/conda-store-server/pyproject.toml @@ -1,6 +1,6 @@ [build-system] # https://github.com/ofek/hatch-vcs -requires = ["hatchling>=1.14.0", "hatch-vcs"] +requires = ["hatchling>=1.14.0", "hatch-vcs", "hatch-fancy-pypi-readme"] build-backend = "hatchling.build" [project] @@ -11,7 +11,7 @@ license = "BSD-3-Clause" requires-python = ">=3.8" keywords = ["conda"] authors = [ - { name = "Christopher Ostrouchov", email = "crhsi.ostrouchov@gmail.com" }, + { name = "Christopher Ostrouchov", email = "chris.ostrouchov@gmail.com" }, ] maintainers = [ { name = "Tania Allard", email = "trallard@bitsandchips.me" }, @@ -73,11 +73,16 @@ dynamic = ["version"] [project.urls] Homepage = "https://conda.store/" -Source = "https://github.com/conda-incubator/conda-store" +Source = "https://github.com/conda-incubator/conda-store/conda-store-server" Issues = "https://github.com/conda-incubator/conda-store/issues" [tool.hatch.version] -path = "conda_store_server/__init__.py" +source = "vcs" +# need to specify root as .git is one level up +raw-options = { root = "../", relative_to = "pyproject.toml", local_scheme = "node-and-date" } + +[tool.hatch.build.hooks.vcs] +version-file = "conda_store_server/_version.py" [tool.hatch.envs.dev] dependencies = [ @@ -91,7 +96,7 @@ dependencies = [ "pytest-playwright", "twine>=5.0.0", "pkginfo>=1.10", # Needed to support metadata 2.3 - + "setuptools-scm>=6.4.0" ] [tool.hatch.envs.lint] From 51c319cf5c405636dd9b450e71c6f61c62ada539 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 12 Aug 2024 11:34:29 +0100 Subject: [PATCH 04/13] :see_no_evil: Ensure we do not track version files --- .gitignore | 2 ++ conda-store/.gitignore | 1 + 2 files changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 0ec82f551..89b2490ff 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ dist build *.egg-info .pytest_cache +**/_version.py +_version.py # data from deployments data diff --git a/conda-store/.gitignore b/conda-store/.gitignore index 325e8c346..61e9f76e2 100644 --- a/conda-store/.gitignore +++ b/conda-store/.gitignore @@ -6,3 +6,4 @@ node_modules/ *.tsbuildinfo __pycache__ .DS_Store +**/_version.py From 12c3dcf0e972a21a564c6e8878aabc04b8e6a414 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 12 Aug 2024 11:34:44 +0100 Subject: [PATCH 05/13] :heavy_plus_sign: Add dev dependencies --- conda-store-server/environment-dev.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/conda-store-server/environment-dev.yaml b/conda-store-server/environment-dev.yaml index 0ef1e428f..7fd93c017 100644 --- a/conda-store-server/environment-dev.yaml +++ b/conda-store-server/environment-dev.yaml @@ -32,3 +32,4 @@ dependencies: - pip - pip: - pytest-playwright + - setuptools-scm>=6.4.0 From 152e5026ca56f6bf5ce98db702345bc5753fc74f Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 12 Aug 2024 11:37:47 +0100 Subject: [PATCH 06/13] :wrench: Update Docker to use scm version --- conda-store-server/Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/conda-store-server/Dockerfile b/conda-store-server/Dockerfile index ae5c6da9a..3e903fb36 100644 --- a/conda-store-server/Dockerfile +++ b/conda-store-server/Dockerfile @@ -77,6 +77,9 @@ WORKDIR /var/lib/conda-store # --------------------------------------------------------------------------------- # for development images we install conda-store-server in editable mode FROM base AS dev +ARG PSEUDO_VERSION=1.0.0 +# we need to set the environment variable for setuptools_scm to work +ENV SETUPTOOLS_SCM_PRETEND_VERSION=${PSEUDO_VERSION} WORKDIR /opt/conda-store-server RUN which python && \ From 24605358d894bc052383a730b74c926b397c46ba Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 12 Aug 2024 11:52:46 +0100 Subject: [PATCH 07/13] :building_construction: Update Dockerfiles to use dynamic version --- .github/workflows/build_docker_image.yaml | 5 +++++ .github/workflows/test_build_docker_image.yaml | 6 ++++++ conda-store/Dockerfile | 4 +++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_docker_image.yaml b/.github/workflows/build_docker_image.yaml index 36776a0ec..74fca8ca6 100644 --- a/.github/workflows/build_docker_image.yaml +++ b/.github/workflows/build_docker_image.yaml @@ -28,6 +28,11 @@ jobs: - name: "Checkout Repository 🛎" uses: actions/checkout@v4 + - name: "Get dev version 🏷️" + id: get-dev-version + run: | + echo "cs-version=$(git describe --tags)" >> $GITHUB_OUTPUT + - name: "Get project's default Python version 🏷️" run: | echo "PYTHON_VERSION_DEFAULT=$(cat .python-version-default)" >> $GITHUB_ENV diff --git a/.github/workflows/test_build_docker_image.yaml b/.github/workflows/test_build_docker_image.yaml index 6d8424094..2bad4620a 100644 --- a/.github/workflows/test_build_docker_image.yaml +++ b/.github/workflows/test_build_docker_image.yaml @@ -39,6 +39,11 @@ jobs: - name: "Checkout Repository 🛎" uses: actions/checkout@v4 + - name: "Get dev version 🏷️" + id: get-dev-version + run: | + echo "cs-version=$(git describe --tags)" >> $GITHUB_OUTPUT + - name: "Get project's default Python version 🏷️" run: | echo "PYTHON_VERSION_DEFAULT=$(cat .python-version-default)" >> $GITHUB_ENV @@ -81,4 +86,5 @@ jobs: cache-to: type=gha,mode=max build-args: | python_version=${{ env.PYTHON_VERSION_DEFAULT }} + PSEUDO_VERSION=${{ steps.get-dev-version.outputs.cs-version }} platforms: ${{ matrix.platform }} diff --git a/conda-store/Dockerfile b/conda-store/Dockerfile index 3a807874e..80199df90 100644 --- a/conda-store/Dockerfile +++ b/conda-store/Dockerfile @@ -42,7 +42,6 @@ ARG RELEASE_VERSION WORKDIR /opt/conda-store - RUN which python && \ python -m pip install conda-store==${RELEASE_VERSION} --no-cache-dir @@ -54,6 +53,9 @@ WORKDIR /opt/jupyterhub # for development images we install conda-store-server in editable mode FROM base AS dev +ARG PSEUDO_VERSION=1.0.0 +# we need to set the environment variable for setuptools_scm to work +ENV SETUPTOOLS_SCM_PRETEND_VERSION=${PSEUDO_VERSION} RUN --mount=type=cache,target=/root/.cache/pip WORKDIR /opt/conda-store From 054d7a85bac20ecb45ccae11c63bf2bc11f6e9c3 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Tue, 13 Aug 2024 13:12:33 +0100 Subject: [PATCH 08/13] :wrench: Move Docker setup to reusable action --- .github/actions/docker-setup/action.yaml | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/actions/docker-setup/action.yaml diff --git a/.github/actions/docker-setup/action.yaml b/.github/actions/docker-setup/action.yaml new file mode 100644 index 000000000..e68c0710b --- /dev/null +++ b/.github/actions/docker-setup/action.yaml @@ -0,0 +1,40 @@ +name: "Setup Docker" +description: "Setup tasks needed to build and publish Docker images" + +inputs: + docker-image: + description: "conda-store project to build the Docker image for: conda-store or conda-store-server" + required: true +outputs: + cs-version: + description: "conda-store current version - dirty tag" + value: ${{ steps.get-dev-version.outputs.cs-version }} + +runs: + using: "composite" + steps: + - name: "Get dev version 🏷️" + id: get-dev-version + shell: bash + run: | + echo "cs-version=$(git describe --tags)" >> $GITHUB_OUTPUT + + - name: "Get project's default Python version 🏷️" + shell: bash + run: | + echo "PYTHON_VERSION_DEFAULT=$(cat .python-version-default)" >> $GITHUB_ENV + + - name: "Lint Dockerfiles 🔍" + uses: jbergstroem/hadolint-gh-action@v1 + with: + dockerfile: ${{ inputs.docker-image }}/Dockerfile + output_format: tty + error_level: 0 + + - name: "Set up Docker Buildx 🏗" + uses: docker/setup-buildx-action@v3 + + - name: "Copy .dockerignore" + run: | + cp .dockerignore ${{ inputs.docker-image }}/.dockerignore + shell: bash From 858df464309080236cefb12af8c5a093a2b2aa9b Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Tue, 13 Aug 2024 13:13:24 +0100 Subject: [PATCH 09/13] :construction_worker: Update workflows to use reusable action --- .github/workflows/build_docker_image.yaml | 26 ++++++--------- .../workflows/test_build_docker_image.yaml | 32 +++++-------------- 2 files changed, 17 insertions(+), 41 deletions(-) diff --git a/.github/workflows/build_docker_image.yaml b/.github/workflows/build_docker_image.yaml index 74fca8ca6..0eb8b33cb 100644 --- a/.github/workflows/build_docker_image.yaml +++ b/.github/workflows/build_docker_image.yaml @@ -27,15 +27,15 @@ jobs: steps: - name: "Checkout Repository 🛎" uses: actions/checkout@v4 + with: + # Fetch HEAD - since we need to get tags for versioning + fetch-depth: 2 - - name: "Get dev version 🏷️" - id: get-dev-version - run: | - echo "cs-version=$(git describe --tags)" >> $GITHUB_OUTPUT - - - name: "Get project's default Python version 🏷️" - run: | - echo "PYTHON_VERSION_DEFAULT=$(cat .python-version-default)" >> $GITHUB_ENV + - name: "Setup CI environment - Docker 🛠" + uses: ./.github/actions/docker-setup + id: setup-ci-docker + with: + docker-image: ${{ matrix.docker-image }} - name: "Retrieve secret from Vault 🗝" uses: hashicorp/vault-action@v3 @@ -50,9 +50,6 @@ jobs: kv/data/repository/conda-incubator/conda-store/shared_secrets QUAY_QUANSIGHT_USERNAME | QUAY_USERNAME; kv/data/repository/conda-incubator/conda-store/shared_secrets QUAY_QUANSIGHT_PASSWORD | QUAY_PASSWORD; - - name: "Set up Docker Buildx 🏗" - uses: docker/setup-buildx-action@v3 - - name: "Login to Docker Hub 🐳" uses: docker/login-action@v3 with: @@ -77,12 +74,6 @@ jobs: type=ref,event=tag type=sha - # we need this as we are setting the context to subproject directory - - name: "Copy .dockerignore" - run: | - cp .dockerignore ${{ matrix.docker-image }}/.dockerignore - shell: bash - - name: "Publish Docker image 🚀" uses: docker/build-push-action@v5 with: @@ -97,4 +88,5 @@ jobs: cache-to: type=gha,mode=max build-args: | python_version=${{ env.PYTHON_VERSION_DEFAULT }} + PSEUDO_VERSION=${{ steps.setup-ci-docker.outputs.cs-version }} platforms: ${{ matrix.platform }} diff --git a/.github/workflows/test_build_docker_image.yaml b/.github/workflows/test_build_docker_image.yaml index 2bad4620a..9639d0b88 100644 --- a/.github/workflows/test_build_docker_image.yaml +++ b/.github/workflows/test_build_docker_image.yaml @@ -17,7 +17,6 @@ on: branches: - main - # ensuring only one instance is running at a given time concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} @@ -38,30 +37,15 @@ jobs: steps: - name: "Checkout Repository 🛎" uses: actions/checkout@v4 - - - name: "Get dev version 🏷️" - id: get-dev-version - run: | - echo "cs-version=$(git describe --tags)" >> $GITHUB_OUTPUT - - - name: "Get project's default Python version 🏷️" - run: | - echo "PYTHON_VERSION_DEFAULT=$(cat .python-version-default)" >> $GITHUB_ENV - - - name: "Set up Docker Buildx 🏗" - uses: docker/setup-buildx-action@v3 - - - name: "Lint Dockerfiles 🔍" - uses: jbergstroem/hadolint-gh-action@v1 with: - dockerfile: ${{ matrix.docker-image }}/Dockerfile - output_format: tty - error_level: 0 + # Fetch HEAD - since we need to get tags for versioning + fetch-depth: 2 - - name: "Copy .dockerignore" - run: | - cp .dockerignore ${{ matrix.docker-image }}/.dockerignore - shell: bash + - name: "Setup CI environment - Docker 🛠" + uses: ./.github/actions/docker-setup + id: setup-ci-docker + with: + docker-image: ${{ matrix.docker-image }} - name: "Add Docker metadata 📝" id: meta @@ -86,5 +70,5 @@ jobs: cache-to: type=gha,mode=max build-args: | python_version=${{ env.PYTHON_VERSION_DEFAULT }} - PSEUDO_VERSION=${{ steps.get-dev-version.outputs.cs-version }} + PSEUDO_VERSION=${{ steps.setup-ci-docker.outputs.cs-version }} platforms: ${{ matrix.platform }} From 0055529ce83ad28086961841d754db6bb970a870 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Tue, 13 Aug 2024 13:34:16 +0100 Subject: [PATCH 10/13] Add vendoring string to conda-store-ui files --- conda-store-server/hatch_build.py | 54 ++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/conda-store-server/hatch_build.py b/conda-store-server/hatch_build.py index 484e61ed8..25336bd57 100644 --- a/conda-store-server/hatch_build.py +++ b/conda-store-server/hatch_build.py @@ -5,11 +5,15 @@ import tempfile import urllib.request +from pathlib import Path from typing import Any, Dict, List from hatchling.builders.hooks.plugin.interface import BuildHookInterface +from conda_store_server import __version__ + +CONDA_STORE_SERVER_VERSION = __version__ CONDA_STORE_UI_VERSION = "2024.6.1" CONDA_STORE_UI_URL = f"https://registry.npmjs.org/@conda-store/conda-store-ui/-/conda-store-ui-{CONDA_STORE_UI_VERSION}.tgz" CONDA_STORE_UI_FILES = [ @@ -23,6 +27,11 @@ class DownloadCondaStoreUIHook(BuildHookInterface): def clean(self, versions: List[str]) -> None: + """Quick utility method to remove any straggling ui files from previous versions + + Args: + versions (List[str]): a list of published versions in npm + """ super().clean(versions) destination_directory = ( pathlib.Path(self.root) @@ -31,6 +40,13 @@ def clean(self, versions: List[str]) -> None: shutil.rmtree(destination_directory, ignore_errors=True) def initialize(self, version: str, build_data: Dict[str, Any]) -> None: + """UI vendoring within conda-store-server, right now it downloads the + published UI, copies the distributed html, js and css files and + does some on the fly env vars injection. + + Args: + version (str): ui version to vendor + """ super().initialize(version, build_data) with tempfile.TemporaryDirectory() as tmp_dir: @@ -53,7 +69,9 @@ def initialize(self, version: str, build_data: Dict[str, Any]) -> None: ) destination_directory.mkdir(parents=True, exist_ok=True) - print(f"Copying files {CONDA_STORE_UI_FILES}") + print( + f"Copying conda-store-ui {CONDA_STORE_UI_FILES} to {destination_directory}" + ) for filename in CONDA_STORE_UI_FILES: shutil.copy( source_directory / filename, @@ -73,3 +91,37 @@ def initialize(self, version: str, build_data: Dict[str, Any]) -> None: "w", encoding="utf-8" ) as dest_f: dest_f.write(content) + # Add vendoring string to files + for filename in CONDA_STORE_UI_FILES: + annotate_vendored(destination_directory / filename) + + +def annotate_vendored(file_path: str): + """Auxiliary method to add a vendoring string to the top of a file. + This helps with tracking the version of the vendored file and the conda-store + version for which we bundled the artefacts. + + Args: + file_path (str): conda-store-ui file path + """ + comment_string = { + ".js": ["//", ""], + ".map": ["//", ""], + ".css": ["/*", "*/"], + ".html": [""], + } + + vendoring_string = ( + f"{(comment_string.get(Path(file_path).suffix)[0])} " + f"conda-store-ui version: {CONDA_STORE_UI_VERSION} -- vendored for conda-store version: {CONDA_STORE_SERVER_VERSION}" + f"{(comment_string.get(Path(file_path).suffix)[1])} \n" + ) + + with open(file_path, "r") as file: + raw_content = file.read() + + modified_content = vendoring_string + raw_content + + # Write the modified content back to the file + with open(file_path, "w") as file: + file.write(modified_content) From 46db401e2ba408f581c5cc1752de353ef36109fd Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Tue, 13 Aug 2024 14:56:25 +0100 Subject: [PATCH 11/13] We do not need cs version with hatch_build --- conda-store-server/hatch_build.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/conda-store-server/hatch_build.py b/conda-store-server/hatch_build.py index 25336bd57..3fdc8b40b 100644 --- a/conda-store-server/hatch_build.py +++ b/conda-store-server/hatch_build.py @@ -10,10 +10,7 @@ from hatchling.builders.hooks.plugin.interface import BuildHookInterface -from conda_store_server import __version__ - -CONDA_STORE_SERVER_VERSION = __version__ CONDA_STORE_UI_VERSION = "2024.6.1" CONDA_STORE_UI_URL = f"https://registry.npmjs.org/@conda-store/conda-store-ui/-/conda-store-ui-{CONDA_STORE_UI_VERSION}.tgz" CONDA_STORE_UI_FILES = [ @@ -113,7 +110,7 @@ def annotate_vendored(file_path: str): vendoring_string = ( f"{(comment_string.get(Path(file_path).suffix)[0])} " - f"conda-store-ui version: {CONDA_STORE_UI_VERSION} -- vendored for conda-store version: {CONDA_STORE_SERVER_VERSION}" + f"conda-store-ui version: {CONDA_STORE_UI_VERSION} " f"{(comment_string.get(Path(file_path).suffix)[1])} \n" ) From 072a603dd6360809a229cf5ad1a2df819fdfb111 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Wed, 14 Aug 2024 16:22:25 +0100 Subject: [PATCH 12/13] :construction_worker: Fix openapi action --- .github/workflows/generate_api_docs.yaml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/generate_api_docs.yaml b/.github/workflows/generate_api_docs.yaml index cbf2ac1a8..11176cd60 100644 --- a/.github/workflows/generate_api_docs.yaml +++ b/.github/workflows/generate_api_docs.yaml @@ -16,26 +16,27 @@ jobs: run: shell: bash -el {0} steps: - - name: Checkout repository + - name: "Checkout repository 🛎" uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.ref }} - - name: Set up Miniconda + - name: "Set up Miniconda 🐍" uses: conda-incubator/setup-miniconda@v3 with: environment-file: conda-store-server/environment-dev.yaml - - name: Install conda-store-server + - name: "Install conda-store-server 📦" run: python -m pip install conda-store-server/. - - name: Run openapi.json generation script + - name: "Run openapi.json generation script 📝" run: python docusaurus-docs/scripts/generate_openapi_json.py - - name: Commit changes + - name: "Commit changes 📝" uses: EndBug/add-and-commit@v9 with: default_author: github_actions message: 'Update REST API documentation (openapi.json)' - add: 'openapi.json' + add: 'docusaurus-docs/static/openapi.json' push: true + pathspec_error_handling: exitAtEnd From 54f5017e6e494c844df4b0dc781fa8a770dd0f99 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Tue, 27 Aug 2024 15:07:18 +0100 Subject: [PATCH 13/13] Fetch: 0 so we can get the tags --- .dockerignore | 4 +-- .github/workflows/build_docker_image.yaml | 3 +- .github/workflows/conda.yml | 1 + .../workflows/test_build_docker_image.yaml | 3 +- .../test_conda_store_server_unit.yaml | 2 ++ .../conda_store_server/__init__.py | 15 ++++++++-- conda-store-server/pyproject.toml | 2 ++ conda-store/Dockerfile | 30 ++++++++++++------- 8 files changed, 41 insertions(+), 19 deletions(-) diff --git a/.dockerignore b/.dockerignore index dffae8f55..b23f4a4fc 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,7 @@ # Git -.git +# .git .gitignore -.gitattributes +# .gitattributes # Docker docker-compose.yml diff --git a/.github/workflows/build_docker_image.yaml b/.github/workflows/build_docker_image.yaml index 0eb8b33cb..dec16940a 100644 --- a/.github/workflows/build_docker_image.yaml +++ b/.github/workflows/build_docker_image.yaml @@ -28,8 +28,7 @@ jobs: - name: "Checkout Repository 🛎" uses: actions/checkout@v4 with: - # Fetch HEAD - since we need to get tags for versioning - fetch-depth: 2 + fetch-depth: 0 - name: "Setup CI environment - Docker 🛠" uses: ./.github/actions/docker-setup diff --git a/.github/workflows/conda.yml b/.github/workflows/conda.yml index f56765dc8..3d6e0e5f9 100644 --- a/.github/workflows/conda.yml +++ b/.github/workflows/conda.yml @@ -30,6 +30,7 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + - name: "Check conda builds 📦" uses: jaimergp/conda-build-action@main with: diff --git a/.github/workflows/test_build_docker_image.yaml b/.github/workflows/test_build_docker_image.yaml index 9639d0b88..a07ee5037 100644 --- a/.github/workflows/test_build_docker_image.yaml +++ b/.github/workflows/test_build_docker_image.yaml @@ -38,8 +38,7 @@ jobs: - name: "Checkout Repository 🛎" uses: actions/checkout@v4 with: - # Fetch HEAD - since we need to get tags for versioning - fetch-depth: 2 + fetch-depth: 0 - name: "Setup CI environment - Docker 🛠" uses: ./.github/actions/docker-setup diff --git a/.github/workflows/test_conda_store_server_unit.yaml b/.github/workflows/test_conda_store_server_unit.yaml index 36ffd0f91..10683f41a 100644 --- a/.github/workflows/test_conda_store_server_unit.yaml +++ b/.github/workflows/test_conda_store_server_unit.yaml @@ -30,6 +30,8 @@ jobs: steps: - name: "Checkout Repository 🛎" uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: "Set up Python 🐍" uses: actions/setup-python@v5 diff --git a/conda-store-server/conda_store_server/__init__.py b/conda-store-server/conda_store_server/__init__.py index 7ac7561c8..b7421df0a 100644 --- a/conda-store-server/conda_store_server/__init__.py +++ b/conda-store-server/conda_store_server/__init__.py @@ -2,12 +2,21 @@ import hashlib import typing -import platformdirs +from pathlib import Path -CONDA_STORE_DIR = platformdirs.user_data_path(appname="conda-store") +# For runtime, we use platformdirs to get the user data directory and ensure +# this is cross-platform +try: + import platformdirs + + CONDA_STORE_DIR = platformdirs.user_data_path(appname="conda-store") +# at build time, we use Path.home() to default to the user's home directory +# this is a workaround as we cannot import platformdirs at build time +except ImportError: + CONDA_STORE_DIR = Path.home() / ".conda-store" -# Define the variable '__version__': +# Since we are now using vcs we need to define the variable '__version__': try: # If setuptools_scm is installed (e.g. in a development environment with # an editable install), then use it to determine the version dynamically. diff --git a/conda-store-server/pyproject.toml b/conda-store-server/pyproject.toml index 12f14003b..6eff859e4 100644 --- a/conda-store-server/pyproject.toml +++ b/conda-store-server/pyproject.toml @@ -104,6 +104,8 @@ dependencies = ["pre-commit"] [tool.hatch.envs.lint.scripts] lint = ["pre-commit run --all"] + +[tool.hatch.envs.test.scripts] unit-test = "pytest -m 'not extended_prefix and not user_journey' tests" playwright-test = [ "playwright install", diff --git a/conda-store/Dockerfile b/conda-store/Dockerfile index 80199df90..06c79230f 100644 --- a/conda-store/Dockerfile +++ b/conda-store/Dockerfile @@ -1,6 +1,8 @@ # conda-store (core) Dockerfile # the generated Docker image is used with docker compose to run the conda-store # worker and public conda-store Docker images +# To build locally, run: +# docker build --rm -f "conda-store/Dockerfile" -t conda-store:latest "conda-store" --platform=linux/arm64 . FROM condaforge/miniforge3:24.3.0-0 AS base @@ -33,35 +35,43 @@ RUN mamba create --name ${conda_env_name} \ conda clean --force-pkgs-dirs COPY ./ /opt/conda-store/ +COPY --from=repo_root .git/ /opt/conda-store/.git/ + +# needed to get the dynamic version for the project +WORKDIR /opt/conda-store +RUN PSEUDO_VERSION=$(git describe --tags) && \ + echo "PSEUDO_VERSION=${PSEUDO_VERSION}" > /etc/environment && \ + echo ${PSEUDO_VERSION} # --------------------------------------------------------------------------------- # for production-ready images we install a specific version of conda-store -FROM base AS prod +# FROM base AS prod -ARG RELEASE_VERSION +# ARG RELEASE_VERSION -WORKDIR /opt/conda-store +# WORKDIR /opt/conda-store -RUN which python && \ - python -m pip install conda-store==${RELEASE_VERSION} --no-cache-dir +# RUN which python && \ +# python -m pip install conda-store==${RELEASE_VERSION} --no-cache-dir -USER conda-store -WORKDIR /opt/jupyterhub +# USER conda-store +# WORKDIR /opt/jupyterhub # --------------------------------------------------------------------------------- # --------------------------------------------------------------------------------- # for development images we install conda-store-server in editable mode FROM base AS dev -ARG PSEUDO_VERSION=1.0.0 # we need to set the environment variable for setuptools_scm to work -ENV SETUPTOOLS_SCM_PRETEND_VERSION=${PSEUDO_VERSION} +ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CONDA_STORE=${PSEUDO_VERSION} RUN --mount=type=cache,target=/root/.cache/pip WORKDIR /opt/conda-store RUN which python && \ - python -m pip install -e . --no-cache-dir + echo ${PSEUDO_VERSION} && \ + echo ${SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CONDA_STORE} +# pip install -e . --no-cache-dir USER conda-store WORKDIR /opt/jupyterhub