Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/packaging #88

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
machine-emulator-tools-*.ext2
machine-guest-tools-*.ext2
rootfs*
libcmt*
.clang-format
.github
.git
Expand Down
37 changes: 5 additions & 32 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ jobs:
- name: Export makefile variables
run: make env >> $GITHUB_ENV

- name: Create debian package control file
run: make control

- name: Create version file
run: make package.json

Expand All @@ -55,7 +52,7 @@ jobs:
- name: Buildx setup
uses: docker/setup-buildx-action@v3

- name: Build [${{ env.TOOLS_DEB }}]
- name: Build [${{ env.TOOLS_TARGZ }}]
id: docker_build
uses: docker/build-push-action@v5
with:
Expand All @@ -65,10 +62,9 @@ jobs:
push: false
load: true
build-args: |
TOOLS_DEB=${{ env.TOOLS_DEB }}
IMAGE_KERNEL_VERSION=${{ env.IMAGE_KERNEL_VERSION }}
LINUX_VERSION=${{ env.LINUX_VERSION }}
TOOLS_TARGZ=${{ env.TOOLS_TARGZ }}
LINUX_HEADERS_URLPATH=${{ env.LINUX_HEADERS_URLPATH }}
LINUX_HEADERS_SHA256=${{ env.LINUX_HEADERS_SHA256 }}
cache-from: type=gha,scope=regular,mode=max
cache-to: type=gha,scope=regular

Expand All @@ -91,51 +87,28 @@ jobs:
path: |
${{ env.TOOLS_ROOTFS }}.html

- name: Build libcmt
id: docker_build_libcmt
uses: docker/build-push-action@v5
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
tags: ${{ env.TOOLS_IMAGE }}-libcmt
push: false
load: true
build-args: |
VERSION=${{ env.VERSION }}
target: libcmt-debian-packager
cache-from: type=gha,scope=regular,mode=max
cache-to: type=gha,scope=regular

- name: Retrieve artifacts
run: make copy-libcmt

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
if-no-files-found: error
path: |
${{ env.TOOLS_DEB }}
${{ env.TOOLS_TARGZ }}
${{ env.TOOLS_ROOTFS }}
libcmt/deb/*

- name: Checksum artifacts
if: startsWith(github.ref, 'refs/tags/v')
run: |
sha512sum ${{ env.TOOLS_DEB }} > ${{ env.TOOLS_DEB }}.sha512
sha512sum ${{ env.TOOLS_TARGZ }} > ${{ env.TOOLS_TARGZ }}.sha512
sha512sum ${{ env.TOOLS_ROOTFS }} > ${{ env.TOOLS_ROOTFS }}.sha512
for f in libcmt/deb/*; do sha512sum $f > $f.sha512; done

- uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/v')
with:
prerelease: true
files: |
${{ env.TOOLS_DEB }}
${{ env.TOOLS_DEB }}.sha512
${{ env.TOOLS_ROOTFS }}
${{ env.TOOLS_ROOTFS }}.html
${{ env.TOOLS_ROOTFS }}.sha512
libcmt/deb/*

test:
runs-on: ubuntu-latest-8-cores
Expand Down
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
*.ext2
control
machine-emulator-tools-*.tar.gz
machine-emulator-tools-*.deb
machine-guest-tools-*.tar.gz
rootfs.*
libcmt-*.*
package.json
*.bin

sys-utils/hex/hex
sys-utils/ioctl-echo-loop/ioctl-echo-loop
sys-utils/rollup/rollup
sys-utils/xhalt/xhalt
sys-utils/yield/yield

# Prerequisites
*.d

Expand Down
60 changes: 38 additions & 22 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,25 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Allow compiling inside riscv64 envionment without cross compilation
- Allow to install all tools with `make install`
- Added delegate call voucher to rollup tools and libcmt

### Changed
- Bump dependencies versions
- Generate rootfs.ext2.html with licenses of all installed packages
- Generate `rootfs.ext2.html` with licenses of all installed packages
- Bump Ubuntu to 24.04 LTS
- Rename repository to machine-guest-tools
- Simplified build system to make packaging easier
- Binaries are not automatically stripped anymore, this should be done when packaging
- Remove all references to `cartesi/toolchain` Docker image
- Avoid using `cttyhack` in `cartesi-init` to support Alpine Linux
- Increased JsonConfig limit in `rollup-http-server`
- Removed pinning of package versions from all Dockerfiles

### Removed
- Removed all Debian packaging from this repository build system

## [0.16.1] - 2024-08-12
### Fixed
Expand Down Expand Up @@ -178,24 +194,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [0.2.0]
- [0.1.0]

[Unreleased]: https://github.com/cartesi/machine-emulator-tools/compare/v0.16.1...HEAD
[0.16.1]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.16.1
[0.16.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.16.0
[0.15.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.15.0
[0.14.1]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.14.1
[0.14.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.14.0
[0.13.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.13.0
[0.12.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.12.0
[0.11.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.11.0
[0.10.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.10.0
[0.9.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.9.0
[0.8.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.8.0
[0.7.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.7.0
[0.6.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.6.0
[0.5.1]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.5.1
[0.5.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.5.0
[0.4.1]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.4.1
[0.4.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.4.0
[0.3.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.3.0
[0.2.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.2.0
[0.1.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.1.0
[Unreleased]: https://github.com/cartesi/machine-guest-tools/compare/v0.16.1...HEAD
[0.16.1]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.16.1
[0.16.0]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.16.0
[0.15.0]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.15.0
[0.14.1]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.14.1
[0.14.0]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.14.0
[0.13.0]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.13.0
[0.12.0]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.12.0
[0.11.0]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.11.0
[0.10.0]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.10.0
[0.9.0]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.9.0
[0.8.0]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.8.0
[0.7.0]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.7.0
[0.6.0]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.6.0
[0.5.1]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.5.1
[0.5.0]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.5.0
[0.4.1]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.4.1
[0.4.0]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.4.0
[0.3.0]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.3.0
[0.2.0]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.2.0
[0.1.0]: https://github.com/cartesi/machine-guest-tools/releases/tag/v0.1.0
178 changes: 26 additions & 152 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,179 +14,53 @@
# limitations under the License.
#

FROM ubuntu:22.04 AS tools-env
ARG IMAGE_KERNEL_VERSION=v0.20.0
ARG LINUX_VERSION=6.5.13-ctsi-1
ARG LINUX_HEADERS_URLPATH=https://github.com/cartesi/image-kernel/releases/download/${IMAGE_KERNEL_VERSION}/linux-libc-dev-riscv64-cross-${LINUX_VERSION}-${IMAGE_KERNEL_VERSION}.deb
ARG BUILD_BASE=/opt/cartesi
FROM ubuntu:24.04 AS tools-env

# Install dependencies
# ------------------------------------------------------------------------------
ENV LINUX_HEADERS_FILEPATH=/tmp/linux-libc-dev-riscv64-cross-${LINUX_VERSION}-${IMAGE_KERNEL_VERSION}.deb

ARG LINUX_HEADERS_URLPATH=
ARG LINUX_HEADERS_SHA256=
ADD ${LINUX_HEADERS_URLPATH} /tmp/linux-libc-dev-riscv64-cross.deb
RUN <<EOF
set -e

export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get upgrade -y
apt-get install -y --no-install-recommends \
dpkg-dev \
g++-12 \
gcc-12 \
g++ \
gcc \
make \
ca-certificates \
git \
wget \
libclang-dev \
pkg-config \
dpkg-cross \
gcc-12-riscv64-linux-gnu \
g++-12-riscv64-linux-gnu

for tool in cpp g++ gcc gcc-ar gcc-nm gcc-ranlib gcov gcov-dump gcov-tool; do
update-alternatives --install /usr/bin/riscv64-linux-gnu-$tool riscv64-linux-gnu-$tool /usr/bin/riscv64-linux-gnu-$tool-12 12
update-alternatives --install /usr/bin/$tool $tool /usr/bin/$tool-12 12
done
update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-12 12
adduser \
rustup \
gcc-riscv64-linux-gnu \
g++-riscv64-linux-gnu

wget -O ${LINUX_HEADERS_FILEPATH} ${LINUX_HEADERS_URLPATH}
echo "2723435e8b45d8fb7a79e9344f6dc517b3dbc08e03ac17baab311300ec475c08 ${LINUX_HEADERS_FILEPATH}" | sha256sum --check
apt-get install -y --no-install-recommends ${LINUX_HEADERS_FILEPATH}

adduser developer -u 499 --gecos ",,," --disabled-password
mkdir -p ${BUILD_BASE}/tools && chown -R developer:developer ${BUILD_BASE}/tools
rm -rf /var/lib/apt/lists/* ${LINUX_HEADERS_FILEPATH}
echo "${LINUX_HEADERS_SHA256} /tmp/linux-libc-dev-riscv64-cross.deb" | sha256sum --check
apt-get install -y --no-install-recommends --allow-downgrades /tmp/linux-libc-dev-riscv64-cross.deb
EOF

ENV RISCV_ARCH="rv64gc"
ENV RISCV_ABI="lp64d"
ENV CFLAGS="-march=$RISCV_ARCH -mabi=$RISCV_ABI"
ENV TOOLCHAIN_PREFIX="riscv64-linux-gnu-"
ENV RUSTUP_HOME=/opt/rust
ENV PATH="/opt/rust/toolchains/1.77-x86_64-unknown-linux-gnu/bin:${PATH}"

FROM tools-env AS builder
COPY --chown=developer:developer sys-utils/ ${BUILD_BASE}/tools/sys-utils/

# build C/C++ tools
# ------------------------------------------------------------------------------
FROM builder AS c-builder
ARG CMT_BASE=${BUILD_BASE}/tools/sys-utils/libcmt
ARG BUILD_BASE=/opt/cartesi

USER developer
RUN make -C ${CMT_BASE} -j$(nproc) libcmt
USER root
RUN make -C ${BUILD_BASE}/tools/sys-utils/libcmt/ -j$(nproc) install TARGET_PREFIX=/usr/riscv64-linux-gnu
USER developer
RUN make -C ${BUILD_BASE}/tools/sys-utils/ -j$(nproc) all

# build libcmt debian package
# ------------------------------------------------------------------------------
FROM c-builder AS libcmt-debian-packager
ARG CMT_BASE=${BUILD_BASE}/tools/sys-utils/libcmt
ARG VERSION=0.0.0
USER root

RUN make -C ${CMT_BASE} \
ARG_VERSION=${VERSION} \
TARGET_PREFIX=/usr \
TARGET_DESTDIR=${BUILD_BASE}/install/run \
install-run libcmt-v${VERSION}.deb

RUN make -C ${CMT_BASE} \
ARG_VERSION=${VERSION} \
TARGET_PREFIX=/usr \
TARGET_DESTDIR=${BUILD_BASE}/install/dev \
install libcmt-dev-v${VERSION}.deb
# Install rust
RUN rustup default 1.77 && rustup target add riscv64gc-unknown-linux-gnu

RUN make -C ${CMT_BASE} \
ARG_VERSION=${VERSION} \
TARGET_PREFIX=/usr/riscv64-linux-gnu \
TARGET_DESTDIR=${BUILD_BASE}/install/cross \
install libcmt-dev-riscv64-cross-v${VERSION}.deb

# build rust tools
# build
# ------------------------------------------------------------------------------
FROM c-builder AS rust-env
ENV PATH="/home/developer/.cargo/bin:${PATH}"
ENV PKG_CONFIG_PATH_riscv64gc_unknown_linux_gnu="/usr/riscv64-linux-gnu/lib/pkgconfig"
ENV PKG_CONFIG_riscv64gc_unknown_linux_gnu="/usr/bin/pkg-config"

USER developer

RUN cd && \
wget https://github.com/rust-lang/rustup/archive/refs/tags/1.27.0.tar.gz && \
echo "3d331ab97d75b03a1cc2b36b2f26cd0a16d681b79677512603f2262991950ad1 1.27.0.tar.gz" | sha256sum --check && \
tar -xzf 1.27.0.tar.gz && \
bash rustup-1.27.0/rustup-init.sh \
-y \
--default-toolchain 1.77.2 \
--profile minimal \
--target riscv64gc-unknown-linux-gnu && \
rm -rf rustup-1.27.0 1.27.0.tar.gz

FROM rust-env AS rust-builder
COPY --chown=developer:developer rollup-http/rollup-init ${BUILD_BASE}/tools/rollup-http/rollup-init
COPY --chown=developer:developer rollup-http/rollup-http-client ${BUILD_BASE}/tools/rollup-http/rollup-http-client
COPY --chown=developer:developer rollup-http/.cargo ${BUILD_BASE}/tools/rollup-http/.cargo

# build rollup-http-server dependencies
FROM rust-builder AS http-server-dep-builder
COPY --chown=developer:developer rollup-http/rollup-http-server/Cargo.toml rollup-http/rollup-http-server/Cargo.lock ${BUILD_BASE}/tools/rollup-http/rollup-http-server/
RUN cd ${BUILD_BASE}/tools/rollup-http/rollup-http-server && \
mkdir src/ && \
echo "fn main() {}" > src/main.rs && \
echo "pub fn dummy() {}" > src/lib.rs && \
cargo build --target riscv64gc-unknown-linux-gnu --release

# build rollup-http-server
FROM http-server-dep-builder AS http-server-builder
COPY --chown=developer:developer rollup-http/rollup-http-server/build.rs ${BUILD_BASE}/tools/rollup-http/rollup-http-server/
COPY --chown=developer:developer rollup-http/rollup-http-server/src ${BUILD_BASE}/tools/rollup-http/rollup-http-server/src
RUN cd ${BUILD_BASE}/tools/rollup-http/rollup-http-server && touch build.rs src/* && \
cargo build --target riscv64gc-unknown-linux-gnu --release

# build echo-dapp dependencies
FROM rust-builder AS echo-dapp-dep-builder
COPY --chown=developer:developer rollup-http/echo-dapp/Cargo.toml rollup-http/echo-dapp/Cargo.lock ${BUILD_BASE}/tools/rollup-http/echo-dapp/
RUN cd ${BUILD_BASE}/tools/rollup-http/echo-dapp && \
mkdir src/ && echo "fn main() {}" > src/main.rs && \
cargo build --target riscv64gc-unknown-linux-gnu --release

# build echo-dapp
FROM echo-dapp-dep-builder AS echo-dapp-builder
COPY --chown=developer:developer rollup-http/echo-dapp/src ${BUILD_BASE}/tools/rollup-http/echo-dapp/src
RUN cd ${BUILD_BASE}/tools/rollup-http/echo-dapp && touch src/* && \
cargo build --target riscv64gc-unknown-linux-gnu --release

# pack tools (deb)
# ------------------------------------------------------------------------------
FROM tools-env AS packer
ARG TOOLS_DEB=machine-emulator-tools.deb
ARG STAGING_BASE=${BUILD_BASE}/_install
ARG STAGING_DEBIAN=${STAGING_BASE}/DEBIAN
ARG STAGING_SBIN=${STAGING_BASE}/usr/sbin
ARG STAGING_BIN=${STAGING_BASE}/usr/bin
ARG STAGING_SHARE=${STAGING_BASE}/usr/share/machine-emulator-tools

RUN mkdir -p ${STAGING_DEBIAN} ${STAGING_SBIN} ${STAGING_BIN} ${STAGING_BASE}/etc && \
echo "cartesi-machine" > ${staging_base}/etc/hostname

COPY control ${STAGING_DEBIAN}/control
COPY package.json ${STAGING_SHARE}/package.json
COPY postinst ${STAGING_DEBIAN}/postinst
COPY copyright ${STAGING_BASE}/usr/share/doc/machine-emulator-tools/copyright
FROM tools-env AS builder

COPY --from=builder ${BUILD_BASE}/tools/sys-utils/cartesi-init/cartesi-init ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/xhalt/xhalt ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/yield/yield ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/hex/hex ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/rollup/rollup ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/ioctl-echo-loop/ioctl-echo-loop ${STAGING_BIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/yield/yield ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/misc/* ${STAGING_BIN}
COPY --from=rust-builder ${BUILD_BASE}/tools/rollup-http/rollup-init/rollup-init ${STAGING_SBIN}
COPY --from=http-server-builder ${BUILD_BASE}/tools/rollup-http/rollup-http-server/target/riscv64gc-unknown-linux-gnu/release/rollup-http-server ${STAGING_BIN}
COPY --from=echo-dapp-builder ${BUILD_BASE}/tools/rollup-http/echo-dapp/target/riscv64gc-unknown-linux-gnu/release/echo-dapp ${STAGING_BIN}
COPY . /work
WORKDIR /work

RUN dpkg-deb -Zxz --root-owner-group --build ${STAGING_BASE} ${BUILD_BASE}/${TOOLS_DEB}
RUN make -j$(nproc) libcmt
RUN make -j$(nproc) sys-utils
RUN make -j$(nproc) rollup-http
RUN make install DESTDIR=$(pwd)/_install PREFIX=/usr
ARG TOOLS_TARGZ=machine-guest-tools.tar.gz
RUN cd _install && tar -czf /work/${TOOLS_TARGZ} *
Loading
Loading