{ "cells": [ { "cell_type": "markdown", "id": "27e5ad81-e0e5-4c1d-af4e-111bae99556e", "metadata": { "tags": [] }, "source": [ "# Build and Push Docker Image" ] }, { "cell_type": "markdown", "id": "c12c5c4d4cea1fd2", "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "source": [ "This tutorial will guide you through the process of building and pushing a Docker image to the MAIA Docker registry.\n", "The Docker image will be remotely built on the cloud and pushed to the MAIA Docker registry, which is hosted at `registry.cloud.cbh.kth.se`.\n", "The Docker Context (Dockerfile and other necessary files) need to be located in a Git repository, which will be accessed by [KANIKO](https://github.com/GoogleContainerTools/kaniko) to build the Docker image.\n", "\n", "The configuration parameters for building and pushing the Docker image are set in a JSON configuration file, following the conventions described below.\n", "```yaml\n", "git_path: \"\" # The path to the Git repository where the Docker Context is located\n", "git_subpath: \"\" # The subpath to the Docker Context in the Git repository\n", "git_username: \"\" # The username to access the Git repository\n", "git_token: \"\" # The token to access the Git repository\n", "docker_registry_secret: \"\" # Kubernetes Secret to Authenticate in the private Registry\n", "docker_image: \"\" # The name of the Docker image to build\n", "buildArgs: # Optional build arguments\n", " OPTIONAL_BUILD_ARG: \"\"\n", " OPTIONAL_BUILD_ARG: \"\"\n", "```" ] }, { "cell_type": "markdown", "id": "025485d6-38ae-469c-b14a-31c5ae647abe", "metadata": { "tags": [] }, "source": [ "## Set Git Specifications" ] }, { "cell_type": "markdown", "id": "fe3a590e-2e6c-4ec6-add5-b4adecb4e1b0", "metadata": {}, "source": [ "In this example, we will build our custom Jupyter Scipy Image, where it will be possible to set the Jupyter Token as an env variable `PW`.\n", "For more details, check the [Dockerfile](https://github.com/kthcloud/MAIA/blob/master/docker/demo/Dockerfile)" ] }, { "cell_type": "code", "execution_count": null, "id": "31131666-bcf8-47f9-bf74-af12221f3e0f", "metadata": {}, "outputs": [], "source": [ "%%writefile kaniko_values.yaml\n", "\n", "docker_registry_secret: \n", "pvc:\n", " pvc_type: \n", " size: \"10Gi\"\n", "\n", "args:\n", " - \"--dockerfile=Dockerfile\"\n", " - \"--context=git://github.com/kthcloud/MAIA.git\"\n", " - \"--context-sub-path=docker/demo\"\n", " - \"--destination=registry.cloud.cbh.kth.se/maia/jupyter-demo:1.2\"\n", " - \"--cache=true\"\n", " - \"--cache-dir=/cache\"\n", " #- \"--context=s3://docker-contexts/{{.Values.context_file}}\"\n" ] }, { "cell_type": "markdown", "id": "69359ea1-cd70-4c6e-bb46-007c3debfee0", "metadata": { "tags": [] }, "source": [ "## Install Helm Chart" ] }, { "cell_type": "code", "execution_count": null, "id": "819a4e04-a7cc-4fe9-be12-36a73edd6c30", "metadata": {}, "outputs": [], "source": [ "%%bash\n", "\n", "helm repo add maia https://kthcloud.github.io/MAIA/\n", "helm repo update\n", "export KUBECONFIG=\n", "\n", "#Optional: delete the previous deployment\n", "# helm delete -n maia-admin demo-docker\n", "\n", "helm install -n maia-admin demo-docker maia/mkg-kaniko --values kaniko_values.yaml --version 1.0.3" ] }, { "cell_type": "markdown", "id": "dd884c2d-78b3-48f5-b337-1381c38ce633", "metadata": {}, "source": [ "## Log the Docker Build Job" ] }, { "cell_type": "code", "execution_count": null, "id": "3c6e0c88", "metadata": {}, "outputs": [], "source": [ "%%bash\n", "\n", "export KUBECONFIG=\n", "\n", "kubectl logs -f -n maia-admin job/demo-docker-mkg-kaniko" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.14" } }, "nbformat": 4, "nbformat_minor": 5 }