Skip to content

Commit

Permalink
add ci using github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Josua-SR committed Jun 24, 2024
1 parent 3f13952 commit 44ac76c
Show file tree
Hide file tree
Showing 2 changed files with 190 additions and 0 deletions.
135 changes: 135 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: build

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
prepare_container:
runs-on: self-hosted
outputs:
uid: ${{ steps.uid_step.outputs.userid }}
gid: ${{ steps.uid_step.outputs.groupid }}
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4

- name: Get user id/group
id: uid_step
run: |
echo "userid=$(id -u)" >> "$GITHUB_OUTPUT"
echo "groupid=$(id -g)" >> "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-config: /etc/docker/cibuilder.toml

- name: Login to Docker Registry
uses: docker/login-action@v3
with:
registry: ciserver.ci:5000
username: ${{ secrets.CI_CACHE_REGISTRY_LOGIN }}
password: ${{ secrets.CI_CACHE_REGISTRY_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ciserver.ci:5000/${{ github.repository_id }}:latest
cache-from: type=registry,ref=ciserver.ci:5000/${{ github.repository_id }}:cache
cache-to: type=registry,ref=ciserver.ci:5000/${{ github.repository_id }}:cache,mode=max
file: docker/Dockerfile
build-args: |
USER_ID=${{ steps.uid_step.outputs.userid }}
GROUP_ID=${{ steps.uid_step.outputs.groupid }}
build_project:
needs: prepare_container
runs-on: self-hosted
timeout-minutes: 30
container:
image: ciserver.ci:5000/${{ github.repository_id }}:latest
credentials:
username: ${{ secrets.CI_CACHE_REGISTRY_LOGIN }}
password: ${{ secrets.CI_CACHE_REGISTRY_PASSWORD }}
options: --user "${{ needs.prepare_container.outputs.uid }}:${{ needs.prepare_container.outputs.gid }}"
outputs:
build_tag: ${{ steps.tag_step.outputs.build_tag }}
steps:
- name: Checkout pull-request
uses: actions/checkout@v4

- name: Download Project Sources
run: |
newt upgrade
- name: Get build tag
id: tag_step
run: |
build_tag=$(date +%Y-%m-%d)_$(git rev-parse --short HEAD)
echo "build_tag=$build_tag" >> "$GITHUB_OUTPUT"
- name: Build
strategy:
matrix:
platform:
- imx8mqsom-nina-b1
- ssn6-nina-b111
- ssn6-nina-b301
- ssn6-fwm7blz22
app: [boot, blehci]
shell: bash
run: |
mkdir deploy
for target in {imx8mqsom-nina-b1,ssn6-nina-b111,ssn6-nina-b301,ssn6-fwm7blz22}; do
newt build ${target}_boot
cp -v bin/targets/${target}_boot/app/@mcuboot/boot/mynewt/mynewt.elf.bin deploy/${target}_boot.elf.bin
newt build ${target}_blehci
newt create-image ${target}_blehci $build_tag
cp -v bin/targets/${target}_blehci/app/@apache-mynewt-nimble/apps/blehci/blehci.img deploy/${target}_nimble.img
done
- name: Deploy to the local minio storage
uses: yakubique/[email protected]
with:
endpoint: http://ciserver.ci:9000
insecure: true
access_key: ${{ secrets.CI_CACHE_MINIO_ACCESS }}
secret_key: ${{ secrets.CI_CACHE_MINIO_SECRET }}
bucket: cipublish
source: ./deploy
target: "/${{ github.repository_id }}/${{ steps.tag_step.outputs.build_tag }}"
recursive: true

publish_artifacts:
needs: build_project
runs-on: self-hosted
if: github.event_name == 'push'
steps:
- name: Download an artifacts from MinIO
uses: yakubique/[email protected]
with:
endpoint: http://ciserver.ci:9000
insecure: true
access_key: ${{ secrets.CI_CACHE_MINIO_ACCESS }}
secret_key: ${{ secrets.CI_CACHE_MINIO_SECRET }}
bucket: cipublish
source: "/${{ github.repository_id }}/${{ needs.build_images.outputs.build_tag }}/"
target: "."
recursive: true

- name: Upload to S3
uses: shallwefootball/[email protected]
with:
aws_key_id: ${{ secrets.IMAGES_S3_ACCESS }}
aws_secret_access_key: ${{ secrets.IMAGES_S3_SECRET }}
aws_bucket: ${{ secrets.IMAGES_S3_BUCKET }}
endpoint: ${{ secrets.IMAGES_S3_HOST }}
source_dir: deploy
destination_dir: SolidSense/mynewt-sr-blehci/${{ needs.build_images.outputs.build_tag }}
55 changes: 55 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
FROM debian:bookworm-slim

# Install host toolchain
ENV DEBIAN_FRONTEND noninteractive
RUN set -e; \
apt-get update; \
apt-get upgrade -y; \
apt-get install -y build-essential ca-certificates git locales wget; \
locale-gen en_GB.UTF-8; \
update-ca-certificates; \
:

# set locales
ENV \
LANG=en_GB.UTF-8 \
LANGUAGE=en_GB:en \
LC_ALL=en_GB.UTF-8

# install cross toolchain
RUN set -e; \
wget https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz; \
tar -C /opt -xf arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz; \
rm -f arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz; \
:
ENV PATH="/opt/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi/bin:$PATH"

# install "newt" tool
RUN set -e; \
wget https://archive.apache.org/dist/mynewt/apache-mynewt-1.11.0/apache-mynewt-newt-bin-linux-1.11.0.tgz; \
tar --strip-components=1 -xvf apache-mynewt-newt-bin-linux-1.11.0.tgz apache-mynewt-newt-bin-linux-1.11.0/newt; \
install -v -m755 -o root -g root newt /usr/local/bin/; \
rm newt; \
:

# Arguments to pass host user's UID and GID
ARG USER_ID=1000
ARG GROUP_ID=1000

# Create a user 'developer' with the same UID/GID as the host user
RUN groupadd -g ${GROUP_ID} developer
RUN useradd -m -u ${USER_ID} -g developer -d /home/developer developer
RUN mkdir -p /workspace
RUN chown -R developer:developer /workspace
RUN mkdir -p /home/developer/.ssh
RUN touch /home/developer/.ssh/known_hosts
RUN chmod 700 /home/developer/.ssh
RUN chmod 600 /home/developer/.ssh/known_hosts
RUN chown -R developer:developer /home/developer/.ssh

RUN git config --add --system user.email "[email protected]"
RUN git config --add --system user.name "Build Container"
RUN git config --add --system http.version HTTP/1.1

# The entry point is set to bash. This means that when the container starts, it will drop the user into bash
ENTRYPOINT ["/bin/bash"]

0 comments on commit 44ac76c

Please sign in to comment.