Skip to content

Commit

Permalink
Add .dockerignore file
Browse files Browse the repository at this point in the history
Adds a dockerignore file instructs docker to skip copying several
unnecessary files and directories into the docker image. Aside from
prevented unnecessary image bloat, it also improves image build caching
since the skipped files are the ones likely to change between builds.
The .git directory is excluded, which means that the labgrid version
must be passed as a build argument since it cannot be determined by
setup.py automatically.

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
  • Loading branch information
JPEWdev authored and Emantor committed Feb 26, 2021
1 parent 2bca1c6 commit b36a9cf
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
*.pyc
*__pycache__
*console_main
.*.swp
.cache
/MANIFEST
.tox
/.#tox.ini
/.eggs/README.txt
*.egg
*.egg-info
/venv*
/build
/doc/.build
/doc/modules
/.coverage
/dist
/.pytest_cache/
/htmlcov/
/.idea
*/__pycache__

/dockerfiles/
!/dockerfiles/exporter/entrypoint.sh
.git/
4 changes: 4 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install system dependencies
run: |
sudo apt install -yq python3-pip
python3 -m pip install --upgrade pip setuptools wheel
- name: Login to DockerHub
uses: docker/login-action@v1
with:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install system dependencies
run: |
sudo apt install -yq python3-pip
python3 -m pip install --upgrade pip setuptools wheel
- name: Build docker images
run: |
./dockerfiles/build.sh
Expand Down
9 changes: 6 additions & 3 deletions dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ RUN set -e ;\
# Client
#
FROM labgrid-base AS labgrid-client
ARG VERSION

RUN set -e ;\
cd /opt/labgrid ;\
pip3 install yq ;\
pip3 install --no-cache-dir -r requirements.txt ;\
python3 setup.py install ;\
SETUPTOOLS_SCM_PRETEND_VERSION="$VERSION" python3 setup.py install ;\
apt update -q=2 ;\
apt install -q=2 --yes --no-install-recommends microcom openssh-client sshpass rsync jq qemu-system; \
apt clean ;\
Expand All @@ -35,13 +36,14 @@ CMD ["/bin/bash"]
# Coordinator
#
FROM labgrid-base AS labgrid-coordinator
ARG VERSION

ENV CROSSBAR_DIR=/opt/crossbar

RUN set -e ;\
cd /opt/labgrid ;\
pip3 install --no-cache-dir -r crossbar-requirements.txt ;\
python3 setup.py install
SETUPTOOLS_SCM_PRETEND_VERSION="$VERSION" python3 setup.py install

VOLUME /opt/crossbar

Expand Down Expand Up @@ -101,13 +103,14 @@ RUN cd /src && \
# Exporter
#
FROM labgrid-base AS labgrid-exporter
ARG VERSION

COPY dockerfiles/exporter/entrypoint.sh /entrypoint.sh

RUN set -e ;\
cd /opt/labgrid ;\
pip3 install --no-cache-dir -r requirements.txt ;\
python3 setup.py install ;\
SETUPTOOLS_SCM_PRETEND_VERSION="$VERSION" python3 setup.py install ;\
apt update -q=2 ;\
apt install -q=2 --yes --no-install-recommends \
libyaml-0-2 \
Expand Down
5 changes: 4 additions & 1 deletion dockerfiles/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ set -ex

export DOCKER_BUILDKIT=1

VERSION="$(./setup.py --version | tail -1)"

for t in client exporter coordinator; do
docker build --target labgrid-${t} -t labgrid-${t} -f dockerfiles/Dockerfile .
docker build --build-arg VERSION="$VERSION" \
--target labgrid-${t} -t labgrid-${t} -f dockerfiles/Dockerfile .
done

0 comments on commit b36a9cf

Please sign in to comment.