diff --git a/docs/productive/git/advanced/gitlab/docker.rst b/docs/productive/git/advanced/gitlab/docker.rst new file mode 100644 index 00000000..4e87cef6 --- /dev/null +++ b/docs/productive/git/advanced/gitlab/docker.rst @@ -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 diff --git a/docs/productive/git/advanced/gitlab/index.rst b/docs/productive/git/advanced/gitlab/index.rst index ad5c16e2..5353e01c 100644 --- a/docs/productive/git/advanced/gitlab/index.rst +++ b/docs/productive/git/advanced/gitlab/index.rst @@ -6,17 +6,20 @@ GitLab ====== `GitLab `_ 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) `_ 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 -`_ 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 +`_ 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 @@ -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