Skip to content

Commit

Permalink
improving docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed May 10, 2022
1 parent 5b29e0c commit 6fbfa0c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
24 changes: 19 additions & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.231.6/containers/python-3/.devcontainer/base.Dockerfile
# ideas from https://www.docker.com/blog/containerized-python-development-part-1/

# This file is for use as a .vscode devcontainer as well as a runtime
# container. The devcontainer should be rootful and use podman or docker
# with user namespaces
ARG BASE="mcr.microsoft.com/vscode/devcontainers/python:0-3.10-bullseye"
FROM ${BASE} as base

# use root to pin where the packages will install
USER root
ENV PATH=/root/.local/bin:$PATH

# things to make pyQt5 work
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && \
apt-get install -y --no-install-recommends \
Expand All @@ -14,10 +21,17 @@ RUN apt-get install -y x11-apps

FROM base as developer

COPY . workspace
WORKDIR /workspace
COPY . .
RUN ls -R

# install runtime from DIST if there is one
RUN test -d /workspace/dist && pip install $([ -f requirements.txt ] && echo -r requirements.txt ) /workspace/dist/*.whl || :
RUN mkdir -p /root/.local && \
test -d dist && \
requirements=$(test -f requirements.txt && echo -r requirements.txt) \
pip install --user $requirements dist/*.whl || :

FROM developer as runtime
FROM base as runtime
COPY --from=developer /root/.local /root/.local

CMD ["dls-pmac-control"]
CMD ["dls-pmac-control"]
22 changes: 14 additions & 8 deletions .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
uses: actions/upload-artifact@v2
with:
name: dist
path: dist/*
path: dist

- name: Install minimum python version
uses: actions/setup-python@v2
Expand All @@ -66,6 +66,7 @@ jobs:
# ${GITHUB_REPOSITORY##*/} is the repo name without org
# Replace this with the cli command if different to the repo name
run: pipx run --python $(which python${{ matrix.python }}) --spec dist/*.whl ${GITHUB_REPOSITORY##*/} --version

test:
strategy:
fail-fast: false
Expand Down Expand Up @@ -103,8 +104,9 @@ jobs:
run: |
set -x
pip install pip --upgrade
echo "this_package=$(sed -n '/^ *name *= *\(.*\)$/s//\1/p' setup.cfg)" >> $GITHUB_ENV
if [ ! -e requirements.txt ]; then pip install -e . && pip freeze --exclude ${this_package} > requirements.txt; fi
if [ ! -e requirements.txt ]; then pip install -e . && pip freeze --exclude-editable > requirements.txt; fi
# TODO: need to think about the interaction of the two lock files. If there are both files then the
# requirements.txt controls what goes in runtime container, but may not be the same as what was tested here

- name: run tests
run: |
Expand All @@ -116,7 +118,7 @@ jobs:
- name: create requirements_dev.txt
if: ${{ matrix.lock == 'true' }}
run: |
pip freeze --exclude ${this_package} > requirements_dev.txt
pip freeze --exclude-editable > requirements_dev.txt
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
Expand Down Expand Up @@ -147,7 +149,8 @@ jobs:
# https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v0.1.14
with:
files: artifacts/dist/*
files: |
artifacts/dist/*
artifacts/lockfiles/requirements.txt
artifacts/lockfiles/requirements_dev.txt
generate_release_notes: true
Expand All @@ -162,7 +165,7 @@ jobs:

make-container:
#needs: [lint, wheel, test]
needs: [wheel]
needs: wheel
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -181,6 +184,8 @@ jobs:
- uses: actions/download-artifact@v2
with:
name: dist
path: dist
- run: ls -R

- name: Cache Docker layers
uses: actions/cache@v2
Expand Down Expand Up @@ -212,9 +217,10 @@ jobs:
with:
builder: ${{ steps.buildx.outputs.name }}
file: .devcontainer/Dockerfile
# push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
context: "."
push: true
build-args: --build-arg BASE=python:3.10-slim
build-args: |
BASE=python:3.10-slim
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
Expand Down

0 comments on commit 6fbfa0c

Please sign in to comment.