Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue for building docker container #91

Merged
merged 10 commits into from
Dec 13, 2024

Conversation

luclaurent
Copy link
Collaborator

Many improvements and updates on

  • workflow (update versions and missing id
  • Dockerfile to use new setup version and new testing

@luclaurent luclaurent linked an issue Nov 29, 2024 that may be closed by this pull request
@luclaurent
Copy link
Collaborator Author

Note that ths proposition will not work directly due to missing credentials for ghcr. You must update them @nennigb.

@@ -13,24 +13,25 @@ jobs:
name: 'Build amc2moodle container'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest @main instead of @v4 for all actions.
Since the version doesn't matter, @main allow to use always the last version.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution @main is not always available (check for @master)

"-p",
"test_*.py"
],
"python.testing.pytestEnabled": false,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file really required ?

Copy link
Collaborator Author

@luclaurent luclaurent Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not with the future new version using pyproject.toml (vscode will read it to identify tests)

Copy link
Collaborator Author

@luclaurent luclaurent Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it in future version see #90

return cls
return decorate

def decorator_set_cwd(directory):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps there are more pythonic way to do this ?
Defined in unittest famework ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know but it works well :-)

python3-venv \
git && \
apt clean &&\
rm -rf /var/lib/{apt,dpkg,cache,log}/

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to use apt-get (to avoid WARNING: apt does not have a stable CLI interface. Use with caution in scripts.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

RUN pip3 install -U pip && \
pip3 install .
RUN mkdir -p ${VENVDIR} && \
python -m venv ${VENVDIR}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why installing the package in a venv ?
No problem with that, I am just curious ;-)
Doesn't seems to create problem.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in order to avoid "error: externally-managed-environment" when use the system python/pip

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok :-)

python3-venv \
git && \
apt clean &&\
rm -rf /var/lib/{apt,dpkg,cache,log}/

# move policy file
RUN mv /etc/ImageMagick-6/policy.xml /etc/ImageMagick-6/policy.xml.off
Copy link
Owner

@nennigb nennigb Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my tests, docker install imageMagick 7 thus the path is wrong.
In interactive session it seems to work without this line. The default policy has changed in v7, perhaps we could just comment this line.
To see the policy in v7

magick identify -list policy

https://imagemagick.org/script/security-policy.php

Normally it should be catch in the unittests with the tinymonk.pdf file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

python -m amc2moodle.moodle2amc.test


RUN python -m pytest --pyargs amc2moodle
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI will fail until

[project.optional-dependencies]
test = ["pytest", "pytest-cov[all]"]

will be merged into the master branch used for docker build.
We could merge by the way.

pyproject.toml Outdated
@@ -26,6 +26,10 @@ dependencies = [
]
requires-python='>=3.8'

[project.optional-dependencies]
test = ["pytest", "pytest-cov[all]"]
lint = [ "black", "flake8"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default
https://hatch.pypa.io/1.13/config/internal/static-analysis/
hatch use ruff: https://github.com/astral-sh/ruff, 99.9% compatible with black.
Not sure we need this line: lint = [ "black", "flake8"]
Perhaps we could also configure ruff or have a discussion on rules

hatch default is line 120, which looks good for me. It could be put in the pyproject.toml to avoid changes

[tool.ruff]
# Allow lines to be as long as 120.
line-length = 120

I prefer simple quotes which is the present convention and looks less bulky.

[tool.ruff.format]
quote-style = "single"

If we choose ruff, we need to modify the readme.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add it

@nennigb
Copy link
Owner

nennigb commented Dec 4, 2024

Another thing to fix (one day) would be the log that grows indefinitely if the docker is not stopped.
In my opinion it is not a big issue since it not the heart of the project.

* update pyproject.toml to integrate the use of ruff as code analyser
* update Docker's files (Dockerfile, README, bash script) to ensure logrotation and a few fixes
* many improvments of typos
* update workflow to use @main on actions
@luclaurent
Copy link
Collaborator Author

luclaurent commented Dec 12, 2024

Another thing to fix (one day) would be the log that grows indefinitely if the docker is not stopped. In my opinion it is not a big issue since it not the heart of the project.

I integrate a new management of the logs for amc2moodle and moodle2amc. I use logrotate with a maximum size of the log of 5MB, keeping only 3 old logs and run logrotate every 60s. Note that the --silent option has been removed in the bash script to allow logging on the daemon log.

Copy link
Owner

@nennigb nennigb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it goods. You can have a look on the detailed the comments.
I let you merge when you are ready.

@@ -15,19 +15,28 @@ The container proposes to mount two volumes:
- `/tmp/work` (**mandatory mount**) that must be link to a specific folder on the host computer
- `/tmp/daemon` (optional mount) that store the log file of the daemon

For instance, the container can be run in CLI (in detached mode) with the following command:
For instance, the container can be run in CLI (in detached mode) with the following command (*by relacing `DIRA` and if necessary `DIRB`):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo "replacing"

In case of permission issue to mount folder(s), consider adding option `--user "$(id -u):$(id -g)"` such as the running command is:

```
docker run --name amc2moodle --user "$(id -u):$(id -g)" -d -v "DIRA:/tmp/work" -v "DIRB:/tmp/daemon" ghcr.io/nennigb/amc2moodle
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks :-)


#log manage
now=$(date +"%Y-%m-%d_%H-%M-%s")
mkdir -p ${LOG_DIR}
LOGFILE=${LOG_DIR}/${now}_autorun.log
init_logrotate
run_logrotate &

{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems goods. I run test and log looks good. The rotation also works well.

@nennigb
Copy link
Owner

nennigb commented Dec 13, 2024

Just a question the modification with f strings were automatic or manual ?
I checked most of them but just in case.

@luclaurent
Copy link
Collaborator Author

Just a question the modification with f strings were automatic or manual ? I checked most of them but just in case.

I ran hatch fmt by mistake. The correct syntax to only check is --check. But after that, I kept the changes ...

@luclaurent luclaurent merged commit fa5d577 into master Dec 13, 2024
24 checks passed
@luclaurent luclaurent deleted the fix-issue-for-building-docker-container branch December 13, 2024 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix issue for building docker container
2 participants