Skip to content

Commit

Permalink
manage dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
submarcos committed Oct 8, 2024
1 parent 9fb4940 commit eb3a1e4
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
cd /app/src || exit

# Activate venv
. /app/venv/bin/activate
. /opt/venv/bin/activate

if [ "$COLLECTSTATIC" == "1" ]
then
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Check deps

on:
pull_request:
paths:
- setup.py
- requirements.txt
- requirements-dev.txt

env:
DEBIAN_FRONTEND: noninteractive

jobs:
quality:
name: Checking dependency graph
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['ubuntu-20.04']
python-version: ['3.8']

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python:v4
with:
cache: pip

- name: Install dependencies
run: |
pip3 install -c requirements-dev.txt pip-tools
- name: Check dependency graph
run: |
pip-compile -q --strip-extras
pip-compile -q --strip-extras requirements-dev.in
- name: Verify dependency graph is ok
uses: tj-actions/verify-changed-files@v20
id: verify-changed-files
with:
files: |
requirements.txt
requirements-dev.txt
- name: Validating graph
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |
echo "Dependency file(s) changed: ${{ steps.verify-changed-files.outputs.changed_files }}"
git diff
core.setFailed('Please add your new dependencies in setup.py and/or dev-requirements.in then run pip-compile to add them in requirements. (see docs/contribute/development)')
12 changes: 10 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
sudo apt-get update -q
Expand All @@ -85,11 +86,13 @@ jobs:
pip install -r requirements.txt -U
pip install -r requirements-dev.txt
npm ci
- name: Test with coverage
run: |
cd src
coverage run ./manage.py test
coverage run -a ./manage.py test --settings screamshotter.settings.test_timeout screenshotter.tests.CaptureTestCase.test_timeout_screenshot
- name: Coverage upload
run: |
pip install codecov
Expand All @@ -101,14 +104,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image
run: |
docker build -t screamshotter_ci:latest .
- name: Upload image
uses: ishworkh/docker-image-artifact-upload@v1
uses: ishworkh/docker-image-artifact-upload@v2
with:
image: "screamshotter_ci:latest"

Expand All @@ -123,6 +129,7 @@ jobs:
version: '20.04'
- os: jammy
version: '22.04'

env:
DISTRO: 'ubuntu:${{ matrix.os }}'
CODE: ${{ matrix.version }}
Expand Down Expand Up @@ -150,9 +157,10 @@ jobs:
name: Tests E2E docker
runs-on: ubuntu-latest
needs: [build_docker_image]

steps:
- name: Download image
uses: ishworkh/docker-image-artifact-download@v1
uses: ishworkh/docker-image-artifact-download@v2
with:
image: "screamshotter_ci:latest"

Expand Down
18 changes: 9 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ ENV MAX_REQUESTS=250
ENV PUPPETEER_CACHE_DIR=/app/puppeteer/

RUN useradd -ms /bin/bash django
RUN mkdir -p /app/static
RUN chown django:django /app
RUN mkdir -p /app/static /opt
RUN chown django:django /app /opt

RUN apt-get -qq update && apt-get install -qq -y \
gconf-service \
Expand Down Expand Up @@ -81,28 +81,28 @@ RUN apt-get -qq update && apt-get install -qq -y \
RUN wget https://bootstrap.pypa.io/get-pip.py && python3 get-pip.py && rm get-pip.py

USER django
RUN python3 -m venv /app/venv
RUN /app/venv/bin/pip3 install --no-cache-dir pip setuptools wheel -U
RUN python3 -m venv /opt/venv
RUN /opt/venv/bin/pip3 install --no-cache-dir pip setuptools wheel -U

COPY requirements.txt /app/
RUN /app/venv/bin/pip3 install --no-cache-dir -r /app/requirements.txt -U && rm /app/requirements.txt
RUN /app/venv/bin/nodeenv /app/venv/ -C '' -p -n 20.9.0
RUN /opt/venv/bin/pip3 install --no-cache-dir -r /app/requirements.txt -U && rm /app/requirements.txt
RUN /opt/venv/bin/nodeenv /app/venv/ -C '' -p -n 20.9.0

# upgrade npm & requirements
COPY package.json /app/package.json
COPY package-lock.json /app/package-lock.json
RUN . /app/venv/bin/activate && npm ci && rm /app/*.json
RUN . /opt/venv/bin/activate && npm ci && rm /app/*.json

FROM build AS dev

COPY requirements-dev.txt /app/
RUN /app/venv/bin/pip3 install --no-cache-dir -r /app/requirements-dev.txt -U && rm /app/requirements-dev.txt
RUN /opt/venv/bin/pip3 install --no-cache-dir -r /app/requirements-dev.txt -U && rm /app/requirements-dev.txt

CMD ["./manage.py", "runserver", "0.0.0.0:8000"]

FROM base

COPY --from=build /app/venv /app/venv
COPY --from=build /opt/venv /opt/venv
COPY --from=build /app/node_modules /app/node_modules
COPY --from=build /app/puppeteer /app/puppeteer
COPY src /app/src
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ build_deb:
docker run --name screamshotter_deb_run -t screamshotter_deb bash -c "exit"
docker cp screamshotter_deb_run:/dpkg ./
docker stop screamshotter_deb_run
docker rm screamshotter_deb_run
docker rm screamshotter_deb_run

deps:
docker compose run --rm web bash -c "pip-compile -q --strip-extras && pip-compile -q --strip-extras requirements-dev.in"
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
BASE_IMAGE: focal

volumes:
- ./src/:/app/src/
- ./:/app/
ports:
- "8000:8000"
environment:
Expand Down

0 comments on commit eb3a1e4

Please sign in to comment.