### Setup Development Environment Source: https://github.com/canonical/rockcraft/blob/main/CONTRIBUTING.md Install project dependencies, linters, and testers using the provided make targets. Run these commands within the cloned project directory. ```bash make setup make lint make test ``` -------------------------------- ### Full Project File Example Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/crafting/add-internal-user-to-a-rock.md A complete project file demonstrating the setup for adding an internal user and running a service with it. Includes name, base, version, summary, and service/part configurations. ```yaml name: internal-user base: bare build-base: ubuntu@26.04 version: "latest" summary: Add an internal user inside a rock description: Add an internal user inside a rock, and run a service with it. platforms: amd64: services: web-service: override: replace command: python3 -m http.server --cgi 8080 startup: enabled user: myuser working-dir: / parts: my-part: plugin: nil source-type: local source: . stage-packages: - base-passwd_data - base-files_base - python3_standard override-build: | craftctl default groupadd --root ${CRAFT_PART_INSTALL} mygroup useradd -d /home/myuser -s /bin/bash --root ${CRAFT_PART_INSTALL} -g mygroup myuser mkdir ${CRAFT_PART_INSTALL}/cgi-bin/ cp serve_user.py ${CRAFT_PART_INSTALL}/cgi-bin/ chmod +x ${CRAFT_PART_INSTALL}/cgi-bin/serve_user.py ``` -------------------------------- ### Overlay Step Configuration Example Source: https://github.com/canonical/rockcraft/blob/main/docs/explanation/overlay-step.md This snippet demonstrates how to configure the overlay step for a part, including installing packages and running a script to remove specific files. It also specifies which files to migrate to subsequent steps. ```yaml parts: part_with_overlay: plugin: nil overlay-packages: - ed overlay-script: | rm -f ${CRAFT_OVERLAY}/usr/bin/vi ${CRAFT_OVERLAY}/usr/bin/vim* rm -f ${CRAFT_OVERLAY}/usr/bin/emacs* rm -f ${CRAFT_OVERLAY}/bin/nano overlay: - bin - usr/bin ``` -------------------------------- ### Install Docker as a Snap Source: https://github.com/canonical/rockcraft/blob/main/docs/reuse/tutorial/setup_edge.rst Installs Docker using the snap package manager. This is a convenient way to get Docker running. ```bash sudo snap install docker ``` -------------------------------- ### Install and Initialize LXD Source: https://github.com/canonical/rockcraft/blob/main/docs/reuse/tutorial/setup_edge.rst Installs LXD using snap and initializes it with default settings for immediate use. ```bash sudo snap install lxd lxd init --auto ``` -------------------------------- ### Install Go Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/go.md Install the Go programming language using snap with classic confinement. This is needed to test the Go app locally before packaging. ```bash sudo snap install go --classic ``` -------------------------------- ### Package Repository Configuration Example Source: https://github.com/canonical/rockcraft/blob/main/docs/reference/rockcraft-yaml.md Example of configuring APT package repositories for build and stage packages. ```yaml package-repositories: - type: apt components: - main suites: - xenial key-id: 78E1918602959B9C59103100F1831DDAFC42E99D url: http://ppa.launchpad.net/snappy-dev/snapcraft-daily/ubuntu ``` -------------------------------- ### Project Name Example Source: https://github.com/canonical/rockcraft/blob/main/docs/reference/rockcraft-yaml.md Example of setting the project name. ```yaml name: ubuntu ``` ```yaml name: jupyterlab-desktop ``` ```yaml name: lxd ``` ```yaml name: digikam ``` ```yaml name: kafka ``` ```yaml name: mysql-router-k8s ``` -------------------------------- ### Example .NET Plugin Configuration Source: https://github.com/canonical/rockcraft/blob/main/docs/reference/plugins/dotnet_plugin.md This example demonstrates how to configure the .NET plugin to build an application using the dotnet-sdk snap, specifying a 'Debug' build configuration and a self-contained runtime for 'linux-x64'. ```yaml parts: my-dotnet-part: source: . plugin: dotnet build-snaps: [dotnet-sdk] dotnet-build-configuration: Debug dotnet-self-contained-runtime-identifier: linux-x64 ``` -------------------------------- ### Install Documentation Requirements Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/documentation/build-docs.md Use this command to install the necessary dependencies for building the documentation. This is a prerequisite for building the docs. ```bash make setup-docs ``` -------------------------------- ### Install LXD Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/node-app.md Install LXD, a container and VM manager, using snap. LXD is required for building the rock. ```bash sudo snap install lxd ``` -------------------------------- ### Adopt Info Example Source: https://github.com/canonical/rockcraft/blob/main/docs/reference/rockcraft-yaml.md Example of specifying a part from which to inherit metadata. ```yaml adopt-info: foo-part ``` -------------------------------- ### Project Version Examples Source: https://github.com/canonical/rockcraft/blob/main/docs/reference/rockcraft-yaml.md Examples of specifying the project version. Quotation marks are optional but recommended for clarity. ```yaml version: '0.1' ``` ```yaml version: 1.0.0 ``` ```yaml version: v1.0.0 ``` ```yaml version: '24.04' ``` -------------------------------- ### Install LXD Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/get-started.md Install LXD using Snap if it is not already installed. LXD is required for Rockcraft's build process. ```bash snap install lxd ``` -------------------------------- ### Make Plugin Configuration Example Source: https://github.com/canonical/rockcraft/blob/main/docs/common/craft-parts/reference/plugins/make_plugin.md Configure a part to use the make plugin. This example specifies a source directory, sets the plugin to 'make', and provides build-time parameters for make, such as an alternate compiler. ```yaml parts: make: source: . plugin: make make-parameters: - CC=clang build-packages: - clang ``` -------------------------------- ### Build Packages for Part Source: https://github.com/canonical/rockcraft/blob/main/docs/reference/rockcraft-yaml.md Lists packages to be installed during the build step before the build starts. These packages are installed into the build environment using the host's native package manager. ```yaml build-packages: - git - libffi-dev - libssl-dev ``` -------------------------------- ### License Example Source: https://github.com/canonical/rockcraft/blob/main/docs/reference/rockcraft-yaml.md Example of specifying the project's license using an SPDX expression. ```yaml license: GPL-3.0+ ``` ```yaml license: Apache-2.0 ``` -------------------------------- ### Ubuntu 24.04 Base, Node.js from npm Plugin Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/web-app-rocks/configure-the-build-base-for-an-express-app.md Configure this setup for an Ubuntu 24.04 base where Node.js and npm are installed via the npm plugin. This allows specifying a particular Node.js version. ```yaml base: ubuntu@24.04 extensions: - expressjs-framework parts: expressjs-framework/install-app: npm-include-node: true npm-node-version: 20.12 ``` -------------------------------- ### Example Rockcraft Pack Output Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/crafting/migrate-to-chiselled-rock.md This is an example of the detailed output you can expect when running the `rockcraft pack` command with debug verbosity. It shows the build process, dependency fetching, and final archive creation. ```text 2026-05-26 16:44:26.830 Starting rockcraft, version 1.19.0 ... 2026-05-26 16:44:27.329 Launching managed ubuntu 26.04 instance... 2026-05-26 16:44:27.329 Executing on host: lxc remote list --format=yaml ... 2026-05-26 16:45:29.562 Building install-dotnet-runtime 2026-05-26 16:45:29.564 execute action install-dotnet-runtime:Action(part_name='install-dotnet-runtime', step=Step.BUILD, action_type=ActionType.RUN, reason=None, project_vars=ProjectVarInfo(root={}), properties=ActionProperties(changed_files=None, changed_dirs=None)) 2026-05-26 16:45:29.566 load state file: /root/parts/install-dotnet-runtime/state/pull 2026-05-26 16:45:29.788 :: 2026/05/26 16:45:29 Consulting release repository... 2026-05-26 16:45:30.309 :: 2026/05/26 16:45:30 Fetching current ubuntu-26.04 release... 2026-05-26 16:45:30.524 :: 2026/05/26 16:45:30 Processing ubuntu-26.04 release... 2026-05-26 16:45:40.419 :: 2026/05/26 16:45:40 Selecting slices... 2026-05-26 16:45:40.420 :: 2026/05/26 16:45:40 Fetching ubuntu 26.04 resolute suite details... 2026-05-26 16:45:40.673 :: 2026/05/26 16:45:40 Release date: Thu, 23 Apr 2026 17:07:15 UTC 2026-05-26 16:45:40.675 :: 2026/05/26 16:45:40 Fetching index for ubuntu 26.04 resolute main component... 2026-05-26 16:45:41.440 :: 2026/05/26 16:45:41 Fetching index for ubuntu 26.04 resolute universe component... 2026-05-26 16:45:49.441 :: 2026/05/26 16:45:49 Fetching ubuntu 26.04 resolute-security suite details... 2026-05-26 16:45:49.619 :: 2026/05/26 16:45:49 Release date: Tue, 26 May 2026 12:45:13 UTC 2026-05-26 16:45:49.621 :: 2026/05/26 16:45:49 Fetching index for ubuntu 26.04 resolute-security main component... 2026-05-26 16:45:49.703 :: 2026/05/26 16:45:49 Fetching index for ubuntu 26.04 resolute-security universe component... 2026-05-26 16:45:49.762 :: 2026/05/26 16:45:49 Fetching ubuntu 26.04 resolute-updates suite details... 2026-05-26 16:45:49.935 :: 2026/05/26 16:45:49 Release date: Tue, 26 May 2026 12:45:19 UTC 2026-05-26 16:45:49.936 :: 2026/05/26 16:45:49 Fetching index for ubuntu 26.04 resolute-updates main component... 2026-05-26 16:45:50.013 :: 2026/05/26 16:45:50 Fetching index for ubuntu 26.04 resolute-updates universe component... 2026-05-26 16:45:50.083 :: 2026/05/26 16:45:50 Fetching pool/main/b/base-files/base-files_14ubuntu6.1_amd64.deb... 2026-05-26 16:45:50.155 :: 2026/05/26 16:45:50 Fetching pool/main/d/dotnet10/dotnet-host-10.0_10.0.8-0ubuntu1~26.04.1_amd64.deb... 2026-05-26 16:45:50.268 :: 2026/05/26 16:45:50 Fetching pool/main/g/glibc/libc6_2.43-2ubuntu2_amd64.deb... 2026-05-26 16:45:51.332 :: 2026/05/26 16:45:51 Fetching pool/universe/g/gcc-14/gcc-14-base_14.3.0-14ubuntu1_amd64.deb... 2026-05-26 16:45:51.386 :: 2026/05/26 16:45:51 Fetching pool/main/g/gcc-16/libgcc-s1_16-20260322-1ubuntu1_amd64.deb... 2026-05-26 16:45:51.455 :: 2026/05/26 16:45:51 Fetching pool/main/g/gcc-16/libstdc++6_16-20260322-1ubuntu1_amd64.deb... 2026-05-26 16:45:51.815 :: 2026/05/26 16:45:51 Fetching pool/main/d/dotnet10/dotnet-hostfxr-10.0_10.0.8-0ubuntu1~26.04.1_amd64.deb... 2026-05-26 16:45:51.909 :: 2026/05/26 16:45:51 Fetching pool/main/d/dotnet10/dotnet-runtime-10.0_10.0.8-0ubuntu1~26.04.1_amd64.deb... ... 2026-05-26 16:46:15.523 Created new layer 2026-05-26 16:46:15.524 Adding Pebble entrypoint 2026-05-26 16:46:15.525 Configuring entrypoint... 2026-05-26 16:46:15.544 Entrypoint set to ['/usr/bin/pebble', 'enter'] 2026-05-26 16:46:15.567 Entrypoint set to ['/bin/pebble', 'enter'] 2026-05-26 16:46:15.571 Adding metadata 2026-05-26 16:46:15.572 Configuring labels and annotations... 2026-05-26 16:46:15.592 Labels and annotations set to ['org.opencontainers.image.version=chiselled', 'org.opencontainers.image.title=dotnet-runtime', 'org.opencontainers.image.created=2026-05-26T14:46:15.571853+00:00', 'org.opencontainers.image.description=.NET Runtime 10.0\n\nA Chiselled rock for the .NET Runtime 10.0', 'org.opencontainers.image.licenses=Apache-2.0'] 2026-05-26 16:46:15.593 Setting the rock's control data 2026-05-26 16:46:15.594 Adding to layer: /tmp/tmpljv_j_q4/.rock as '.rock' 2026-05-26 16:46:15.595 Adding to layer: /tmp/tmpljv_j_q4/.rock/metadata.yaml as '.rock/metadata.yaml' 2026-05-26 16:46:15.612 Control data written 2026-05-26 16:46:15.613 Metadata added 2026-05-26 16:46:15.613 Exporting to OCI archive 2026-05-26 16:46:15.816 Exported to OCI archive 'dotnet-runtime_chiselled_amd64.rock' ``` -------------------------------- ### Install FastAPI Dependencies Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/fastapi.md Create a requirements.txt file to specify the FastAPI version for installation. ```text fastapi[standard]>=0.109.1 ``` -------------------------------- ### Install Rockcraft via Snap Source: https://github.com/canonical/rockcraft/blob/main/README.md Installs Rockcraft on snap-ready systems using the classic confinement. Ensure your system supports snaps for this installation method. ```bash snap install rockcraft --classic ``` -------------------------------- ### Install Express Generator and Create App Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/express.md Install the Express generator globally and use it to create a new Express application skeleton. Then, navigate into the app directory and install its dependencies. ```bash sudo npm install -g express-generator@4 express app cd app && npm install ``` -------------------------------- ### Setup Documentation Dependencies Source: https://github.com/canonical/rockcraft/blob/main/docs/README.md After updating the documentation subproject, clean the project and set up the documentation dependencies. This command syncs dependencies to the parent project. ```bash make clean make docs-setup uv add -r docs/requirements.txt --group docs-sphinx-stack ``` -------------------------------- ### Start Express App Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/express.md Run this command to start the Express application's HTTP server. ```bash npm start ``` -------------------------------- ### Project Title Example Source: https://github.com/canonical/rockcraft/blob/main/docs/reference/rockcraft-yaml.md Example of setting a human-readable project title. ```yaml title: Ubuntu Linux ``` ```yaml title: Jupyter Lab Desktop ``` ```yaml title: LXD ``` ```yaml title: DigiKam ``` ```yaml title: Apache Kafka ``` ```yaml title: MySQL Router K8s charm ``` -------------------------------- ### Example Output of .NET Info Command Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/crafting/migrate-to-chiselled-rock.md This is an example output when running 'dotnet --info' inside the chiselled .NET Runtime container. ```text Host: Version: 10.0.8 Architecture: x64 Commit: 94ea82652c RID: ubuntu.26.04-x64 .NET SDKs installed: No SDKs were found. .NET runtimes installed: Microsoft.NETCore.App 10.0.8 [/usr/lib/dotnet/shared/Microsoft.NETCore.App] Other architectures found: None Environment variables: Not set global.json file: Not found Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download ``` -------------------------------- ### Rockcraft Project Configuration Example Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/flask.md An example of the initial rockcraft.yaml file generated for a Flask application. Key fields include name, base, build-base, version, summary, description, and platforms. ```yaml name: flask-hello-world # see https://documentation.ubuntu.com/rockcraft/en/1.6.0/explanation/bases/ # for more information about bases and bare bases base: bare # as an alternative, an ubuntu base can be used build-base: ubuntu@24.04 # build-base is required when the base is bare version: '0.1' # just for humans. Semantic versioning is recommended summary: A summary of your Flask app # 79 char long summary description: | This is flask-hello-world's description. You have a paragraph or two to tell the most important story about it. Keep it under 100 words though, we live in tweetspace and your description wants to look good in the container registries out there. # the platforms this rock should be built on and run on. # you can check your architecture with `dpkg --print-architecture` platforms: amd64: # arm64: # ppc64el: # s390x: ``` -------------------------------- ### Example Output of Docker Image Inspection Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/crafting/migrate-to-chiselled-rock.md This is an example output when inspecting the chiselled .NET Runtime rock image. ```text IMAGE ID DISK USAGE CONTENT SIZE EXTRA dotnet-runtime:chiselled a846a767e8e8 213MB 64.5MB ``` -------------------------------- ### Source Code Link Example Source: https://github.com/canonical/rockcraft/blob/main/docs/reference/rockcraft-yaml.md Example of providing a link to the project's source code repository. ```yaml source-code: - https://github.com/canonical/craft-application ``` -------------------------------- ### Install Multipass Source: https://github.com/canonical/rockcraft/blob/main/docs/reuse/tutorial/setup_edge.rst Installs Multipass using snap if it's not found. Ensure the multipass service is active before proceeding. ```bash sudo snap install multipass ``` -------------------------------- ### Install Devpack and Java Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/springboot.md Install 'devpack-for-spring' and OpenJDK 21 JDK. These are required to test the Spring Boot application locally before packaging. ```bash sudo snap install devpack-for-spring --classic sudo apt update && sudo apt install -y openjdk-21-jdk ``` -------------------------------- ### Install Rockcraft Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/springboot.md Install Rockcraft with classic confinement, granting it full filesystem access. This version is required for the experimental framework. ```bash sudo snap install rockcraft --classic --channel latest/edge ``` -------------------------------- ### Run Go Application Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/go.md Executes the built Go application. The app starts an HTTP server on port 8000. ```bash ./go-hello-world ``` -------------------------------- ### Pass argument to ExpressJS script Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/web-app-rocks/set-up-web-app-rock.md Pass the `--example-arg` argument to the ExpressJS npm start script. ```yaml services: expressjs: command: npm start -- --example-arg ``` -------------------------------- ### Rust Plugin Configuration Example Source: https://github.com/canonical/rockcraft/blob/main/docs/common/craft-parts/reference/plugins/rust_plugin.md Example of configuring the Rust plugin to inherit LDFLAGS for a classic Snap application. This ensures proper linkage by adding environment LDFLAGS to Rust linker directives. ```yaml parts: my-classic-app: plugin: rust source: . rust-inherit-ldflags: true build-environment: - LDFLAGS: > -Wl,-rpath=$ORIGIN/lib:/snap/core24/current/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR -Wl,-dynamic-linker=$(find /snap/core24/current/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR -name 'ld*.so.*' -print | head -n1) ``` -------------------------------- ### Check Multipass Service Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/fastapi.md Verify if the Multipass service is installed and active. If active but not running, start it. If not found, install Multipass. ```bash snap services multipass ``` -------------------------------- ### Verify Node.js App Output Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/node-app.md This is an example of the expected output from the Docker container, indicating that the Pebble service has started the Node.js application and it is listening on port 8080. ```text 2023-10-30T12:37:33.654Z [pebble] Started daemon. 2023-10-30T12:37:33.659Z [pebble] POST /v1/services 3.878846ms 202 2023-10-30T12:37:33.663Z [pebble] Service "app" starting: node server.js 2023-10-30T12:37:33.864Z [app] Running on http://0.0.0.0:8080 2023-10-30T12:37:33.865Z [pebble] Started default services with change 1. ``` -------------------------------- ### Go Use Plugin Configuration Example Source: https://github.com/canonical/rockcraft/blob/main/docs/common/craft-parts/reference/plugins/go_use_plugin.md This snippet shows how to configure a part to use the 'go-use' plugin and another part to use the 'go' plugin, demonstrating dependency management with the 'after' key. ```yaml parts: go-flags: source: https://github.com/jessevdk/go-flags.git plugin: go-use hello: build-snaps: - go/1.22/stable plugin: go source: . after: - go-flags ``` -------------------------------- ### NPM Plugin for Registry Application Source: https://github.com/canonical/rockcraft/blob/main/docs/common/craft-parts/reference/plugins/npm_plugin.md Example of installing an application from the npm registry that does not require a Node.js runtime. It utilizes Node.js during build time via build snaps. ```yaml parts: app: plugin: npm source: https://registry.npmjs.org/esbuild/-/esbuild-0.21.3.tgz source-type: tar npm-include-node: false build-snaps: # use Node.js Snap during the build-time only - node ``` -------------------------------- ### Declare Python interpreter with uv plugin Source: https://github.com/canonical/rockcraft/blob/main/docs/reference/plugins/uv_plugin.md Example of how to declare a Python interpreter and venv module for a part using the uv plugin. This ensures the necessary Python environment is available for package installation. ```yaml package-repositories: - type: apt ppa: deadsnakes/ppa priority: always parts: my-part: plugin: source: . stage-packages: [python3.12-venv] ``` -------------------------------- ### Go Plugin Configuration Example Source: https://github.com/canonical/rockcraft/blob/main/docs/common/craft-parts/reference/plugins/go_plugin.md This snippet shows how to configure a part to use the Go plugin. It specifies the Go snap version, enables a build tag, and sets up a `go generate` command. ```yaml parts: go: plugin: go source: . build-snaps: - go/1.22/stable go-buildtags: - experimental go-generate: - ./cmd ``` -------------------------------- ### Install Flask Dependencies Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/flask.md Installs Python virtual environment tools and the Flask library. Ensure you have python3-venv installed. ```bash sudo apt-get update && sudo apt-get install python3-venv -y python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt ``` -------------------------------- ### Build .NET App with User-Provided SDK Source: https://github.com/canonical/rockcraft/blob/main/docs/reference/plugins/dotnet_v2_plugin.md This example demonstrates building a .NET application using a custom, user-provided .NET SDK. It requires staging the SDK via a separate part and updating the PATH environment variable. Ensure dependencies like libicu74 are included in both build and stage steps. ```yaml parts: dotnet-deps: plugin: dump source: https://builds.dotnet.microsoft.com/dotnet/Sdk/8.0.416/dotnet-sdk-8.0.416-linux-x64.tar.gz source-checksum: sha512/633cb85673e3519c825532f780f6750ff24ed248ef8df68885540e510b559b6adc2c8d940e4c349fc0cf2c9caf184f1efeaccbc5e952d6e435f3da027cae4188 organize: '*': dotnet-sdk/ prime: - -dotnet-sdk/ my-dotnet-part: after: [dotnet-deps] source: . plugin: dotnet dotnet-configuration: "Release" dotnet-self-contained: true build-packages: - libicu74 stage-packages: - libicu74 build-environment: - PATH: ${PATH}:${CRAFT_STAGE}/dotnet-sdk ``` -------------------------------- ### Part Processing Order Example 2 (With Dependencies) Source: https://github.com/canonical/rockcraft/blob/main/docs/common/craft-parts/explanation/lifecycle.md Illustrates the execution flow when part A has a dependency on part C. The output shows C's build and stage steps preceding A's, alongside alphabetical ordering. ```text Execute: Pull C Execute: Pull A Execute: Pull B Execute: Overlay C Execute: Overlay A Execute: Overlay B Execute: Build C Execute: Stage C (required to build 'A') Execute: Build A Execute: Build B Execute: Stage A Execute: Stage B Execute: Prime C Execute: Prime A Execute: Prime B ``` -------------------------------- ### Initialize a 12-factor app rock Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/web-app-rocks/set-up-web-app-rock.md Use `rockcraft init` with a profile to create a `rockcraft.yaml` file for your rock. Verify the project file for correct name and description. ```bash rockcraft init --profile ``` ```bash rockcraft init --profile django-framework ``` ```bash rockcraft init --profile expressjs-framework ``` ```bash rockcraft init --profile fastapi-framework ``` ```bash rockcraft init --profile flask-framework ``` ```bash rockcraft init --profile go-framework ``` -------------------------------- ### Serve Documentation Locally with Auto-rebuild Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/documentation/build-docs.md This command builds the documentation and serves it locally, automatically rebuilding and reloading the browser on file changes. It also activates the virtual environment if it exists. ```bash make docs-auto ``` -------------------------------- ### Check Snap Version Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/get-started.md Verify that Snap is installed and check its version. This is a prerequisite for installing Rockcraft. ```bash snap --version ``` -------------------------------- ### Create Django Project Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/django.md Initializes a new Django project named 'django_hello_world' using the django-admin command-line tool. ```bash django-admin startproject django_hello_world ``` -------------------------------- ### Conventional Commit Example Source: https://github.com/canonical/rockcraft/blob/main/CONTRIBUTING.md Example of a Conventional Commit message for adding a text sanitizer feature. ```bash feat: add text sanitizer ``` -------------------------------- ### Initialize LXD Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/get-started.md Initialize LXD with minimal configuration. This step is required if LXD is not already running or configured. ```bash lxd init --minimal # drop the --minimal for an interactive configuration ``` -------------------------------- ### Initialize Go Module Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/go.md Initializes a new Go module in the project directory. ```bash go mod init go-hello-world ``` -------------------------------- ### Contact Information Example Source: https://github.com/canonical/rockcraft/blob/main/docs/reference/rockcraft-yaml.md Example of providing contact information, which can be a single email or a list of contacts and URLs. ```yaml contact: - contact@example.com - https://example.com/contact ``` -------------------------------- ### Build Go Application Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/go.md Builds the Go application, creating an executable binary. ```bash go build . ``` -------------------------------- ### Create Go Project Directory Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/go.md Creates and navigates into a new directory for the Go project. ```bash mkdir go-hello-world cd go-hello-world ``` -------------------------------- ### Part Processing Order Example 1 (No Dependencies) Source: https://github.com/canonical/rockcraft/blob/main/docs/common/craft-parts/explanation/lifecycle.md Shows the execution flow for parts A, B, and C when no dependencies are specified. The output reflects alphabetical ordering within each stage. ```text Execute: Pull A Execute: Pull B Execute: Pull C Execute: Overlay A Execute: Overlay B Execute: Overlay C Execute: Build A Execute: Build B Execute: Build C Execute: Stage A Execute: Stage B Execute: Stage C Execute: Prime A Execute: Prime B Execute: Prime C ``` -------------------------------- ### Go Hello World Application Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/go.md A basic Go HTTP server that listens on port 8000 and responds with 'Hello, world!'. ```go package main import ( "fmt" "log" "net/http" ) func helloWorldHandler(w http.ResponseWriter, req *http.Request) { log.Printf("new hello world request") fmt.Fprintln(w, "Hello, world!") } func main() { log.Printf("starting hello world application") http.HandleFunc("/", helloWorldHandler) http.ListenAndServe(":8000", nil) } ``` -------------------------------- ### Gradle Plugin Configuration Example Source: https://github.com/canonical/rockcraft/blob/main/docs/common/craft-parts/reference/plugins/gradle_plugin.md This snippet shows a typical configuration for the Gradle plugin in a Rockcraft part. It specifies the plugin to use, the source directory, an initialization script, additional parameters, the Gradle task to execute, and build snap dependencies. ```yaml plugin: gradle source: . gradle-init-script: gradle-parameters: - -D= gradle-task: build build-snaps: - gradle ``` -------------------------------- ### Build Documentation Locally Source: https://github.com/canonical/rockcraft/blob/main/CONTRIBUTING.md Build the documentation site locally to check for rendering issues. ```bash make docs ``` -------------------------------- ### Issues Link Example Source: https://github.com/canonical/rockcraft/blob/main/docs/reference/rockcraft-yaml.md Example of providing links or email addresses for submitting issues, bugs, or feature requests. ```yaml issues: - issues@example.com - https://example.com/issues ``` -------------------------------- ### Initialize Rockcraft Project with Go Profile Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/go.md Initializes a new Rockcraft project using the 'go-framework' profile, which automates the creation of rockcraft.yaml for a Go app. ```bash rockcraft init --profile go-framework ``` -------------------------------- ### Test Documentation Commands Source: https://github.com/canonical/rockcraft/blob/main/docs/README.md After setting up dependencies, test the three main documentation commands to ensure they function correctly. ```bash make docs make docs-auto make docs-lint ``` -------------------------------- ### Pass argument to Go application Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/web-app-rocks/set-up-web-app-rock.md Pass the `--example-arg` argument to the main Go application. ```yaml services: go: override: replace command: go-hello-world --example-arg ``` -------------------------------- ### Reset Virtual Environment and Re-setup Source: https://github.com/canonical/rockcraft/blob/main/CONTRIBUTING.md Delete the virtual environment, clean temporary files, and set up the project again. Use this when tests fail unpredictably. ```bash rm -rf .venv make clean make setup ``` -------------------------------- ### Run installed binary from rock Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/chiselling/install-slice.md Run a binary installed from your custom slice within the Docker environment. This verifies that the slice was correctly integrated. ```bash docker run --rm chisel-vim-tiny exec vim-tiny ``` -------------------------------- ### Run the Hello World Rock Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/hello-world.md Executes the 'hello' command from the 'hello:latest' Docker image. The '--rm' flag ensures the container is removed after execution. ```bash docker run --rm hello:latest exec hello -t ``` -------------------------------- ### Test rock installation with skopeo Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/chiselling/install-slice.md Test that the binaries from your custom slice have been correctly installed in the rock. This command copies the rock archive to a Docker daemon. ```bash sudo rockcraft.skopeo --insecure-policy copy oci-archive:custom-vim-tiny-rock_0.0.1_amd64.rock docker-daemon:chisel-vim-tiny:latest ``` -------------------------------- ### Create Project Directory Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/pypi-package.md Create a new directory for the Rockcraft project and navigate into it. ```bash mkdir pyfiglet-rock && cd pyfiglet-rock ``` -------------------------------- ### Start NGINX Service via Pebble Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/crafting/convert-to-pebble-layer.md If the NGINX service is not running, use this command to start it using the Pebble service manager within the container. ```bash docker exec nginx-pebble-service pebble start nginx ``` -------------------------------- ### Initialize Rockcraft Project Source: https://github.com/canonical/rockcraft/blob/main/README.md Creates a minimal rockcraft.yaml file in the root of your container's codebase. This is the first step before adding packages and dependencies. ```bash rockcraft init ``` -------------------------------- ### Install npm Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/express.md Update package lists and install npm (Node Package Manager) on the Ubuntu environment. npm is required for managing Node.js packages for the Express app. ```bash sudo apt-get update -y && sudo apt-get install npm -y ``` -------------------------------- ### Build Snaps for Part Source: https://github.com/canonical/rockcraft/blob/main/docs/reference/rockcraft-yaml.md Lists snaps to be installed during the build step, making them available in the build environment. Entries can specify snap name, channel, or version. ```yaml build-snaps: - go/latest/stable - node/stable ``` -------------------------------- ### Initialize Rockcraft Project Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/fastapi.md Initialize a new Rockcraft project with a profile specifically for FastAPI applications. ```bash rockcraft init --profile fastapi-framework ``` -------------------------------- ### Qmake Plugin Configuration Example Source: https://github.com/canonical/rockcraft/blob/main/docs/common/craft-parts/reference/plugins/qmake_plugin.md This snippet demonstrates how to declare a part using the qmake plugin for a local source. It specifies Qt 6 and builds with the Debug configuration. ```yaml parts: hello: source: . plugin: qmake qmake-major-version: 6 qmake-parameters: - "CONFIG+=debug" ``` -------------------------------- ### Ubuntu 24.04 Base, Node.js from Ubuntu Package Archive Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/web-app-rocks/configure-the-build-base-for-an-express-app.md Use this configuration when you want to leverage the Ubuntu 24.04 base and have Node.js installed from the Ubuntu package archive. The npm plugin handles app file copying and dependency installation. ```yaml base: ubuntu@24.04 extensions: - expressjs-framework ``` -------------------------------- ### Run the Node.js App Container Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/node-app.md Start a Docker container from the imported rock image. This command maps local port 8000 to the container's port 8080 and starts the application with the '-v' flag, which typically enables verbose logging. ```bash docker run --name my-node-app -p 8000:8080 my-node-app:1.0 -v ``` -------------------------------- ### Pack and Deploy Updated Go App Source: https://github.com/canonical/rockcraft/blob/main/docs/tutorial/go.md Commands to pack the updated Go application into a rock, copy it to a Docker daemon, and run it as a container. This process includes building the rock, pushing it, and starting the container. ```text rockcraft pack rockcraft.skopeo --insecure-policy \ copy oci-archive:go-hello-world_0.2_$(dpkg --print-architecture).rock \ docker-daemon:go-hello-world:0.2 docker images go-hello-world:0.2 docker run --rm -d -p 8000:8000 \ --name go-hello-world go-hello-world:0.2 ``` -------------------------------- ### Build .NET App with Plugin-Provided SDK Source: https://github.com/canonical/rockcraft/blob/main/docs/reference/plugins/dotnet_v2_plugin.md Use this snippet to build a .NET application when the plugin should provision the .NET SDK. Specify the desired .NET version, build configuration, and whether the output should be self-contained. ```yaml parts: my-dotnet-part: source: . plugin: dotnet dotnet-version: "8.0" dotnet-configuration: "Debug" dotnet-self-contained: true ``` -------------------------------- ### Bare Base, Node.js from npm Plugin Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/web-app-rocks/configure-the-build-base-for-an-express-app.md Use this configuration for a bare base where Node.js and npm are installed by the npm plugin, allowing for a specific Node.js version to be set. The npm plugin also handles app file copying and dependency installation. ```yaml base: bare build-base: ubuntu@24.04 parts: expressjs-framework/install-app: npm-include-node: true npm-node-version: 20.12 ``` -------------------------------- ### Check Rockcraft Version Source: https://github.com/canonical/rockcraft/blob/main/docs/how-to/get-started.md Verify that Rockcraft has been installed successfully and check its version. ```bash rockcraft --version ```