Skip to content

Commit

Permalink
feat: add IMAGE_KERNEL_VERSION suffix to artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolitzer committed Aug 14, 2023
1 parent 395ba86 commit 0647480
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 106 deletions.
57 changes: 12 additions & 45 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
name: Build
on: [push]
env:
KERNEL_VERSION: 5.15.63-ctsi-2
RISCV_PK_VERSION: 1.0.0-ctsi-1
TOOLCHAIN_VERSION: 0.13.0
jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3

- name: Retrieve environment variables
run: make env >> $GITHUB_ENV

- name: Copy default Cartesi Linux config
run: make cartesi-linux-config

Expand Down Expand Up @@ -37,7 +36,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Download dependencies
run: make download checksum
run: make download

- name: Build docker image
id: docker_build
Expand All @@ -53,61 +52,28 @@ jobs:
TOOLCHAIN_REPOSITORY=${{ secrets.DOCKER_ORGANIZATION }}/toolchain
TOOLCHAIN_VERSION=${{ env.TOOLCHAIN_VERSION }}
KERNEL_VERSION=${{ env.KERNEL_VERSION }}
IMAGE_KERNEL_VERSION=${{ env.IMAGE_KERNEL_VERSION }}
RISCV_PK_VERSION=${{ env.RISCV_PK_VERSION }}
cache-from: type=gha,mode=xmax,scope=regular
cache-to: type=gha,scope=regular

