Skip to content

Commit

Permalink
Split Dockerfile into 2 images: cacher and cacher-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
isudak authored Apr 8, 2024
1 parent aef1bfe commit e643a0d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
target: cacher-tests
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
Expand All @@ -73,7 +74,7 @@ jobs:
- name: Run pytest
run: |
docker compose run --rm cacher bash -c "
docker compose run --rm cacher_tests bash -c "
pytest -v --cov \
--junit-xml=$REPORTS_DIR/pytest-report.xml \
--cov-report=xml:$REPORTS_DIR/pytest-coverage.xml \
Expand All @@ -82,28 +83,28 @@ jobs:
- name: Run pylint
if: ${{ steps.changed-files.outputs.src == 'true' }}
run: |
docker compose run --rm cacher bash -c "
docker compose run --rm cacher_tests bash -c "
pylint --exit-zero ${{ steps.changed-files.outputs.src_files }} \
| tee $REPORTS_DIR/pylint-report.txt"
- name: Run black
if: ${{ steps.changed-files.outputs.py == 'true' }}
run: |
docker compose run --rm cacher bash -c "
docker compose run --rm cacher_tests bash -c "
black --check --diff --color ${{ steps.changed-files.outputs.py_files }} \
| tee >(sed 's/\x1B\[[0-9;]*m//g' > $REPORTS_DIR/black-report.txt)"
- name: Run isort
if: ${{ steps.changed-files.outputs.py == 'true' }}
run: |
docker compose run --rm cacher bash -c "
docker compose run --rm cacher_tests bash -c "
isort --check-only --diff --color ${{ steps.changed-files.outputs.py_files }} \
| tee >(sed 's/\x1B\[[0-9;]*m//g' > $REPORTS_DIR/isort-report.txt)"
- name: Run bandit
if: ${{ steps.changed-files.outputs.src == 'true' }}
run: |
docker compose run --rm cacher bash -c "
docker compose run --rm cacher_tests bash -c "
bandit -c pyproject.toml ${{ steps.changed-files.outputs.src_files }} \
| tee >(sed 's/\x1B\[[0-9;]*m//g' > $REPORTS_DIR/bandit-report.txt)"
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
target: cacher-tests
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
Expand All @@ -38,7 +39,7 @@ jobs:
- name: Run pytest
id: pytest
run: |
docker compose run --rm cacher bash -c "
docker compose run --rm cacher_tests bash -c "
pytest -v --cov \
--cov-report=json:$REPORTS_DIR/pytest-report.json \
--cov-report=term | tee $REPORTS_DIR/pytest-output.txt"
Expand Down
18 changes: 14 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM almalinux:9
FROM almalinux:9 as cacher

RUN <<EOT
set -ex
Expand All @@ -15,12 +15,22 @@ RUN <<EOT
EOT

WORKDIR /code
COPY requirements.* .
COPY requirements.txt .
RUN <<EOT
set -ex
python3 -m ensurepip
pip3 install -r requirements.devel.txt
rm requirements.*
pip3 install -r requirements.txt
rm requirements.txt
EOT

ADD --chmod=755 https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh /


FROM cacher as cacher-tests

COPY requirements-tests.txt .
RUN <<EOT
set -ex
pip3 install -r requirements-tests.txt
rm requirements-tests.txt
EOT
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ services:
image: alma-tests-cacher:latest
build:
context: .
target: cacher
command: "python3 alma_tests_cacher.py"
volumes:
- ".:/code"

cacher_tests:
image: alma-tests-cacher-tests:latest
build:
context: .
target: cacher-tests
volumes:
- ".:/code"
2 changes: 0 additions & 2 deletions requirements.devel.txt → requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
-r requirements.txt

anyio==4.3.0

pytest==8.1.1
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
aiohttp==3.9.1
aiohttp==3.9.3
pydantic==2.5.3
pydantic-settings==2.1.0
sentry-sdk==1.39.1
Expand Down

0 comments on commit e643a0d

Please sign in to comment.