Skip to content

Commit 597a81a

Browse files
Merge pull request #448 from RocketPy-Team/tst/update-workflows
ENH: workflows update and new docker files
2 parents f9ff423 + 93a062e commit 597a81a

File tree

8 files changed

+296
-23
lines changed

8 files changed

+296
-23
lines changed

.dockerignore

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Python files
2+
__pycache__/
3+
*.pyc
4+
*.pyo
5+
*.pyd
6+
.Python
7+
db.sqlite3
8+
/db.sqlite3
9+
pip-log.txt
10+
pip-delete-this-directory.txt
11+
.pytest_cache/
12+
13+
# Documentation and Tests
14+
docs/
15+
.coverage
16+
readthedocs.yml
17+
.travis.yml
18+
Makefile
19+
20+
# Binary and Package files
21+
*.egg-info/
22+
*.egg
23+
dist/
24+
build/
25+
26+
# VCS
27+
.git/
28+
.gitignore
29+
.gitattributes
30+
.github/
31+
32+
# IDEs and Editors
33+
.vscode
34+
35+
# Virtual environments
36+
.venv
37+
venv
38+
ENV/
39+
env/
40+
41+
# Others
42+
*.log
43+
44+
# Docker
45+
Dockerfile
46+
.dockerignore

.github/workflows/test_pytest.yaml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ on:
55
types: [opened, synchronize, reopened, ready_for_review]
66
paths:
77
- "**.py"
8+
- ".github/**"
89

910
jobs:
10-
fail_if_pull_request_is_draft:
11+
fail_if_pr_is_draft:
1112
if: github.event.pull_request.draft == true
1213
runs-on: ubuntu-18.04
1314
steps:
1415
- name: Fails in order to indicate that pull request needs to be marked as ready to review and unit tests workflow needs to pass.
1516
run: exit 1
16-
run_pytest_and_doctest:
17+
pytest_and_doctest:
1718
runs-on: ${{ matrix.os }}
1819
strategy:
1920
matrix:
@@ -23,7 +24,10 @@ jobs:
2324
- windows-latest
2425
python-version:
2526
- 3.8
26-
- 3.11
27+
- 3.12
28+
env:
29+
OS: ${{ matrix.os }}
30+
PYTHON: ${{ matrix.python-version }}
2731
steps:
2832
- uses: actions/checkout@v2
2933
- name: Set up Python ${{ matrix.python-version }}
@@ -44,6 +48,17 @@ jobs:
4448
pip install -r requirements-tests.txt
4549
- name: Test with pytest
4650
run: |
47-
pytest
51+
pytest --cov=rocketpy --cov-report=xml
4852
cd rocketpy
49-
pytest --doctest-modules
53+
pytest --doctest-modules --cov=rocketpy --cov-report=xml
54+
- name: Upload coverage report to Codecov
55+
uses: codecov/codecov-action@v3
56+
with:
57+
token: ${{ secrets.CODECOV_TOKEN }}
58+
directory: ./coverage/reports/
59+
env_vars: OS,PYTHON
60+
fail_ci_if_error: true
61+
files: ./coverage.xml, ./rocketpy/coverage.xml
62+
flags: unittests
63+
name: codecov-umbrella
64+
verbose: true

