Skip to content

Commit

Permalink
Add content for v24.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
aegagros authored and tsopokis committed Jul 15, 2024
1 parent d73109c commit fa23c27
Show file tree
Hide file tree
Showing 23 changed files with 279 additions and 8,052 deletions.
1 change: 1 addition & 0 deletions .VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24.2.3
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
.vscode/
dist/
build/
105 changes: 30 additions & 75 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,37 @@
# Licensed under the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause

FROM debian:bookworm-slim
ARG SOURCE=/usr/src
ARG DIST_USR=/dist/usr
ARG MIRROR_REGISTRY

FROM ${MIRROR_REGISTRY}alpine:3.17.7 AS alpine_toolchain_builder
ARG SOURCE
ARG DIST_USR
WORKDIR ${SOURCE}
RUN apk add build-base cmake file g++ gcc git jq json-c-dev \
libc-dev make musl-dev && \
mkdir -p ${SOURCE} ${DIST_USR}
RUN git clone https://git.openwrt.org/project/libubox.git && \
cd libubox && git reset --hard d716ac4bc4236031d4c3cc1ed362b502e20e3787 && \
mkdir ${SOURCE}/libubox-build && cd ${SOURCE}/libubox-build && \
cmake ../libubox/ -DCMAKE_INSTALL_PREFIX=${DIST_USR} -DBUILD_LUA=OFF -DBUILD_EXAMPLES=OFF -DCMAKE_C_FLAGS="-Os -s" && \
make && make install
RUN git clone https://git.openwrt.org/project/ubus.git && \
cd ubus && git reset --hard a72457b61df045d3c499a6211362b751710590d7 && \
mkdir ${SOURCE}/ubus-build && cd ${SOURCE}/ubus-build && \
cmake ../ubus/ -DCMAKE_INSTALL_PREFIX=${DIST_USR} -DCMAKE_C_FLAGS="-Os -s" -DBUILD_LUA=OFF -DBUILD_EXAMPLES=OFF -DBUILD_STATIC=OFF && \
make && make install
RUN find ${DIST_USR}/lib/ -name "*.a" -exec rm {} \;

FROM ${MIRROR_REGISTRY}alpine:3.17.7 AS alpine_toolchain
LABEL maintainer="Nokia"
LABEL org.opencontainers.image.source=https://github.com/nokia/corteca-toolchain
LABEL org.opencontainers.image.description="Nokia Corteca Toolchain images"
LABEL org.opencontainers.image.licenses=BSD-3-Clause

ARG BUILDROOT_VERSION=2023.02.1
ARG PARALLEL_PROCS=4
ARG DEVICE_CONFIG
ARG REBUILD_BUILDROOT=yes
ARG DOCKER_USER=user

ENV DEBIAN_FRONTEND=noninteractive
ENV BUILDROOT_VERSION=${BUILDROOT_VERSION}
ENV PARALLEL_PROCS=${PARALLEL_PROCS}
ENV DEVICE_CONFIG=${DEVICE_CONFIG}
ENV PATH="${PATH}:/buildroot/output/host/bin"

COPY --chmod=0755 scripts/nokia_toolchain.sh /usr/bin/nokia_toolchain
COPY --chmod=0755 config/${DEVICE_CONFIG}.config /etc/buildroot.config
COPY --chmod=0644 environments/${DEVICE_CONFIG}.env /etc/target.env

RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y \
bc \
ca-certificates \
cpio \
curl \
file \
gcc-aarch64-linux-gnu \
gcc-arm-linux-gnueabi \
git \
jq \
rsync \
xz-utils \
wget \
unzip \
dirmngr \
fakeroot \
less \
pkg-config \
pkgconf && \
apt-get install --no-install-recommends -y \
golang-go \
binutils \
binutils-x86-64-linux-gnu \
cpp \
g++ \
gcc \
golang-go \
golang-src \
libgcc-12-dev \
libstdc++-12-dev \
rpcsvc-proto && \
apt-get install -y \
build-essential \
libncurses5-dev && \
apt-get -y autoremove && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
mkdir -p /buildroot /app && \
addgroup ${DOCKER_USER} && adduser ${DOCKER_USER} --ingroup ${DOCKER_USER} && \
echo 'export PATH=${PATH}:/buildroot/output/host/bin' >> /etc/bash.bashrc && \
echo "PS1='"'${debian_chroot:+($debian_chroot)}\u@${DEVICE_CONFIG}:\w\$ '"'" >> /etc/bash.bashrc && \
echo "source /etc/target.env" >> /etc/bash.bashrc && \
chown ${DOCKER_USER}:${DOCKER_USER} /buildroot && \
chown ${DOCKER_USER}:${DOCKER_USER} /app

USER $DOCKER_USER

RUN curl https://buildroot.org/downloads/buildroot-${BUILDROOT_VERSION}.tar.xz | \
tar -C /buildroot -xvJ --strip-components=1 && \
cp /etc/buildroot.config /buildroot/.config && \
nokia_toolchain

WORKDIR /buildroot
ENTRYPOINT ["/bin/bash"]
CMD ["/usr/bin/nokia_toolchain", "build_app"]
ARG DIST_USR
COPY --from=alpine_toolchain_builder ${DIST_USR} /usr
COPY --from=alpine_toolchain_builder ${DIST_USR} ${DIST_USR}
RUN apk add build-base cmake curl file g++ gcc git jq json-c-dev \
libc-dev libgcc libstdc++ make musl-dev rsync tar unzip
ENV DIST_USR=${DIST_USR}
130 changes: 97 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,120 @@
# Corteca Toolchain v23.12.1
# Base image for Corteca Toolchain

