diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 21a6dec..3f8a800 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -2,10 +2,11 @@ name: Keboola Component Build & Deploy Pipeline on: push: branches: - - 'feature/*' - - 'bug/*' + - feature/* + - bug/* + - fix/* tags: - - '*' # Skip the workflow on the main branch without tags + - "*" # Skip the workflow on the main branch without tags concurrency: ci-${{ github.ref }} # to avoid tag collisions in the ECR env: diff --git a/Dockerfile b/Dockerfile index 6817573..0a6352a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,10 @@ COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ # RUN apt-get update && apt-get install -y build-essential +# Create user to correctly set the $HOME env variable (used by certain packages, eg. stanza, for caching data) +ARG USERNAME=keboola +RUN adduser --uid 1000 --disabled-password ${USERNAME} + # Set UV_CACHE_DIR to override XDG_CACHE_HOME from the base image # See https://docs.astral.sh/uv/concepts/cache/#cache-directory RUN mkdir -p /.cache/uv @@ -12,19 +16,21 @@ ENV UV_CACHE_DIR="/.cache/uv" # Using the same path as venv defined in the base image so we can use all the preinstalled packages ENV UV_PROJECT_ENVIRONMENT="/home/default/" +# Run uv sync as uid/gid 1000 so we don't have to chown the /home/default directory with 100k files =-O +USER 1000:1000 + WORKDIR /code/ COPY pyproject.toml . COPY uv.lock . -# Run uv sync as uid/gid 1000 so we don't have to chown the /home/default directory with 100k files =-O -USER 1000:1000 # The --inexact flag prevents uv from uninstalling the preinstalled packages RUN uv sync --all-groups --frozen --inexact -# Keboola running containers with "-u 1000:1000" causes permission when installing user defined packages +# Keboola running containers with "-u 1000:1000" causes permission issues when installing user defined packages +# so we need to chown the files to 1000:1000 USER root -RUN chown 1000:1000 /code/pyproject.toml -RUN chown 1000:1000 /code/uv.lock +RUN chown 1000:1000 pyproject.toml +RUN chown 1000:1000 uv.lock COPY src/ src/ COPY tests/ tests/ @@ -32,4 +38,6 @@ COPY scripts/ scripts/ COPY flake8.cfg . COPY deploy.sh . +RUN chown -R 1000:1000 * + CMD ["uv", "run", "python", "src/component.py"] diff --git a/src/component.py b/src/component.py index 60a52d3..8727a07 100644 --- a/src/component.py +++ b/src/component.py @@ -93,6 +93,7 @@ def script_excerpt(script): @staticmethod def install_packages(packages): for package in packages: + logging.info("Installing package: %s...", package) args = [ "uv", "add", @@ -100,8 +101,8 @@ def install_packages(packages): ] process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = process.communicate() - logging.info(f"Installing package: {package}. Full log in detail.", extra={"full_message": stdout}) process.poll() + logging.info("Installation finished: %s. Full log in detail.", package, extra={"full_message": stdout}) if process.poll() != 0: raise UserException(f"Failed to install package: {package}. Log in event detail.", stderr) elif stderr: