Skip to content

Commit

Permalink
feat!: add support for building rootfs.ext2
Browse files Browse the repository at this point in the history
  • Loading branch information
vfusco committed Dec 2, 2023
1 parent a682321 commit 684b632
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 141 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
machine-emulator-tools-*.ext2
example/
rootfs.*
41 changes: 17 additions & 24 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
control
machine-emulator-tools-*.tar.gz
machine-emulator-tools-*.deb
dep/
rootfs.*

# Prerequisites
*.d
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
41 changes: 25 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
39 changes: 0 additions & 39 deletions example/README.md

This file was deleted.

32 changes: 0 additions & 32 deletions example/build

This file was deleted.

17 changes: 0 additions & 17 deletions example/img-pack

This file was deleted.

9 changes: 0 additions & 9 deletions example/ubuntu-22.04.dockerfile

This file was deleted.

14 changes: 14 additions & 0 deletions fs.Dockerfile
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 684b632

Please sign in to comment.