From 6b9196d395ac730336437d7af816bae4c4031362 Mon Sep 17 00:00:00 2001 From: Michael Tauraso Date: Fri, 25 Oct 2024 15:14:03 -0700 Subject: [PATCH] Fixing up Dockerfile, adding github action to build image - Image installs resspect from source - Image builds on latest ubuntu avoiding conflicts with ubuntu's version of pip - Image sets up a data directory and a venv for resspect - Image does not yet work with the docker-compose file or the TOM docker-compose ecosystem. --- .github/workflows/docker-build.yml | 32 ++++++++++++++++++++ Dockerfile | 47 ++++++++++++++++++++++-------- README.md | 2 +- 3 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/docker-build.yml diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 00000000..fbe73e43 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,32 @@ + +name: Build Docker image +# Shamelessly cribbed from https://docs.docker.com/build/ci/github-actions/test-before-push/ +# with minor modifications +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +env: + TEST_TAG: user/app:test + LATEST_TAG: user/app:latest + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and export to Docker + uses: docker/build-push-action@v6 + with: + load: true + tags: ${{ env.TEST_TAG }} + build-args: BUILDKIT_CONTEXT_KEEP_GIT_DIR=1 + + # TODO actually have this do something with test data + - name: Test + run: | + docker run --rm ${{ env.TEST_TAG }} -c "fit_dataset --help" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f4baef73..1d98e51b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,50 @@ FROM ubuntu -WORKDIR /resspect -ENV HOME / +ENV RESSPECT_DIR=/resspect +ENV RESSPECT_SRC=${RESSPECT_DIR}/resspect-src +ENV RESSPECT_VENV=${RESSPECT_DIR}/resspect-venv +ENV RESSPECT_VENV_BIN=${RESSPECT_VENV}/bin +ENV RESSPECT_WORK=${RESSPECT_DIR}/resspect-work + +WORKDIR ${RESSPECT_DIR} + +#ENV HOME=/ + RUN echo "entering resspect Dockerfile" -RUN apt-get update && \ +RUN apt-get update && \ apt-get -y upgrade && \ apt-get clean && \ - apt-get install -y python3 python3-pip postgresql-client && \ + apt-get install -y python3 python3-pip python3-venv postgresql-client git && \ rm -rf /var/lib/apt/lists/* RUN ln -s /usr/bin/python3 /usr/bin/python -RUN pip install --upgrade pip +# Copy over resspect source from local checkout +COPY . ${RESSPECT_SRC} + +# Create a venv for resspect +RUN python3 -m venv ${RESSPECT_VENV} + +# Use this venv for future python commands in this dockerfile +ENV PATH=${RESSPECT_VENV_BIN}:$PATH -COPY pyproject.toml ./pyproject.toml -RUN pip install dephell[full] && \ - dephell deps convert --from=pyproject.toml --to=requirements.txt && \ - pip install -r requirements.txt && \ - pip uninstall -y dephell && \ - rm -rf /root/.cache/pip +# Activate the venv every time we log in. +RUN touch /root/.bashrc && echo "source ${RESSPECT_VENV_BIN}/activate" >> /root/.bashrc +WORKDIR ${RESSPECT_SRC} +RUN pwd && ls -la && git describe --tags + +# Install resspect and dependencies to the venv +# XCXC TODO test pretend version + +#RUN SETUPTOOLS_SCM_PRETEND_VERSION_FOR_RESSPECT=0.2.dev36+2.0 SETUPTOOLS_SCM_DEBUG=1 pip install ${RESSPECT_SRC} +RUN SETUPTOOLS_SCM_PRETEND_VERSION_FOR_RESSPECT=35624a81ac270ce03b6d552eb3e2fbdb3eb6f985 SETUPTOOLS_SCM_DEBUG=1 pip install ${RESSPECT_SRC} + +# Create a sample work dir for resspect +RUN mkdir -p ${RESSPECT_WORK}/results +RUN mkdir -p ${RESSPECT_WORK}/plots +RUN cp -r ${RESSPECT_SRC}/data ${RESSPECT_WORK} EXPOSE 8081 ENTRYPOINT ["bash"] - diff --git a/README.md b/README.md index 6d22d738..438735ca 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,6 @@ Navigate to the repository folder and do You can now install this package with: - (RESSPECT) >>> python setup.py install + (RESSPECT) >>> pip install -e . > You may choose to create your virtual environment within the folder of the repository. If you choose to do this, you must remember to exclude the virtual environment directory from version control using e.g., ``.gitignore``.