From cdf23f572f1b8fa1509b0a470affc9dfd37a5932 Mon Sep 17 00:00:00 2001 From: Gabriel Gerlero Date: Sun, 24 Mar 2024 21:43:21 -0300 Subject: [PATCH] Build Docker images --- .dockerignore | 160 ++++++++++++++++++++ .github/workflows/docker.yml | 51 +++++++ .github/workflows/dockerhub-description.yml | 28 ++++ Dockerfile | 16 ++ README.md | 2 +- 5 files changed, 256 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker.yml create mode 100644 .github/workflows/dockerhub-description.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e8bfaf4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,160 @@ +# Byte-compiled / optimized / DLL files +**/__pycache__/ +**/*.py[cod] +**/*$py.class + +# C extensions +**/*.so + +# Distribution / packaging +**/.Python +**/build/ +**/develop-eggs/ +**/dist/ +**/downloads/ +**/eggs/ +**/.eggs/ +**/lib/ +**/lib64/ +**/parts/ +**/sdist/ +**/var/ +**/wheels/ +**/share/python-wheels/ +**/*.egg-info/ +**/.installed.cfg +**/*.egg +**/MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +**/*.manifest +**/*.spec + +# Installer logs +**/pip-log.txt +**/pip-delete-this-directory.txt + +# Unit test / coverage reports +**/htmlcov/ +**/.tox/ +**/.nox/ +**/.coverage +**/.coverage.* +**/.cache +**/nosetests.xml +**/coverage.xml +**/*.cover +**/*.py,cover +**/.hypothesis/ +**/.pytest_cache/ +**/cover/ + +# Translations +**/*.mo +**/*.pot + +# Django stuff: +**/*.log +**/local_settings.py +**/db.sqlite3 +**/db.sqlite3-journal + +# Flask stuff: +**/instance/ +**/.webassets-cache + +# Scrapy stuff: +**/.scrapy + +# Sphinx documentation +**/docs/_build/ + +# PyBuilder +**/.pybuilder/ +**/target/ + +# Jupyter Notebook +**/.ipynb_checkpoints + +# IPython +**/profile_default/ +**/ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +**/__pypackages__/ + +# Celery stuff +**/celerybeat-schedule +**/celerybeat.pid + +# SageMath parsed files +**/*.sage.py + +# Environments +**/.env +**/.venv +**/env/ +**/venv/ +**/ENV/ +**/env.bak/ +**/venv.bak/ + +# Spyder project settings +**/.spyderproject +**/.spyproject + +# Rope project settings +**/.ropeproject + +# mkdocs documentation +/site + +# mypy +**/.mypy_cache/ +**/.dmypy.json +**/dmypy.json + +# Pyre type checker +**/.pyre/ + +# pytype static type analyzer +**/.pytype/ + +# Cython debug symbols +**/cython_debug/ + +# macOS +**/.DS_Store + +# VS Code +**/.vscode + +# Docker +**/Dockerfile +**/.dockerignore + +# Git +**/.git +**/.gitignore +**/.gitattributes + +# GitHub +**/.github + +# Dev Containers +**/.devcontainer +**/.devcontainer.json diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..cd56122 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,51 @@ +name: Docker + +on: + push: + branches: + - main + tags: + - '*' + pull_request: + branches: + - main + workflow_dispatch: + +env: + IMAGES: ${{ vars.DOCKERHUB_REPOSITORY || github.repository }} + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.IMAGES }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=pep440,pattern={{version}} + type=pep440,pattern={{major}}.{{minor}} + type=pep440,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }} + - name: Login to DockerHub + if: vars.DOCKERHUB_REPOSITORY + continue-on-error: ${{ github.event_name == 'pull_request' }} + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v5 + with: + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + push: ${{ github.event_name == 'push' }} diff --git a/.github/workflows/dockerhub-description.yml b/.github/workflows/dockerhub-description.yml new file mode 100644 index 0000000..26d6352 --- /dev/null +++ b/.github/workflows/dockerhub-description.yml @@ -0,0 +1,28 @@ +name: Update Docker Hub description +on: + push: + branches: + - main + paths: + - README.md + - .github/workflows/dockerhub-description.yml + workflow_dispatch: + +jobs: + dockerhub-description: + if: vars.DOCKERHUB_REPOSITORY + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Modify README.md for Docker Hub + run: | + sed -i "s|^\s*#\s\+\(.\+\)|# [\1]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY)|" README.md + - name: Update Docker Hub description + uses: peter-evans/dockerhub-description@v4 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + repository: ${{ vars.DOCKERHUB_REPOSITORY }} + short-description: ${{ github.event.repository.description }} + enable-url-completion: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fb4f7d3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM opencfd/openfoam-default:2312 + +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* \ + && pip install --no-cache-dir --upgrade pip + +COPY . /src/ + +RUN pip install --no-cache-dir /src \ + && rm -rf /src \ +# smoke test + && python3 -c 'import foamlib' + +CMD ["python3"] diff --git a/README.md b/README.md index 426eb84..7cf1ac7 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![PyPI](https://img.shields.io/pypi/v/foamlib)](https://pypi.org/project/foamlib/) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/foamlib)](https://pypi.org/project/foamlib/) - +[![Docker image](https://img.shields.io/badge/docker%20image-gerlero%2Ffoamlib-informational)](https://hub.docker.com/r/gerlero/foamlib/) **foamlib** provides a simple, modern and ergonomic Python interface for interacting with [OpenFOAM](https://www.openfoam.com).