diff --git a/.dockerignore b/.dockerignore index 0b73b065..517f5327 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,2 @@ machine-emulator-tools-*.ext2 -example/ +rootfs.* diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 21cf96be..3fdae091 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,6 +3,7 @@ on: [push] env: TOOLCHAIN_IMAGE: ${{ github.repository_owner }}/toolchain TOOLCHAIN_TAG: 0.16.0 + TOOLS_IMAGE: ${{ github.repository_owner }}/machine-emulator-tools jobs: tools: runs-on: ubuntu-22.04 @@ -27,9 +28,6 @@ jobs: - name: Export makefile variables run: make env >> $GITHUB_ENV - - name: Download and check dependencies - run: make checksum - - name: Buildx setup uses: docker/setup-buildx-action@v2 @@ -43,55 +41,50 @@ jobs: type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} - - name: Build [${{ env.MACHINE_EMULATOR_TOOLS_TAR_GZ }}] + - name: Build [${{ env.TOOLS_DEB }}] id: docker_build uses: docker/build-push-action@v4 with: context: . builder: ${{ steps.buildx.outputs.name }} - tags: ${{ steps.docker_meta.outputs.tags }} + tags: ${{ env.TOOLS_IMAGE }}:devel.build push: false load: true build-args: | - MACHINE_EMULATOR_TOOLS_TAR_GZ=${{ env.MACHINE_EMULATOR_TOOLS_TAR_GZ }} - MACHINE_EMULATOR_TOOLS_DEB=${{ env.MACHINE_EMULATOR_TOOLS_DEB }} - MACHINE_EMULATOR_TOOLS_VERSION=${{ env.MACHINE_EMULATOR_TOOLS_VERSION }} + TOOLS_DEB=${{ env.TOOLS_DEB }} LINUX_SOURCES_VERSION=${{ env.LINUX_SOURCES_VERSION }} - LINUX_SOURCES_FILEPATH=${{ env.LINUX_SOURCES_FILEPATH }} - RNDADDENTROPY_VERSION=${{ env.RNDADDENTROPY_VERSION }} - RNDADDENTROPY_FILEPATH=${{ env.RNDADDENTROPY_FILEPATH }} + LINUX_SOURCES_URLPATH=${{ env.LINUX_SOURCES_URLPATH }} cache-from: type=gha,scope=regular,mode=max cache-to: type=gha,scope=regular - name: Retrieve artifacts - run: make copy MACHINE_EMULATOR_TOOLS_IMAGE=`echo "${{ steps.docker_meta.outputs.tags }}" | head -1 | cut -d "," -f 1 | xargs` + run: make copy TOOLS_IMAGE=${{ env.TOOLS_IMAGE }}:devel.build - - name: Upload [${{ env.MACHINE_EMULATOR_TOOLS_TAR_GZ }}] + - name: Upload [${{ env.TOOLS_DEB }}] uses: actions/upload-artifact@v3 with: - name: ${{ env.MACHINE_EMULATOR_TOOLS_TAR_GZ }} - path: ${{ env.MACHINE_EMULATOR_TOOLS_TAR_GZ }} + name: ${{ env.TOOLS_DEB }} + path: ${{ env.TOOLS_DEB }} - - name: Upload [${{ env.MACHINE_EMULATOR_TOOLS_DEB }}] + - name: Upload rootfs.ext2 uses: actions/upload-artifact@v3 with: - name: ${{ env.MACHINE_EMULATOR_TOOLS_DEB }} - path: ${{ env.MACHINE_EMULATOR_TOOLS_DEB }} + name: rootfs.ext2 - name: Checksum artifacts run: | - sha512sum ${{ env.MACHINE_EMULATOR_TOOLS_DEB }} > ${{ env.MACHINE_EMULATOR_TOOLS_DEB }}.sha512 - sha512sum ${{ env.MACHINE_EMULATOR_TOOLS_TAR_GZ }} > ${{ env.MACHINE_EMULATOR_TOOLS_TAR_GZ }}.sha512 + sha512sum ${{ env.TOOLS_DEB }} > ${{ env.TOOLS_DEB }}.sha512 + sha512sum rootfs.ext2 > rootfs.ext2.sha512 - uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/v') with: prerelease: true files: | - ${{ env.MACHINE_EMULATOR_TOOLS_TAR_GZ }} - ${{ env.MACHINE_EMULATOR_TOOLS_TAR_GZ }}.sha512 - ${{ env.MACHINE_EMULATOR_TOOLS_DEB }} - ${{ env.MACHINE_EMULATOR_TOOLS_DEB }}.sha512 + ${{ env.TOOLS_DEB }} + ${{ env.TOOLS_DEB }}.sha512 + rootfs.ext2 + rootfs.ext2.sha512 build: runs-on: ubuntu-22.04 diff --git a/.gitignore b/.gitignore index caa32699..e5e72fef 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ control machine-emulator-tools-*.tar.gz machine-emulator-tools-*.deb -dep/ +rootfs.* # Prerequisites *.d diff --git a/Dockerfile b/Dockerfile index 7fa98c74..ee43e254 100644 --- a/Dockerfile +++ b/Dockerfile @@ -73,7 +73,7 @@ RUN cd ${BUILD_BASE}/tools/linux/rollup/http/rollup-http-server && \ # pack tools (deb) # ------------------------------------------------------------------------------ FROM c-builder as packer -ARG MACHINE_EMULATOR_TOOLS_DEB=machine-emulator-tools.deb +ARG TOOLS_DEB=machine-emulator-tools.deb ARG STAGING_BASE=${BUILD_BASE}/_install ARG STAGING_DEBIAN=${STAGING_BASE}/DEBIAN ARG STAGING_BIN=${STAGING_BASE}/opt/cartesi/bin @@ -90,4 +90,4 @@ COPY --from=rust-builder ${BUILD_BASE}/tools/linux/rollup/http/rollup-http-serve COPY skel/ ${STAGING_BASE}/ COPY control ${STAGING_DEBIAN}/control -RUN dpkg-deb -Zxz --root-owner-group --build ${STAGING_BASE} ${BUILD_BASE}/${MACHINE_EMULATOR_TOOLS_DEB} +RUN dpkg-deb -Zxz --root-owner-group --build ${STAGING_BASE} ${BUILD_BASE}/${TOOLS_DEB} diff --git a/Makefile b/Makefile index 96fd2064..3af5f607 100644 --- a/Makefile +++ b/Makefile @@ -20,50 +20,59 @@ PATCH := 0 LABEL := VERSION := $(MAJOR).$(MINOR).$(PATCH)$(LABEL) -MACHINE_EMULATOR_TOOLS_VERSION ?= v$(VERSION) -MACHINE_EMULATOR_TOOLS_DEB := machine-emulator-tools-$(MACHINE_EMULATOR_TOOLS_VERSION).deb -MACHINE_EMULATOR_TOOLS_IMAGE := cartesi/machine-emulator-tools:$(MACHINE_EMULATOR_TOOLS_VERSION) +TOOLS_DEB := machine-emulator-tools-v$(VERSION).deb +TOOLS_IMAGE := cartesi/machine-emulator-tools:$(VERSION) LINUX_SOURCES_VERSION ?= 6.5.9-ctsi-1 LINUX_SOURCES_URLPATH := https://github.com/cartesi/linux/archive/refs/tags/v$(LINUX_SOURCES_VERSION).tar.gz -all: $(MACHINE_EMULATOR_TOOLS_DEB) +all: $(TOOLS_DEB) build: Dockerfile control - docker buildx build --platform=linux/riscv64 --load \ - --build-arg MACHINE_EMULATOR_TOOLS_DEB=$(MACHINE_EMULATOR_TOOLS_DEB) \ + @docker buildx build --platform=linux/riscv64 --load \ + --build-arg MACHINE_EMULATOR_TOOLS_DEB=$(TOOLS_DEB) \ --build-arg LINUX_SOURCES_VERSION=$(LINUX_SOURCES_VERSION) \ --build-arg LINUX_SOURCES_URLPATH=$(LINUX_SOURCES_URLPATH) \ - -t $(MACHINE_EMULATOR_TOOLS_IMAGE) \ + -t $(TOOLS_IMAGE) \ -f $< \ . copy: - ID=`docker create --platform=linux/riscv64 $(MACHINE_EMULATOR_TOOLS_IMAGE)` && \ - docker cp $$ID:/opt/cartesi/$(MACHINE_EMULATOR_TOOLS_DEB) . && \ + @ID=`docker create --platform=linux/riscv64 $(TOOLS_IMAGE)` && \ + docker cp $$ID:/opt/cartesi/$(TOOLS_DEB) . && \ docker rm $$ID control: - sed 's|ARG_VERSION|$(VERSION)|g' control.template > control + @sed 's|ARG_VERSION|$(VERSION)|g' control.template > control -$(MACHINE_EMULATOR_TOOLS_DEB): build copy +$(TOOLS_DEB) deb: build copy -fs: $(MACHINE_EMULATOR_TOOLS_DEB) +rootfs.ext2: $(TOOLS_DEB) + @docker buildx build --platform=linux/riscv64 --load \ + --build-arg TOOLS=$(TOOLS_DEB) \ + --output type=tar,dest=rootfs.tar \ + --file fs.Dockerfile \ + . && \ + bsdtar -cf rootfs.gnutar --format=gnutar @rootfs.tar && \ + xgenext2fs -fzB 4096 -i 4096 -a rootfs.gnutar -L rootfs rootfs.ext2 + +fs: rootfs.ext2 env: - @echo MACHINE_EMULATOR_TOOLS_DEB=$(MACHINE_EMULATOR_TOOLS_DEB) - @echo MACHINE_EMULATOR_TOOLS_VERSION=$(MACHINE_EMULATOR_TOOLS_VERSION) + @echo TOOLS_DEB=$(TOOLS_DEB) @echo LINUX_SOURCES_VERSION=$(LINUX_SOURCES_VERSION) @echo LINUX_SOURCES_URLPATH=$(LINUX_SOURCES_URLPATH) setup: - docker run --privileged --rm linuxkit/binfmt:bebbae0c1100ebf7bf2ad4dfb9dfd719cf0ef132 + @docker run --privileged --rm linuxkit/binfmt:bebbae0c1100ebf7bf2ad4dfb9dfd719cf0ef132 setup-required: @echo 'riscv64 buildx setup required:' `docker buildx ls | grep -q riscv64 && echo no || echo yes` help: @echo 'available commands:' + @echo ' deb - build machine-emulator-tools .deb package' + @echo ' fs - build rootfs.ext2' @echo ' setup - setup riscv64 buildx' @echo ' setup-required - check if riscv64 buildx setup is required' @echo ' help - list makefile commands' @@ -72,6 +81,6 @@ help: @echo ' distclean - clean and remove dependencies' clean: - rm -f $(MACHINE_EMULATOR_TOOLS_DEB) control + rm -f $(TOOLS_DEB) control rootfs.* .PHONY: build copy fs env setup setup-required help distclean diff --git a/example/README.md b/example/README.md deleted file mode 100644 index 98e322df..00000000 --- a/example/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# Example: Cartesi root filesystem with machine emulator tools - -The following example demonstrates how to create a bootable root filesystem for the Cartesi Machine based on a Ubuntu RISC-V 64 docker image. It requires the machine-emulator-tools. - -### Requirements - -- Docker >= 18.x -- GNU Make >= 3.81 -- xgenext2fs >= 1.5.3 -- bsdtar >= 3.6.2 -- bc >= 1.06 - -### Building - -```sh -cp ../machine-emulator-tools-v0.13.0.tar.gz . -./build ubuntu-22.04.dockerfile -``` - -After the build is done, the file `ubuntu-22.04.ext2` should be available in the current path. -Assuming you have `cartesi-machine` installed in your environment, -you can then test interactive terminal with it: - -```sh -$ cartesi-machine --flash-drive=label:root,filename:ubuntu-22.04.ext2 -i bash -Running in interactive mode! - - . - / \ - / \ -\---/---\ /----\ - \ X \ - \----/ \---/---\ - \ / CARTESI - \ / MACHINE - ' - -root@cartesi-machine:~# -``` diff --git a/example/build b/example/build deleted file mode 100755 index edd2b8bd..00000000 --- a/example/build +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh - -set -e - -if [ $# -eq 0 ]; then - echo "no dockerfile supplied" - exit 1 -fi - -NAME=${1%.*} -DOCKERFILE="$NAME.dockerfile" -TOOLS=machine-emulator-tools-v0.13.0.tar.gz - -if [ ! -f "$DOCKERFILE" ]; then - echo "dockerfile \"$DOCKERFILE\" not found" - exit 1 -fi - -if [ ! -f "$TOOLS" ]; then - echo "tools tarball \"$TOOLS\" not found" - exit 1 -fi - -TAR=$(mktemp) && \ -docker buildx build --progress plain \ - --build-arg TOOLS=$TOOLS \ - --output type=tar,dest=$TAR \ - --file $NAME.dockerfile \ - . && \ -GNUTAR=$(mktemp) && \ -bsdtar -cf $GNUTAR --format=gnutar @$TAR -./img-pack $GNUTAR $NAME.ext2 rootfs && (rm -f $TAR $GNUTAR; echo "created $NAME.ext2"; true) || (rm -f $TAR $GNUTAR; false) diff --git a/example/img-pack b/example/img-pack deleted file mode 100755 index feeed659..00000000 --- a/example/img-pack +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -blocksize=4096 -bytes=$(($(wc -c < "$1") +0)) -bcargs="$(cat <<- EOF - define max(a, b) { return (a > b) * a + (a <= b) * b } - max(8, 1.5 * ($bytes + $blocksize - 1) / $blocksize) - EOF -)" -blocks=$(echo "$bcargs" | bc) - -xgenext2fs \ - -fzB $blocksize \ - -b $blocks \ - -i $blocksize \ - -L ${3:-rootfs} \ - -a $1 \ - $2 diff --git a/example/ubuntu-22.04.dockerfile b/example/ubuntu-22.04.dockerfile deleted file mode 100644 index 10ecd658..00000000 --- a/example/ubuntu-22.04.dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM --platform=linux/riscv64 riscv64/ubuntu:22.04 -ARG TOOLS=machine-emulator-tools.tar.gz -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - busybox-static \ - python3 python3-requests && \ - rm -rf /var/lib/apt/lists/* -RUN useradd --create-home --user-group dapp -ADD ${TOOLS} / diff --git a/fs.Dockerfile b/fs.Dockerfile new file mode 100644 index 00000000..42c9f035 --- /dev/null +++ b/fs.Dockerfile @@ -0,0 +1,14 @@ +FROM --platform=linux/riscv64 riscv64/ubuntu:22.04 +ARG TOOLS_DEB=machine-emulator-tools-v0.14.0.deb +ADD ${TOOLS_DEB} /tmp/ +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + busybox-static=1:1.30.1-7ubuntu3 \ + ca-certificates=20230311ubuntu0.22.04.1 \ + curl=7.81.0-1ubuntu1.14 \ + /tmp/${TOOLS_DEB} \ + python3 \ + python3-requests && \ + rm -rf /tmp/${TOOLS_DEB} && \ + rm -rf /var/lib/apt/lists/* +RUN useradd --create-home --user-group dapp