Part of Corteca Developer Toolkit, Toolchain is a set of compilation tools that help isolate the application within the container, avoiding interaction with the host system's libraries in the creation of applications for [Corteca Marketplace](https://www.nokia.com/networks/fixed-networks/corteca-applications/). This repository is hosted on [https://github.com/nokia/corteca-toolchain](https://github.com/nokia/corteca-toolchain)

## Clone the repository

### Clone with submodules

```bash
git clone --recurse-submodules https://github.com/nokia/corteca-toolchain.git
```

### Add submodules after cloning

In case you have previously cloned the repository without `--recurse-submodules` you can do:

```bash
git submodule update --init --recursive
```

## Repo layout

```shell
├── context # Toolchain image context (files to be included in the images)
│ ├── config # Buildroot configuration files for each toolchain
│ ├── environments # Environment variables for each toolchain
│ └── scripts
│ └── nokia_toolchain.sh # Script for invoking toolchain actions inside the container
├── images # Image resources for this file
├── sample-application # Sample Container Application
├── Dockerfile # Toolchain image Dockerfile
├── README.md # this file
└── USAGE.md # Corteca Development Platform Documentation
├── Documentation # Documentation
├──.VERSION # Toolchain image version
├── Jenkinsfile # Pipeline
├── README.md # This file
└── Dockerfile # Toolchain image Dockerfile
```

## Introduction
## Build toolchain

### Prerequisites

The toolchain image is a multi-platform image, this means that a single image is created and depending on the running platform docker only pulls the layers for the specific architecture.
To enable multi-platform image build we need to change the storage driver and enable docker to run images for different CPU architectures.

This repository contains the files needed to build the Corteca Toolchains. There are 2 flavors of the toolchain depending on the target CPU architecture:
#### Storage drivers

| Toolchain name | CPU Architecture | Indicative list of Corteca devices |
| ---------- | ----------------------- | ------------ |
| `corteca-toolchain-armv7` | armv7, arm-el, 32-bits | Beacon 6 |
| `corteca-toolchain-armv8` | armv8, aarch64, 64-bits | Beacon 10, Beacon 24, Beacon G6, XS-2426X-A, XS-2426G-B, Beacon3.1 / G-1426G-A |
In order to be able to build multi-platform images you need to change the storage driver of docker. The easiest way to do it is to use the [`containerd image store`](https://docs.docker.com/storage/containerd/)

Both of the images are based on Buildroot v2023.02.1 and are configured for each CPU architecture. The following packages are installed by default in the target filesystem:
create file `/etc/docker/daemon.json` with the following contents and restart docker daemon

- Linux Kernel Headers v4.14.x
- binutils v2.37
- libc: musl v1.2.3
- gcc v10
- ubus
- mbedTLS
```text
{
"features": {
"containerd-snapshotter": true
}
}
```

#### Execution of different multi-architecture

Since we build the image for multiple platforms we need to support the execution of different platforms, we also need that in order to run arm64 containers on intel/amd 64bit CPUs.

## Prerequisites
For this we need enable execution of different multi-architecture containers by QEMU and binfmt_misc. For more information, see [qemu-user-static](https://github.com/multiarch/qemu-user-static).

In order to be able to build your application you need to have docker installed and create a directory structure to hold the source code and all the other files that are need for your application.
```shell
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
```

### Docker
### Build a multi-platform base image

The toolchains for compiling and building the containers require docker or a compatible container engine. This document assumes that you use docker. Make sure you have docker installed.
Currently we build an image for amd64, arm32 and arm64.

```shell
docker --version
docker buildx build \
--platform linux/amd64,linux/arm64,linux/arm/v7 \
-t ghcr.io/nokia/corteca-toolchain:$(cat .VERSION) \
-t ghcr.io/nokia/corteca-toolchain \
- < Dockerfile
```

If this fails, please follow the installation procedure for your OS.
### Test the images

### Sample application
We can test that our image supports multiple platforms and test each one of those

In order to be able to build your application you need to create a specific directory structure to hold the source code and all the other files that are need for the container package creation. For more information on this, you can take a look at the [Sample Container Application Documentation](sample-application/README.md).
#### Arm v8 (64bits)

For instructions on using the toolchain to build your application, refer to [Corteca Development Platform Documentation](USAGE.md)
```shell
docker run --rm -it --platform linux/arm64 ghcr.io/nokia/corteca-toolchain uname -m
```

expected output:

```text
aarch64
```

#### Arm v7 (32bits)

```shell
docker run --rm -it --platform linux/arm/v7 ghcr.io/nokia/corteca-toolchain uname -m
```

expected output:

```text
armv7l
```

#### Amd64 (64bits)

```shell
docker run --rm -it --platform linux/amd64 ghcr.io/nokia/corteca-toolchain uname -m
```

expected output:

```text
x86_64
```

### Run a container

You can create a running container e.g. for arm64:

```shell
docker run --rm -it --platform linux/arm64 ghcr.io/nokia/corteca-toolchain
```
71 changes: 0 additions & 71 deletions USAGE.md

This file was deleted.

Loading

0 comments on commit fa23c27

Please sign in to comment.