Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Update versioning and bundling #861

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Git
.git
# .git
.gitignore
.gitattributes
# .gitattributes

# Docker
docker-compose.yml
Expand Down
40 changes: 40 additions & 0 deletions .github/actions/docker-setup/action.yaml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 8 additions & 12 deletions .github/workflows/build_docker_image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ jobs:
steps:
- name: "Checkout Repository 🛎"
uses: actions/checkout@v4
with:
fetch-depth: 0

- 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
Expand All @@ -45,9 +49,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:
Expand All @@ -72,12 +73,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:
Expand All @@ -92,4 +87,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 }}
1 change: 1 addition & 0 deletions .github/workflows/conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: "Check conda builds 📦"
uses: jaimergp/conda-build-action@main
with:
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/generate_api_docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 7 additions & 18 deletions .github/workflows/test_build_docker_image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -38,25 +37,14 @@ jobs:
steps:
- name: "Checkout Repository 🛎"
uses: actions/checkout@v4

- 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-depth: 0

- 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
Expand All @@ -81,4 +69,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 }}
2 changes: 2 additions & 0 deletions .github/workflows/test_conda_store_server_unit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ dist
build
*.egg-info
.pytest_cache
**/_version.py
_version.py

# data from deployments
data
Expand Down
3 changes: 3 additions & 0 deletions conda-store-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
41 changes: 34 additions & 7 deletions conda-store-server/conda_store_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,40 @@
import hashlib
import typing

import platformdirs


__version__ = "2024.6.1"


CONDA_STORE_DIR = platformdirs.user_data_path(appname="conda-store")
from pathlib import Path


# 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"

# 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.
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:
Expand Down
1 change: 1 addition & 0 deletions conda-store-server/environment-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ dependencies:
- pip
- pip:
- pytest-playwright
- setuptools-scm>=6.4.0
51 changes: 50 additions & 1 deletion conda-store-server/hatch_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import tempfile
import urllib.request

from pathlib import Path
from typing import Any, Dict, List

from hatchling.builders.hooks.plugin.interface import BuildHookInterface
Expand All @@ -23,6 +24,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)
Expand All @@ -31,6 +37,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:
Expand All @@ -53,7 +66,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,
Expand All @@ -73,3 +88,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} "
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)
Loading
Loading