Skip to content

Commit

Permalink
📝 Add automatic building of Docker containers
Browse files Browse the repository at this point in the history
  • Loading branch information
veit committed Jul 15, 2024
1 parent adf5193 commit aeae7c3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
51 changes: 51 additions & 0 deletions docs/productive/git/advanced/gitlab/docker.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Building Docker containers
==========================

We use :doc:`ci-cd`, to create our Python Docker containers.

#. First, we define the Python version in our :ref:`pyproject-toml` file of the
project:

.. code-block:: toml
[project]
name = "my-app"
requires-python = "==3.12.*"
#. We then extract this string in our :file:`.gitlab-ci.yml` file and pass it as
a build argument to ``docker build``:

.. code-block:: yaml
build:
stage: build
only: [main]
script:
- export PY=$(sed -nE 's/^requires-python = "==(3\.[0-9]+)\.*"$/python\1/p' pyproject.toml)
- >
docker build
--build-arg PY=$PY
#. Finally, we can use the extracted version in the Dockerfile to create a
virtual environment in the build phase and install the Python version in the
``application`` stage:

.. code-block:: docker
:emphasize-lines: 3, 6
FROM your-docker/build-image as build
ARG PY
RUN --mount=type=cache,target=/root/.cache \
set -ex \
&& virtualenv --python $PY /app
FROM your-docker/app-image
RUN set -ex \
&& apt-get update -qy \
&& apt-get install -qy \
-o APT::Install-Recommends=false \
-o APT::Install-Suggests=false \
COPY --from=build --chown=app /app /app
16 changes: 10 additions & 6 deletions docs/productive/git/advanced/gitlab/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ GitLab
======

`GitLab <https://gitlab.com>`_ is a web application for version management based
on Git. Later, further functions were added such as an issue tracking system with
Kanban board, a system for `Continuous Integration and Continuous Delivery
on Git. Later, further functions were added such as an issue tracking system
with Kanban board, a system for `Continuous Integration and Continuous Delivery
(CI/CD) <https://about.gitlab.com/features/continuous-integration/>`_ as well as
a Wiki and Snippets. The GitLab Community Edition (CE) is developed as open
source software under the MIT licence and can be installed on-premises.

The GitLab CI tools enable automated builds and deployments without the need for
external integrations. If a PaaS solution such as `Kubernetes
<https://en.wikipedia.org/wiki/Kubernetes>`_ is already in use, apps can be
automatically deployed, tested and scaled with GitLab CI/CD. In addition, code
can be automatically scanned for potential security risks.
external integrations, for example building a Docker container with the Python
version of the project.

If a PaaS solution such as `Kubernetes
<https://en.wikipedia.org/wiki/Kubernetes>`_ is already in use, GitLab-CI/CD can
be used to automatically deploy, test and scale apps. The
:doc:`/productive/security` of your project can also be checked automatically.

GitLab is a completely packaged platform, while GitHub can be extended with apps
from the Marketplace. However, this does not mean that GitLab cannot be
Expand All @@ -32,5 +35,6 @@ integrated, for example with Asana, Jira, Microsoft Teams, Slack, etc.
roles-permissions
merge-requests
ci-cd
docker
github-migration
package-registry

0 comments on commit aeae7c3

Please sign in to comment.