This is just an insightful gist that shows how I automate some tasks.
More information can be found in the repository gbraad-dotfiles/notebooks.
This is just an insightful gist that shows how I automate some tasks.
More information can be found in the repository gbraad-dotfiles/notebooks.
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Compiling `crc` using a notebook\n", | |
"\n", | |
"This is just an insightful gist that shows how I automate some tasks.\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Setup host\n", | |
"\n", | |
"this step prepares the host machine with `podman` and my dotfiles. The dotfiles contains several helper functions that simplify starting the containers." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"%%bash\n", | |
"apt-get install -y podman\n", | |
"rm ~/.tmux.conf\n", | |
"curl -fsSL https://dotfiles.gbraad.nl/install.sh | sh\n", | |
"cd ~/.dotfiles\n", | |
"stow ipython" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"To simplify executing cells with these dotfiles, we can load an extensin that sources the helper functions." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"dotfiles extension loaded!\n" | |
] | |
} | |
], | |
"source": [ | |
"import sys, os\n", | |
"sys.path.append(os.path.expanduser(\"~/.ipython/extensions\"))\n", | |
"ip = get_ipython()\n", | |
"ip.extension_manager.load_extension(\"dotfiles\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Prepare work directory\n", | |
"\n", | |
"The source will be stored on the host machine in `~/Projects/crc-org/crc`. To contribute, it is expected your `ssh`-public key is registered with GitHub." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Cloning into 'crc'...\n", | |
"remote: Enumerating objects: 70554, done.\u001b[K\n", | |
"remote: Counting objects: 100% (1842/1842), done.\u001b[K\n", | |
"remote: Compressing objects: 100% (963/963), done.\u001b[K\n", | |
"remote: Total 70554 (delta 1399), reused 876 (delta 874), pack-reused 68712 (from 2)\u001b[K\n", | |
"Receiving objects: 100% (70554/70554), 63.58 MiB | 8.95 MiB/s, done.\n", | |
"Resolving deltas: 100% (37736/37736), done.\n", | |
"Updating files: 100% (12264/12264), done.\n" | |
] | |
} | |
], | |
"source": [ | |
"%%dotfiles\n", | |
"mkdir -p ~/Projects/crc-org\n", | |
"cd ~/Projects/crc-org\n", | |
"git clone [email protected]:/crc-org/crc" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Prepare developer environment\n", | |
"\n", | |
"`devenv` is a helper function that starts developer environments using containers that are prepared, published to a public container registry.\n", | |
"\n", | |
"The container here is a named `gofedora`, whose source and image is published to https://github.com/gbraad-devenv/fedora-golang, and `ghcr.io/gbraad-devenv/fedora-golang:latest`\n", | |
"\n", | |
"The command `noinit` starts this image with `sleep infinity` to ensure the image remains active. Alternatively `system` can be used, which starts this image with `systemd`." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"e0a916a5f0474121b8da16e8abbb4afb3ee2825532000727f39634d23c41ed05\n" | |
] | |
} | |
], | |
"source": [ | |
"%%dotfiles\n", | |
"#devenv gofedora rm\n", | |
"devenv gofedora noinit" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Compilation\n", | |
"\n", | |
"The actual compilation process is performed from the container that was set up in the previous step. It performs a `make clean` and `make`. The host machine will not store any intermediate files, only the result." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\u001b[6 q\r" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"rm -f packaging/darwin/Distribution\n", | |
"rm -f packaging/darwin/Resources/welcome.html\n", | |
"rm -f packaging/darwin/scripts/postinstall\n", | |
"rm -rf packaging/darwin/root-crc/\n", | |
"rm -rf packaging/windows/msi\n", | |
"rm -f out/linux-amd64/split\n", | |
"rm -f packaging/rpm/crc.spec images/rpmbuild/Containerfile\n", | |
"rm -rf out\n", | |
"rm -f /home/gbraad/go/bin/crc\n", | |
"rm -rf release\n", | |
"go install -tags \"containers_image_openpgp\" -ldflags=\"-X github.com/crc-org/crc/v2/pkg/crc/version.crcVersion=2.50.0 -X github.com/crc-org/crc/v2/pkg/crc/version.ocpVersion=4.18.2 -X github.com/crc-org/crc/v2/pkg/crc/version.okdVersion=4.15.0-0.okd-2024-02-23-163410 -X github.com/crc-org/crc/v2/pkg/crc/version.microshiftVersion=4.18.2 -X github.com/crc-org/crc/v2/pkg/crc/version.commitSha=a85523 \" ./cmd/crc\n" | |
] | |
} | |
], | |
"source": [ | |
"%%dotfiles\n", | |
"devenv gofedora exec su gbraad -l -c \"cd ~/Projects/crc-org/crc && make clean && make\"" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": ".venv", | |
"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.11.10" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |