diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c49bb68 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +docs +tests +.github +.nox +.venv diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index a231563..a286861 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -3,18 +3,25 @@ name: Docker on: push: branches: - - '*' + - main tags: - '*' paths-ignore: - 'docs/**' + pull_request: + branches: + - main jobs: docker: - runs-on: ubuntu-latest + name: Docker + + runs-on: ubuntu-24.04 + env: USER: sdss APP: lvmguider + steps: - name: Set docker tags id: set-tags @@ -26,23 +33,33 @@ jobs: then BRANCH=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's/[\/]/_/g') echo TAGS=$USER/$APP:$BRANCH >> $GITHUB_OUTPUT + elif [[ $GITHUB_REF == refs/pull/* ]] + then + BRANCH=${{ github.head_ref || github.ref_name }} + echo TAGS=$USER/$APP:$BRANCH >> $GITHUB_OUTPUT else echo TAGS=$USER/$APP:${GITHUB_REF#refs/tags/} >> $GITHUB_OUTPUT fi + - name: Show tags run: echo ${{ steps.set-tags.outputs.TAGS }} + - name: Set up QEMU uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Log in to registry run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin + - name: Build and push id: docker_build uses: docker/build-push-action@v6 with: - file: docker/Dockerfile push: true + provenance: false tags: ghcr.io/${{ steps.set-tags.outputs.TAGS }} + - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index fb2cb3a..a551fbe 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,19 +12,23 @@ jobs: lint: name: Lint - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 + - name: Install uv + uses: astral-sh/setup-uv@v5 + with: + enable-cache: true + - name: Set up Python uses: actions/setup-python@v5 with: - python-version: '3.12' - cache: 'pip' + python-version: '3.13' - name: Lint with ruff run: | - pip install ruff + uv tool install ruff ruff check src/ tests/ ruff format --check src/ tests/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 93265a6..2840c72 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,7 @@ jobs: release: name: Build and publish - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 permissions: contents: write @@ -27,7 +27,7 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} - name: Install uv - uses: astral-sh/setup-uv@v4 + uses: astral-sh/setup-uv@v5 with: enable-cache: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..0d190a0 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,51 @@ +name: Test + +on: + push: + paths-ignore: + - 'docs/**' + pull_request: + paths-ignore: + - 'docs/**' + +jobs: + test: + name: Test + + runs-on: ubuntu-24.04 + + strategy: + fail-fast: false + matrix: + python-version: ['3.10', '3.11', '3.12', '3.13'] + + env: + OBSERVATORY: 'LCO' + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install uv + uses: astral-sh/setup-uv@v5 + with: + enable-cache: true + + - name: Install dependencies + run: | + uv sync --no-dev --frozen + + - name: Test with pytest + run: | + uv pip install pytest pytest-mock pytest-asyncio pytest-cov + uv run pytest + + # - name: Upload coverage to Codecov + # uses: codecov/codecov-action@v5 + # with: + # token: ${{ secrets.CODECOV_TOKEN }} + # files: ./coverage.xml diff --git a/docker/Dockerfile b/docker/Dockerfile index 0856b05..062feec 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,7 +1,8 @@ -FROM python:3.11-slim-bookworm +FROM python:3.12-slim-bookworm +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ -MAINTAINER Jose Sanchez-Gallego, gallegoj@uw.edu -LABEL org.opencontainers.image.source https://github.com/sdss/lvmguider +LABEL org.opencontainers.image.authors="Jose Sanchez-Gallego, gallegoj@uw.edu" +LABEL org.opencontainers.image.source=https://github.com/sdss/lvmguider WORKDIR /opt @@ -15,22 +16,25 @@ COPY docker/matplotlibrc /root/.config/matplotlib/ COPY docker/LiberationSerif-Regular.ttf /usr/share/fonts/ # Refresh system font cache -RUN apt update -y -RUN apt install -y fontconfig +RUN apt-get update -y +RUN apt-get install -y fontconfig RUN fc-cache -f -v # Refresh matplotlib font cache RUN rm -fr ~/.cache/matplotlib -RUN apt install -y build-essential -RUN apt install -y astrometry.net +RUN apt-get install -y build-essential +RUN apt-get install -y astrometry.net # Ignore warnings about installing as packages with pip as root. ENV PIP_ROOT_USER_ACTION=ignore -RUN pip3 install -U pip setuptools wheel -RUN cd lvmguider && pip3 install . -RUN rm -Rf lvmguider +ENV UV_COMPILE_BYTECODE=1 +ENV UV_LINK_MODE=copy +ENV PATH="$PATH:/opt/lvmguider/.venv/bin" + +# Sync the project +RUN cd lvmguider && uv sync --frozen --no-cache --no-dev # Set umask so that new files inherit the parent folder permissions. # Not sure this works so we are also setting the permissions in the entrypoint. diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index d398279..33d9afa 100644 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -1,5 +1,5 @@ #!/bin/bash umask 0002 -pip3 install -U astropy-iers-data +uv pip install -U astropy-iers-data exec "$@"