- name: Export artifacts
run: make copy IMG=`echo "${{ steps.docker_meta.outputs.tags }}" | head -1 | cut -d "," -f 1 | xargs`

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
path: artifacts/*

- uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/v')
with:
prerelease: true
files: |
linux-headers-${{ env.KERNEL_VERSION }}.tar.xz
linux-nobbl-${{ env.KERNEL_VERSION }}.bin
linux-${{ env.KERNEL_VERSION }}.bin
linux-selftest-${{ env.KERNEL_VERSION }}.ext2
artifacts/*
env:
GITHUB_TOKEN: ${{ secrets.CI_TOKEN }}

- name: Upload [linux-headers-${{ env.KERNEL_VERSION }}.tar.xz]
uses: actions/upload-artifact@v3
with:
name: linux-headers-${{ env.KERNEL_VERSION }}.tar.xz
path: linux-headers-${{ env.KERNEL_VERSION }}.tar.xz

- name: Upload [linux-nobbl-${{ env.KERNEL_VERSION }}.bin]
uses: actions/upload-artifact@v3
with:
name: linux-nobbl-${{ env.KERNEL_VERSION }}.bin
path: linux-nobbl-${{ env.KERNEL_VERSION }}.bin

- name: Upload [linux-${{ env.KERNEL_VERSION }}.bin]
uses: actions/upload-artifact@v3
with:
name: linux-${{ env.KERNEL_VERSION }}.bin
path: linux-${{ env.KERNEL_VERSION }}.bin

- name: Upload [linux-selftest-${{ env.KERNEL_VERSION }}.ext2]
uses: actions/upload-artifact@v3
with:
name: linux-selftest-${{ env.KERNEL_VERSION }}.ext2
path: linux-selftest-${{ env.KERNEL_VERSION }}.ext2

- name: Upload [linux-libc-dev-${{ env.KERNEL_VERSION }}.deb]
uses: actions/upload-artifact@v3
with:
name: linux-libc-dev-${{ env.KERNEL_VERSION }}.deb
path: linux-libc-dev-${{ env.KERNEL_VERSION }}.deb

- name: Upload [linux-libc-dev-riscv64-cross-${{ env.KERNEL_VERSION }}.deb]
uses: actions/upload-artifact@v3
with:
name: linux-libc-dev-riscv64-cross-${{ env.KERNEL_VERSION }}.deb
path: linux-libc-dev-riscv64-cross-${{ env.KERNEL_VERSION }}.deb

- name: Push docker image
id: docker_push
uses: docker/build-push-action@v4
Expand All @@ -123,6 +89,7 @@ jobs:
TOOLCHAIN_REPOSITORY=${{ secrets.DOCKER_ORGANIZATION }}/toolchain
TOOLCHAIN_VERSION=${{ env.TOOLCHAIN_VERSION }}
KERNEL_VERSION=${{ env.KERNEL_VERSION }}
IMAGE_KERNEL_VERSION=${{ env.IMAGE_KERNEL_VERSION }}
RISCV_PK_VERSION=${{ env.RISCV_PK_VERSION }}
cache-from: type=gha,mode=max,scope=regular
cache-to: type=gha,scope=regular
10 changes: 3 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
linux-*.elf
linux-*.bin
linux-nobbl-*.bin
linux-headers-*.tar.xz
linux-selftest-*.ext2
linux-libc-dev-*.deb
artifacts/*
linux-*.tar.gz
riscv-pk-*.tar.gz
cartesi-linux-config
dep
19 changes: 12 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ USER developer

# copy kernel
# ------------------------------------------------------------------------------
COPY --chown=developer:developer dep/linux-${KERNEL_VERSION}.tar.gz ${BUILD_BASE}/dep/
COPY --chown=developer:developer linux-${KERNEL_VERSION}.tar.gz ${BUILD_BASE}/dep/
RUN tar xzf ${BUILD_BASE}/dep/linux-${KERNEL_VERSION}.tar.gz \
--strip-components=1 --one-top-level=${BUILD_BASE}/work/linux && \
rm ${BUILD_BASE}/dep/linux-${KERNEL_VERSION}.tar.gz

# copy riscv-pk
# ------------------------------------------------------------------------------
COPY --chown=developer:developer dep/riscv-pk-${RISCV_PK_VERSION}.tar.gz ${BUILD_BASE}/dep/
COPY --chown=developer:developer riscv-pk-${RISCV_PK_VERSION}.tar.gz ${BUILD_BASE}/dep/
RUN tar xzf ${BUILD_BASE}/dep/riscv-pk-${RISCV_PK_VERSION}.tar.gz \
--strip-components=1 --one-top-level=${BUILD_BASE}/work/riscv-pk && \
rm ${BUILD_BASE}/dep/riscv-pk-${RISCV_PK_VERSION}.tar.gz
Expand All @@ -56,16 +56,21 @@ COPY cartesi-linux-config ${BUILD_BASE}/work/linux/.config

# build
# ------------------------------------------------------------------------------
ARG IMAGE_KERNEL_VERSION=0.0.0
COPY build.mk build.mk
RUN make -f build.mk KERNEL_TIMESTAMP="${KERNEL_TIMESTAMP}"
RUN make -f build.mk KERNEL_TIMESTAMP="${KERNEL_TIMESTAMP}" IMAGE_KERNEL_VERSION="${IMAGE_KERNEL_VERSION}"

# deb headers
# ------------------------------------------------------------------------------
COPY tools tools
RUN make -f build.mk KERNEL_TIMESTAMP="${KERNEL_TIMESTAMP}" DESTDIR=${BUILD_BASE}/work/_install cross-deb \
&& rm -rf ${BUILD_BASE}/work/_install
RUN make -f build.mk KERNEL_TIMESTAMP="${KERNEL_TIMESTAMP}" DESTDIR=${BUILD_BASE}/work/_install native-deb \
&& rm -rf ${BUILD_BASE}/work/_install
RUN \
make -f build.mk KERNEL_TIMESTAMP="${KERNEL_TIMESTAMP}" IMAGE_KERNEL_VERSION="${IMAGE_KERNEL_VERSION}" \
DESTDIR=${BUILD_BASE}/work/_install cross-deb && \
rm -rf ${BUILD_BASE}/work/_install
RUN \
make -f build.mk KERNEL_TIMESTAMP="${KERNEL_TIMESTAMP}" IMAGE_KERNEL_VERSION="${IMAGE_KERNEL_VERSION}" \
DESTDIR=${BUILD_BASE}/work/_install native-deb && \
rm -rf ${BUILD_BASE}/work/_install

USER root

Expand Down
67 changes: 34 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,33 @@

.PHONY: all build download push run pull share copy clean clean-config checksum

MAJOR := 0
MINOR := 16
PATCH := 0
LABEL :=
IMAGE_KERNEL_VERSION?= $(MAJOR).$(MINOR).$(PATCH)$(LABEL)

TAG ?= devel
TOOLCHAIN_DOCKER_REPOSITORY ?= cartesi/toolchain
TOOLCHAIN_TAG ?= 0.13.0
KERNEL_TIMESTAMP ?= $(shell date -Rud @$(shell git log -1 --format=%ct 2> /dev/null || date +%s))
KERNEL_VERSION ?= 5.15.63-ctsi-2
KERNEL_SRCPATH := dep/linux-${KERNEL_VERSION}.tar.gz
KERNEL_SRCPATH := linux-$(KERNEL_VERSION).tar.gz
RISCV_PK_VERSION ?= 1.0.0-ctsi-1
RISCV_PK_SRCPATH := dep/riscv-pk-${RISCV_PK_VERSION}.tar.gz
RISCV_PK_SRCPATH := riscv-pk-$(RISCV_PK_VERSION).tar.gz
KERNEL_CONFIG ?= configs/default-linux-config

CONTAINER_BASE := /opt/cartesi/kernel

IMG ?= cartesi/linux-kernel:$(TAG)
BASE:=/opt/riscv

HEADERS := linux-headers-$(KERNEL_VERSION).tar.xz
IMAGE := linux-nobbl-$(KERNEL_VERSION).bin
LINUX := linux-$(KERNEL_VERSION).bin
LINUX_ELF := linux-$(KERNEL_VERSION).elf
SELFTEST := linux-selftest-$(KERNEL_VERSION).ext2
NATIVE_DEB := linux-libc-dev-$(KERNEL_VERSION).deb
CROSS_DEB := linux-libc-dev-riscv64-cross-$(KERNEL_VERSION).deb

BUILD_ARGS :=

ifneq ($(IMAGE_KERNEL_VERSION),)
BUILD_ARGS += --build-arg IMAGE_KERNEL_VERSION=$(IMAGE_KERNEL_VERSION)
endif

ifneq ($(TOOLCHAIN_DOCKER_REPOSITORY),)
BUILD_ARGS += --build-arg TOOLCHAIN_REPOSITORY=$(TOOLCHAIN_DOCKER_REPOSITORY)
endif
Expand Down Expand Up @@ -91,41 +93,40 @@ run-as-root:
config: CONTAINER_COMMAND := $(CONTAINER_BASE)/scripts/update-linux-config
config: cartesi-linux-config run-as-root

env:
@echo KERNEL_VERSION="$(KERNEL_VERSION)"
@echo IMAGE_KERNEL_VERSION="$(IMAGE_KERNEL_VERSION)"
@echo RISCV_PK_VERSION="$(RISCV_PK_VERSION)"
@echo TOOLCHAIN_VERSION="$(TOOLCHAIN_TAG)"
@make -srf build.mk KERNEL_VERSION=$(KERNEL_VERSION) IMAGE_KERNEL_VERSION=$(IMAGE_KERNEL_VERSION) env
copy:
ID=`docker create $(IMG)` && \
docker cp $$ID:$(BASE)/kernel/artifacts/$(HEADERS) . && \
docker cp $$ID:$(BASE)/kernel/artifacts/$(IMAGE) . && \
docker cp $$ID:$(BASE)/kernel/artifacts/$(LINUX) . && \
docker cp $$ID:$(BASE)/kernel/artifacts/$(LINUX_ELF) . && \
docker cp $$ID:$(BASE)/kernel/artifacts/$(SELFTEST) . && \
docker cp $$ID:$(BASE)/kernel/artifacts/$(NATIVE_DEB) . && \
docker cp $$ID:$(BASE)/kernel/artifacts/$(CROSS_DEB) . && \
docker cp $$ID:$(BASE)/kernel/artifacts/ . && \
docker rm -v $$ID

cartesi-linux-config:
cp $(KERNEL_CONFIG) ./cartesi-linux-config

$(KERNEL_SRCPATH):
wget -O $@ https://github.com/cartesi/linux/archive/v$(KERNEL_VERSION).tar.gz

$(RISCV_PK_SRCPATH):
wget -O $@ https://github.com/cartesi/riscv-pk/archive/v$(RISCV_PK_VERSION).tar.gz

checksum: $(KERNEL_SRCPATH) $(RISCV_PK_SRCPATH)
shasum -ca 256 shasumfile

shasumfile: $(KERNEL_SRCPATH) $(RISCV_PK_SRCPATH)
@shasum -a 256 $^ > $@

download: checksum

clean-config:
rm -f ./cartesi-linux-config

clean: clean-config
rm -f $(HEADERS) $(IMAGE) $(LINUX) $(LINUX_ELF) $(SELFTEST) $(NATIVE_DEB) $(CROSS_DEB)
rm -rf artifacts/

depclean: clean
rm -f \
$(KERNEL_SRCPATH) $(RISCV_PK_SRCPATH)

checksum: $(KERNEL_SRCPATH) $(RISCV_PK_SRCPATH)
shasum -ca 256 shasumfile

download: $(KERNEL_SRCPATH) $(RISCV_PK_SRCPATH)

dep:
mkdir dep
$(KERNEL_SRCPATH): URL=https://github.com/cartesi/linux/archive/v${KERNEL_VERSION}.tar.gz
$(KERNEL_SRCPATH): | dep
T=`mktemp` && wget "$(URL)" -O $$T && mv $$T $@ || rm $$T

$(RISCV_PK_SRCPATH): URL=https://github.com/cartesi/riscv-pk/archive/v${RISCV_PK_VERSION}.tar.gz
$(RISCV_PK_SRCPATH): | dep
T=`mktemp` && wget "$(URL)" -O $$T && mv $$T $@ || rm $$T
31 changes: 19 additions & 12 deletions build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,31 @@ JOBS := -j$(shell nproc)

KERNEL_VERSION ?= $(shell make -sC $(LINUX_DIR) kernelversion)
KERNEL_TIMESTAMP ?= $(shell date -Ru)
HEADERS := artifacts/linux-headers-$(KERNEL_VERSION).tar.xz
IMAGE := artifacts/linux-nobbl-$(KERNEL_VERSION).bin
LINUX := artifacts/linux-$(KERNEL_VERSION).bin
LINUX_ELF := artifacts/linux-$(KERNEL_VERSION).elf
SELFTEST := artifacts/linux-selftest-$(KERNEL_VERSION).ext2
CROSS_DEB_FILENAME := artifacts/linux-libc-dev-riscv64-cross-$(KERNEL_VERSION).deb
NATIVE_DEB_FILENAME := artifacts/linux-libc-dev-$(KERNEL_VERSION).deb
IMAGE_KERNEL_VERSION?= 0.0.0
HEADERS := artifacts/linux-headers-$(KERNEL_VERSION)-v$(IMAGE_KERNEL_VERSION).tar.xz
IMAGE := artifacts/linux-nobbl-$(KERNEL_VERSION)-v$(IMAGE_KERNEL_VERSION).bin
LINUX := artifacts/linux-$(KERNEL_VERSION)-v$(IMAGE_KERNEL_VERSION).bin
LINUX_ELF := artifacts/linux-$(KERNEL_VERSION)-v$(IMAGE_KERNEL_VERSION).elf
SELFTEST := artifacts/linux-selftest-$(KERNEL_VERSION)-v$(IMAGE_KERNEL_VERSION).ext2
CROSS_DEB_FILENAME := artifacts/linux-libc-dev-riscv64-cross-$(KERNEL_VERSION)-v$(IMAGE_KERNEL_VERSION).deb
NATIVE_DEB_FILENAME := artifacts/linux-libc-dev-$(KERNEL_VERSION)-v$(IMAGE_KERNEL_VERSION).deb
ARTIFACTS := $(HEADERS) $(IMAGE) $(LINUX) $(SELFTEST)


all: $(ARTIFACTS)

env:
@echo export ARCH=riscv
@echo export CROSS_COMPILE=$(TOOLCHAIN_PREFIX)-
@echo export KBUILD_BUILD_TIMESTAMP="$(KERNEL_TIMESTAMP)"
@echo export KBUILD_BUILD_USER=dapp
@echo export KBUILD_BUILD_HOST=cartesi
@echo KBUILD_BUILD_TIMESTAMP=\""$(KERNEL_TIMESTAMP)"\"
@echo KBUILD_BUILD_USER=dapp
@echo KBUILD_BUILD_HOST=cartesi

@echo HEADERS="$(HEADERS)"
@echo IMAGE="$(IMAGE)"
@echo LINUX="$(LINUX)"
@echo LINUX_ELF="$(LINUX_ELF)"
@echo SELFTEST="$(SELFTEST)"
@echo CROSS_DEB_FILENAME="$(CROSS_DEB_FILENAME)"
@echo NATIVE_DEB_FILENAME="$(NATIVE_DEB_FILENAME)"

# build linux
# ------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions shasumfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
e8d4d1882632eac7fd8e433b4eb4db014fd56e645fdad3b89be7d1ca4f20ca07 dep/linux-5.15.63-ctsi-2.tar.gz
9a873345b9914940e7bf03a167da823910c8a2acadd818b780ffbd1a3edcc4c5 dep/riscv-pk-1.0.0-ctsi-1.tar.gz
e8d4d1882632eac7fd8e433b4eb4db014fd56e645fdad3b89be7d1ca4f20ca07 linux-5.15.63-ctsi-2.tar.gz
9a873345b9914940e7bf03a167da823910c8a2acadd818b780ffbd1a3edcc4c5 riscv-pk-1.0.0-ctsi-1.tar.gz

0 comments on commit 0647480

Please sign in to comment.