.travis.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Set base image
2+
# python:latest will get the latest version of python, on linux
3+
# Get a full list of python images here: https://hub.docker.com/_/python/tags
4+
FROM python:latest
5+
6+
# set the working directory in the container
7+
WORKDIR /RocketPy
8+
9+
# Ensure pip is updated
10+
RUN python3 -m pip install --upgrade pip
11+
12+
# Copy the dependencies file to the working directory
13+
COPY requirements.txt .
14+
COPY requirements-tests.txt .
15+
16+
# Install dependencies
17+
# Use a single RUN instruction to minimize the number of layers
18+
RUN pip install \
19+
-r requirements.txt \
20+
-r requirements-tests.txt
21+
22+
# copy the content of the local src directory to the working directory
23+
COPY . .
24+
25+
# command to run on container start
26+
# print the operational system and the python version
27+
CMD [ "python3", "-c", "import platform;import sys; print('Python ', sys.version, ' running on ', platform.platform())" ]
28+
29+
# Install the rocketpy package # TODO: check if I can put this in editable mode
30+
RUN pip install .

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/RocketPy-Team/rocketpy/blob/master/docs/notebooks/getting_started_colab.ipynb)
1010
[![PyPI](https://img.shields.io/pypi/v/rocketpy?color=g)](https://pypi.org/project/rocketpy/)
1111
[![Documentation Status](https://readthedocs.org/projects/rocketpyalpha/badge/?version=latest)](https://docs.rocketpy.org/en/latest/?badge=latest)
12+
[![codecov](https://codecov.io/gh/RocketPy-Team/RocketPy/graph/badge.svg?token=Ecc3bsHFeP)](https://codecov.io/gh/RocketPy-Team/RocketPy)
1213
[![Contributors](https://img.shields.io/github/contributors/RocketPy-Team/rocketpy)](https://github.com/RocketPy-Team/RocketPy/graphs/contributors)
1314
[![Chat on Discord](https://img.shields.io/discord/765037887016140840?logo=discord)](https://discord.gg/b6xYnNh)
1415
[![Sponsor RocketPy](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/RocketPy-Team)

docker-compose.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: '3.8'
2+
3+
services:
4+
python38-linux:
5+
image: python:3.8
6+
volumes:
7+
- .:/app
8+
working_dir: /app
9+
command: bash -c "pip install . && pip install -r requirements-tests.txt && pytest && cd rocketpy && pytest --doctest-modules"
10+
logging:
11+
options:
12+
max-size: "10m"
13+
max-file: "3"
14+
15+
python312-linux:
16+
image: python:3.12
17+
volumes:
18+
- .:/app
19+
working_dir: /app
20+
command: bash -c "pip install . && pip install -r requirements-tests.txt && pytest && cd rocketpy && pytest --doctest-modules"
21+
logging:
22+
options:
23+
max-size: "10m"
24+
max-file: "3"

docs/development/docker.rst

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
RocketPy with docker
2+
=====================
3+
4+
RocketPy does not provide an official docker image, but you can build one
5+
yourself using the provided `Dockerfile` and `docker-compose.yml` files.
6+
7+
Benefits
8+
--------
9+
10+
Docker allows you to run applications in containers. The main benefits of
11+
using docker are:
12+
13+
1. **Isolation**: run RocketPy in a fresh environment, without
14+
worrying about dependencies.
15+
2. **Portability**: run RocketPy on any operational system that supports
16+
docker, including the 3 main operational systems (Windows, Linux and Mac).
17+
3. **Reproducibility**: ensure that tour code is working regardless of the
18+
operational system.
19+
20+
Using docker will be specially important when you are not sure if the code
21+
additions will still run on different operational systems.
22+
23+
Although we have a set of GitHub actions to test the code on different
24+
operational systems every time a pull request is made, it is important to
25+
submit a PR only after you are sure that the code will run flawlessly,
26+
otherwise quota limits may be reached on GitHub.
27+
28+
Requirements
29+
-------------
30+
31+
Before you start, you need to install on your machine:
32+
33+
1. `Docker <https://docs.docker.com/get-docker/>`__, to build and run the image.
34+
2. `Docker Compose <https://docs.docker.com/compose/install/>`__, to compose multiple images at once.
35+
3. Also, make sure you have cloned the RocketPy repository in your machine!
36+
37+
Build the image
38+
----------------
39+
40+
To build the image, run the following command on your terminal:
41+
42+
.. code-block:: console
43+
44+
docker build -t rocketpy-image -f Dockerfile .
45+
46+
47+
This will build the image and tag it as `rocketpy-image` (you can apply another
48+
name of your preference if you want).
49+
50+
An image is a read-only template with instructions for creating a Docker
51+
container (see `Docker docs <https://docs.docker.com/get-started/overview/#docker-objects>`__).
52+
53+
This process may take a while, since it will create an image that could easily
54+
be 1.5 GB in size.
55+
But don't worry, you just need to build the image once.
56+
57+
Run the container
58+
-----------------
59+
60+
Now that you have the image, you can run it as a container:
61+
62+
.. code-block:: console
63+
64+
docker run -it --entrypoint /bin/bash rocketpy-image
65+
66+
67+
This will run the container and open a bash terminal inside it.
68+
If you are using VSCode, you can even integrate the running container into your
69+
IDE, allowing you to code and test directly within the container environment.
70+
This is particularly useful if you want to maintain your usual development setup
71+
while ensuring consistency in the execution environment.
72+
For more details on how to do this, refer to the
73+
`VSCode docs <https://code.visualstudio.com/docs/remote/containers>`__
74+
on developing inside a container.
75+
76+
Indeed, vscode offers a full support for docker, read the
77+
`vscode docs <https://code.visualstudio.com/docs/containers/overview#_installation>`__
78+
for more details
79+
80+
81+
Run the unit tests
82+
--------------------
83+
84+
You might have noticed that the container is running in an isolated environment
85+
with no access to your machine's files, but the `Dockerfile` already copied the
86+
RocketPy repository to the container.
87+
This means that you can run tests (and simulations!) as if you were running
88+
RocketPy on your machine.
89+
90+
As simple as that, you can run the unit tests:
91+
92+
.. code-block:: console
93+
94+
pytest
95+
96+
97+
To access a list of all available execution options, see the
98+
`pytest docs <https://docs.pytest.org/en/latest/how-to/usage.html>`__.
99+
100+
Compose docker images
101+
---------------------
102+
103+
We also made available a `docker-compose.yml` file that allows you to compose
104+
multiple docker images at once.
105+
Unfortunately, this file will not allow you to test the code on different
106+
operational systems at once, since docker images inherits from the host
107+
operational system.
108+
However, it is still useful to run the unit tests on different python versions.
109+
110+
Currently, the `docker-compose.yml` file is configured to run the unit tests
111+
on python 3.8 and 3.12.
112+
113+
To run the unit tests on both python versions, run the following command
114+
**on your machine**:
115+
116+
.. code-block:: console
117+
118+
docker-compose up
119+
120+
Also, you can check the logs of the containers by running:
121+
122+
.. code-block:: console
123+
124+
docker-compose logs
125+
126+
127+
This command is especially useful for debugging if any issues occur during the
128+
build process or when running the containers.
129+
130+
After you're done testing, or if you wish to stop the containers and remove the
131+
services, use the command:
132+
133+
.. code-block:: console
134+
135+
docker-compose down
136+
137+
138+
This will stop the running containers and remove the networks, volumes, and
139+
images created by up.
140+
141+
142+
Changing to other operational systems
143+
-------------------------------------
144+
145+
The default image in the `Dockerfile` is based on a Linux distribution.
146+
However, you can alter the base image to use different operating systems, though
147+
the process may require additional steps depending on the OS's compatibility
148+
with your project setup.
149+
For instance, certain dependencies or scripts may behave differently or require
150+
different installation procedures, so use it with caution.
151+
152+
To change the base image, you will need to modify the `FROM` statement in the
153+
`Dockerfile`.
154+
For example, to use a Windows-based image, you might change:
155+
156+
.. code-block:: Dockerfile
157+
158+
FROM python:latest
159+
160+
161+
to
162+
163+
.. code-block:: Dockerfile
164+
165+
FROM mcr.microsoft.com/windows/servercore:ltsc2019
166+
167+
168+
Please note, the above is just an example, and using a different OS may require
169+
further adjustments in the `Dockerfile`.
170+
We recommend you to see the official Python images on the Docker Hub for
171+
different OS options: `Docker Hub Python Tags <https://hub.docker.com/_/python/tags>`__.
172+
173+
Be aware that switching to a non-Linux image can lead to larger image sizes and
174+
longer pull times.

docs/development/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Contributing to RocketPy
88
Running RocketPy as a Developer <rocketpy_as_developer.rst>
99
GitHub Workflow for RocketPy Hackathon 2022 <github_hackathon.rst>
1010
Style Guide <style_guide>
11+
RocketPy with Docker <docker.rst>
1112
Building the Documentation <build_docs.rst>
1213

1314
This section is still a work in progress. Here you will find information on how to contribute to our code base.

0 commit comments

Comments
 (0)