Skip to content

Commit

Permalink
Add new action to create docker image (#16)
Browse files Browse the repository at this point in the history
# Description
Add new action to create docker image

## Type of change
- New feature (non-breaking change which adds functionality)

## Checklist before requesting a review
- [x] I have performed a self-review of my code.
- [x] If it is a core feature, I have added thorough tests.
- [x] If this is a new component I have added examples.
- [x] I updated the README and related documentation.
  • Loading branch information
filippobrizzi authored Feb 2, 2024
1 parent b40081c commit 9e73fb9
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 78 deletions.
37 changes: 37 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.cache/
.git/
.vscode/
build/

# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
83 changes: 83 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
name: Build and deploy pipeline

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
PRESET: preferred

jobs:
docker_build_and_publish:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: dorny/[email protected]
id: filter
with:
filters: |
docker:
- 'docker/**'
- name: Docker login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push the image
if: steps.filter.outputs.docker == 'true'
run: |
cd ${{github.workspace}}/docker
./build.sh
docker_deps_build_and_publish:
needs: docker_build_and_publish
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: dorny/[email protected]
id: filter
with:
filters: |
external:
- 'external/**'
- name: Docker login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push the image
if: steps.filter.outputs.external == 'true'
run: |
cd ${{github.workspace}}/docker
./build_deps.sh
build:
needs: docker_deps_build_and_publish
# TODO: use the docker image published at the step over
runs-on: ubuntu-latest
container:
image: ghcr.io/filippobrizzi/x86_64/eolo-dev_deps:latest
credentials:
username: ${{ github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
steps:
- uses: actions/checkout@v3
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build --preset CI
# TODO: add a step to run the formatter
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build -- all examples

- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ninja checks
41 changes: 0 additions & 41 deletions .github/workflows/cmake-single-platform.yml

This file was deleted.

29 changes: 28 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,34 @@
"cacheVariables": {
"BUILD_MODULES": "all"
}
}
},
{
"name": "deps-docker",
"description": "Configuration setting for all modules with preferred toolchain",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build",
"installDir": "/install",
"toolchainFile": "${sourceDir}/toolchains/toolchain_clang.cmake",
"cacheVariables": {
"BUILD_MODULES": "all",
"ENABLE_LINTER": "OFF",
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "CI",
"description": "Configuration setting for all modules with preferred toolchain",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build",
"installDir": "/install",
"toolchainFile": "${sourceDir}/toolchains/toolchain_clang.cmake",
"cacheVariables": {
"BUILD_MODULES": "all",
"ENABLE_LINTER": "ON",
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_PREFIX_PATH": "/install"
}
}
],
"buildPresets": [
{
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
ARG BASE_IMAGE

# FROM arm64v8/ubuntu:22.04
FROM ${BASE_IMAGE}

ENV DEBIAN_FRONTEND=noninteractive
Expand Down
17 changes: 17 additions & 0 deletions docker/Dockerfile_deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE}

SHELL ["/bin/bash", "-c"]

COPY . /tmp/eolo/
RUN ls /tmp/eolo/

RUN mkdir /tmp/eolo/build
WORKDIR /tmp/eolo/build
RUN . "$HOME/.cargo/env" && cmake ../ --preset deps-docker
RUN ninja all && \
ninja install

RUN cd / && rm -rf /tmp/eolo

WORKDIR /
28 changes: 24 additions & 4 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,36 @@

source ./version.sh


ARCH=$(uname -m)
HOST_ARCH=$(uname -m)
ARCH=${1:-${HOST_ARCH}}
if [ "${ARCH}" == "aarch64" ]; then
ARCH = "arm64"
fi

if [ "${ARCH}" == "x86_64" ]; then
# see https://hub.docker.com/r/nvidia/opengl/tags
BASE_IMAGE="nvidia/opengl:1.0-glvnd-runtime-ubuntu22.04"
else
elif [ "${ARCH}" == "arm64" ]; then
BASE_IMAGE="arm64v8/ubuntu:22.04"
else
echo "Supported arch value: arm64, x86_64"
exit 1
fi

ncores=$(cat /proc/cpuinfo | grep processor | wc -l)

docker build -t ${IMAGE}:${VERSION} -f Dockerfile --cpuset-cpus "0-$ncores" --build-arg BASE_IMAGE=${BASE_IMAGE} .
IMAGE_NAME="ghcr.io/filippobrizzi/${ARCH}/${IMAGE}"

function docker_tag_exists() {
docker manifest inspect ${IMAGE_NAME}:${VERSION} > /dev/null
}

if docker_tag_exists; then
echo "Image already exists, you can pull it with:"
echo "$ docker pull ${IMAGE_NAME}:${VERSION}"
else
echo "Building image: ${IMAGE_NAME}:${VERSION}"
docker build -t ${IMAGE_NAME}:${VERSION} -f Dockerfile --cpuset-cpus "0-$ncores" --build-arg BASE_IMAGE=${BASE_IMAGE} . --tag ${IMAGE_NAME}:latest
docker push ${IMAGE_NAME}:${VERSION}
docker push ${IMAGE_NAME}:latest
fi
32 changes: 32 additions & 0 deletions docker/build_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

source ./version.sh

HOST_ARCH=$(uname -m)
ARCH=${1:-${HOST_ARCH}}
if [ "${ARCH}" == "aarch64" ]; then
ARCH = "arm64"
fi

BASE_IMAGE=ghcr.io/filippobrizzi/${ARCH}/${IMAGE}:${VERSION}
docker pull ${BASE_IMAGE}

SUFFIX=deps
IMAGE_NAME="ghcr.io/filippobrizzi/${ARCH}/${IMAGE}_${SUFFIX}"

function docker_tag_exists() {
docker manifest inspect ${IMAGE_NAME}:${VERSION} > /dev/null
}

if docker_tag_exists; then
echo "Image already exists, you can pull it with:"
echo "$ docker pull ${IMAGE_NAME}:${DEPS_VERSION}"
else
echo "Building image: ${IMAGE_NAME}:${DEPS_VERSION}"
pushd ../
docker build . -t ${IMAGE_NAME}:${DEPS_VERSION} -f docker/Dockerfile_deps --cpuset-cpus "0-$ncores" --build-arg BASE_IMAGE=${BASE_IMAGE} --tag ${IMAGE_NAME}:latest
popd

docker push ${IMAGE_NAME}:${DEPS_VERSION}
docker push ${IMAGE_NAME}:latest
fi
5 changes: 4 additions & 1 deletion docker/version.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

VERSION=1.0.1
VERSION=1.0.2
IMAGE=eolo-dev

# This is the version of the dep image. Increase this number everytime you change `external/CMakeLists.txt`
DEPS_VERSION=1.0.2
Loading

0 comments on commit 9e73fb9

Please sign in to comment.