Your IP : 216.73.216.101


Current Path : /snap/core26/646/snap/
Upload File :
Current File : //snap/core26/646/snap/snapcraft.yaml

name: core26
adopt-info: build-env
summary: Runtime environment based on Ubuntu 26.04
description: |
  The base snap based on the Ubuntu 26.04 release.
confinement: strict
type: base
build-base: core26
grade: stable
assumes:
  - snapd2.55.5
  # This is uncommented in our github builds for riscv64
  ## - isa-riscv64-rva23

parts:
  build-env:
    plugin: nil
    # To retrigger the pull step automatically on changes.
    source: .
    override-pull: |
      # We use a file with env vars in $CRAFT_PROJECT_DIR to decide whether to
      # include cloud-init or not. This file can be manually created for local
      # builds, or created here if we are running from a launchpad recipe with
      # suffix -cloud-init. This is detected by looking at the
      # SNAPCRAFT_IMAGE_INFO env var injected in LP, which tells us the build
      # url and has a form like:
      #
      # {
      #   "build-request-id": "lp-<id>",
      #   "build-request-timestamp": "<time>",
      #   "build_url": "https://launchpad.net/~ubuntu-core-service/+snap/core26-cloud-init/+build/<build_id>"
      # }
      #
      # (although in one line).
      if ! [ -e "$CRAFT_PROJECT_DIR"/build-env ]; then
        (
            cd "${CRAFT_PART_SRC}"
            touch build-env
            # parse the snap name from the url, and remove the prefix "core26-" and 
            # suffix "/+build" to get the variant name, if any.
            if [ -n "${SNAPCRAFT_IMAGE_INFO+x}" ]; then
              SNAP_BUILD_VARIANT=$(printf '%s' "$SNAPCRAFT_IMAGE_INFO" | grep -oP '(?<=core26-)[^/]*(?=/\+build)' || true)
              if [ -n "$SNAP_BUILD_VARIANT" ]; then
                  echo "SNAP_BUILD_VARIANT=$SNAP_BUILD_VARIANT" > build-env
              fi
            fi
        )
      else
        # copy to install dir so that we can use it in the build step
        cp "$CRAFT_PROJECT_DIR"/build-env "${CRAFT_PART_SRC}"/build-env
      fi

      date_tag=$("$CRAFT_PROJECT_DIR"/get-version.sh)

      # make sure we load the build-env here, especially if we're using
      # the locally sourced one.
      . "${CRAFT_PART_SRC}"/build-env
      SNAP_BUILD_VARIANT=${SNAP_BUILD_VARIANT:-}

      # handle build variants
      if [ -n "$SNAP_BUILD_VARIANT" ]; then
        craftctl set version="${date_tag}+$SNAP_BUILD_VARIANT"
        echo "SNAP_BUILD_NAME=core26-$SNAP_BUILD_VARIANT" >> "${CRAFT_PART_SRC}"/build-env
      else
        craftctl set version="${date_tag}"
        echo "SNAP_BUILD_NAME=core26" > "${CRAFT_PART_SRC}"/build-env
      fi
    override-build: |
      cp "${CRAFT_PART_SRC}"/build-env "${CRAFT_PART_INSTALL}"/build-env
    prime:
      - -build-env

  # TODO: rewrite this once all slices are upstreamed to use chisel slices
  # directly from canonical, instead of our own chisel-releases repo.
  chisel-libs:
    after:
      - build-env
    plugin: nil
    build-packages:
      - golang
      - file
    source: https://github.com/canonical/chisel-ubuntu-core.git
    source-type: git
    source-branch: '26.04'
    override-build: |
      go install github.com/canonical/chisel/cmd/chisel@latest
      
      # Define the system utilities that we want to include in the base
      # These are the ones where we can probably slim down the number of binaries
      # later on, but for now we include them all to ensure maximum compatibility.
      UTILS=(
        apparmor_bins
        bash_bins
        bzip2_scripts
        coreutils-from-uutils_bins
        diffutils_bins
        dosfstools_bins
        debianutils_which
        debianutils_ischroot
        debianutils_run-parts
        file_bins
        gdbserver_bins
        gnu-coreutils_bins
        gnutls-bin_bins
        gpgv_bins
        grep_bins
        gzip_scripts
        hostname_bins
        iptables_bins
        iputils-ping_bins
        less_bins
        login_bins
        mawk_bins
        ncurses-bin_bins
        polkitd_bins
        rfkill_bins
        sed_bins
        sudo-rs_bins
        sysvinit-utils_scripts
        squashfs-tools_bins
        tar_bins
        util-linux_bins
        util-linux_nsenter
        util-linux-extra_pivot-root
        util-linux-extra_hardware
        util-linux-extra_process
        util-linux-extra_login
        vim-tiny_bins
      )

      # Define the system libraries and services that we want to include in the base
      # 
      SLICES=(
        apparmor_systemd
        base-files_motd
        base-files_release-info
        base-files_root-defaults
        bash-completion_config
        bash-completion_completions
        ca-certificates_data-with-certs
        cracklib-runtime_bins
        cryptsetup_bins
        cryptsetup-bin_bins
        dbus_services
        dbus-user-session_services
        dhcpcd-base_standard
        distro-info-data_data
        dmsetup_rules
        e2fsprogs_services
        e2fsprogs_standard
        fdisk_bins
        fonts-ubuntu_all
        fonts-ubuntu_config
        finalrd_services
        iproute2_bins
        kmod_bins
        kmod_config

        libc6_config
        libc6_gconv
        libc-bin_iconv
        libc-bin_nsswitch
        libc-bin_ldconfig
        libc-bin_locale
        libc-bin_getconf
        libc-bin_getent

        libpam-modules_config
        libpam-modules_pam-config
        libpam-pwquality_pam-config
        libpam-modules-bin_standard
        libpam-modules-bin_extrausers
        libpam-modules-bin_namespace
        libpam-modules-bin_timestamp
        libpam-systemd_libs
        libengine-pkcs11-openssl_libs
        libgnutls30t64_config
        libopts25_libs
        libp11-3t64_libs
        libnss-mdns_mdns4-minimal
        libnss-extrausers_libs
        libpam-pwquality_libs
        libpciaccess0_libs
        libwrap0_host-files
        libx11-data_xerrordb
        locales_standard

        netcat-openbsd_bins
        netplan.io_bins
        ncurses-base_terminfo

        openssh-client_config
        openssh-client_services
        openssh-server_bins
        openssh-server_config
        openssh-server_services
        openssl_bins
        opensc_bins
        p11-kit_bins
        passwd_pam-config
        polkitd_services
        procps_bins
        plymouth_bins
        plymouth-label-ft_libs
        procps_config

        udev_services
        util-linux_services
        systemd_bash-completions
        systemd_extras
        systemd_run0
        systemd_kernel-parameters
        systemd_udev-rules
        systemd_tpm2
        systemd_standard
        systemd_user-services
        systemd-bootchart_services
        systemd-coredump_bins
        systemd-cryptsetup_bins
        systemd-cryptsetup_services
        systemd-resolved_bins
        systemd-sysv_bins
        systemd-timesyncd_services
        systemd-zram-generator_services
        
        tzdata_zoneinfo
        wpasupplicant_services
      )

      . "$CRAFT_STAGE"/build-env
      SNAP_BUILD_VARIANT=${SNAP_BUILD_VARIANT:-}
      if [ "$SNAP_BUILD_VARIANT" = cloud-init ]; then
          SLICES+=(cloud-init_bins)
      fi

      # TODO: not sure about FIPS yet, this will have to come later, chisel has builtin
      # support for ESM, meaning it's something we can request chisel to do for us.
      # if [ "$SNAP_BUILD_VARIANT" = fips ]; then
      #   # Ensure vital crypt packages are refreshed / downgraded and downloaded
      #   # from the FIPS ppa. This should also contain openssh-server, but we already
      #   # have that one listed above.
      #   SLICES+=(libgcrypt20 libgnutls30t64 openssl-fips-module-3 ssh)
      # fi
      
      # add architecture specific slices
      case "$(dpkg --print-architecture)" in
          amd64|arm64)
              SLICES+=(secureboot-db_services nvidia-kernel-common-595_bins nvidia-kernel-common-595_modprobe-d-kms)
              ;;
          i386)
              SLICES+=(secureboot-db_services)
              ;;
          riscv64)
              SLICES+=(gdbserver_bins systemd-bootchart_services)
              ;;
      esac

      # create the rootfs directory we install slices into
      mkdir -p "${CRAFT_PART_INSTALL}"/base

      # Cut the initial slices into the rootfs
      chisel cut \
        --release="${CRAFT_PART_SRC}" \
        --root "${CRAFT_PART_INSTALL}"/base \
        "${SLICES[@]}" "${UTILS[@]}" \
        base-files_chisel

      # Cut foreign libraries we also need
      case "$(dpkg --print-architecture)" in
          amd64)
              chisel cut \
                --arch=i386 \
                --release="${CRAFT_PART_SRC}" \
                --root "${CRAFT_PART_INSTALL}"/base \
                libnss-mdns_mdns4-minimal libc6_libs libc6_gconv libc6_config libgcc-s1_libs
              ;;
      esac
      
      # https://documentation.ubuntu.com/chisel/en/latest/reference/manifest/
      # chisel automatically generates a manifest for the cut slices here:
      # $rootfs/var/lib/chisel/manifest.wall
      # this is zstd compressed, and must therefor be uncompressed
      # unzstd ./manifest.wall -o manifest.json

    override-prime: |
      # No files from this step in prime

  snapd-files:
    plugin: nil
    source: .
    build-packages:
      - snapd
    after:
      - chisel-libs
    override-build: |
      mkdir -p "${CRAFT_PART_INSTALL}"/base/usr/lib/systemd/system-generators
      cp /usr/lib/systemd/system-generators/snapd-generator "${CRAFT_PART_INSTALL}"/base/usr/lib/systemd/system-generators/snapd-generator
      mkdir -p "${CRAFT_PART_INSTALL}"/base/usr/lib/tmpfiles.d
      cp /usr/lib/tmpfiles.d/snapd.conf "${CRAFT_PART_INSTALL}"/base/usr/lib/tmpfiles.d/snapd.conf
    override-prime: |
      # No files from this step in prime

  generators:
    plugin: nil
    source: generators/
    build-packages:
      - cargo
      - rustc
    override-build: |
      cd "${CRAFT_PART_SRC}"
      cargo build --release
      strip target/release/ubuntu-core-generator
      mkdir -p "${CRAFT_PART_INSTALL}/usr/lib/core"
      install -m 755 target/release/ubuntu-core-generator \
        "${CRAFT_PART_INSTALL}/usr/lib/core/ubuntu-core-generator"

  splash-theme:
    plugin: dump
    source: https://github.com/snapcore/plymouth-theme-ubuntu-core.git
    source-type: git
    organize:
      ubuntu-core: usr/share/plymouth/themes/ubuntu-core
      copyright: usr/share/doc/plymouth-theme-ubuntu-core/copyright
    stage:
      - -README.md

  hooks:
    after:
      - chisel-libs
      - snapd-files
      - splash-theme
      - build-env
    plugin: make
    source: .
    build-packages:
      - shellcheck
      - distro-info
    override-prime: |
      craftctl default

      # ensure build-in tests are run
      make -C ${CRAFT_PART_SRC} test TESTDIR=${CRAFT_PRIME}

  generate-changelog:
    after:
      - hooks
    plugin: make
    # Use the root to be able to detect the git repo, as we need to be able
    # to get the current commit
    source: .
    build-packages:
      - python3-debian
      - python3-requests
      - python3-yaml
    # to generate changelogs, it's own snap need to be present
    # TODO: maybe we can override pull and just copy the files we need into
    # the source dir.
    build-snaps:
      - core26/beta
    override-build: |
      cd ${CRAFT_PART_SRC}

      # Generate the dpkg.yaml for compatability purposes. Scanning tools still expect
      # this file to be present, and they move slowly in terms of support for the new chisel format.
      mkdir -p "${CRAFT_PART_INSTALL}/usr/share/snappy"
      python3 ./tools/wall2dpkg.py "${CRAFT_STAGE}/var/lib/chisel/manifest.wall" "${CRAFT_PART_INSTALL}/usr/share/snappy/dpkg.yaml"

      # When building through spread there is no .git, which means we cannot
      # generate the changelog in this case, ensure that the current folder is
      # a git repository, additionally check that the snap we are building a changelog
      # against has the dpkg.yaml.
      if git rev-parse HEAD && [ -e "/snap/core26/current/usr/share/snappy/dpkg.yaml" ]; then
        CHG_PARAMS=
        if [ -e /build/core26 ]; then
          CHG_PARAMS=--launchpad
        fi
        mkdir -p "${CRAFT_PART_INSTALL}/usr/share/doc"
        ./tools/generate-changelog.py "/snap/core26/current" "${CRAFT_PART_INSTALL}" core26 $CHG_PARAMS
      else
        echo "WARNING: changelog will not be generated for this build"
      fi

  publish-artifacts-lp:
    after:
      - generate-changelog
    plugin: nil
    override-prime: |
      # copy dpkg.yaml, chisel manifest and changelog files for lp build
      if [ -e /build/core26 ]; then
        DATEFMT="$(date +%Y%m%d%H%M)"
        /bin/cp ${CRAFT_PRIME}/usr/share/snappy/dpkg.yaml /build/core26/core26-$(DATEFMT)_${CRAFT_ARCH_BUILD_FOR}.dpkg.yaml
        /bin/cp ${CRAFT_PRIME}/var/lib/chisel/manifest.wall /build/core26/core26-$(DATEFMT)_${CRAFT_ARCH_BUILD_FOR}.manifest.wall
        /bin/cp ${CRAFT_PRIME}/usr/share/doc/ChangeLog /build/core26/core26-$(DATEFMT)_${CRAFT_ARCH_BUILD_FOR}.ChangeLog
      fi