Skip to content

Commit

Permalink
improved docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
filippobrizzi committed Jan 31, 2024
1 parent 90fd081 commit e2d5119
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 29 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
run: |
cd ${{github.workspace}}/docker
./build.sh
./publish.sh
docker_deps_build_and_publish:
needs: docker_build_and_publish
runs-on: ubuntu-latest
Expand All @@ -56,8 +55,7 @@ jobs:
if: steps.filter.outputs.external == 'true'
run: |
cd ${{github.workspace}}/docker
./build_dev.sh
./publish_dev.sh
./build_deps.sh
build:
needs: docker_deps_build_and_publish
# TODO: use the docker image published at the step over
Expand Down
27 changes: 24 additions & 3 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,37 @@

source ./version.sh

HOST_ARCH=$(uname -m)
ARCH=${1:-${HOST_ARCH}}

ARCH=$(uname -m)
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} . --tag ${IMAGE}:latest
IMAGE_NAME="ghcr.io/filippobrizzi/${ARC}/${IMAGE}"

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

if docker_tag_exists; then
echo "Image already exists, pulling it"
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}:latest
docker push ${IMAGE_NAME}:${VERSION}
docker push ${IMAGE_NAME}:latest
fi
30 changes: 23 additions & 7 deletions docker/build_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,31 @@

source ./version.sh

ncores=$(cat /proc/cpuinfo | grep processor | wc -l)
((ncores--))
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/${ARC}/${IMAGE}_${SUFFIX}"

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

BASE_IMAGE=ghcr.io/filippobrizzi/${IMAGE}:${VERSION}
docker pull ${BASE_IMAGE}
docker build . -t ${IMAGE}_${SUFFIX}:${VERSION} -f docker/Dockerfile_deps --cpuset-cpus "0-$ncores" --build-arg BASE_IMAGE=${BASE_IMAGE} --tag ${IMAGE}_${SUFFIX}:latest
if docker_tag_exists; then
echo "Image already exists, pulling it: ${IMAGE_NAME}:${VERSION}"
docker pull ${IMAGE_NAME}:${VERSION}
else
echo "Building image: ${IMAGE_NAME}:${VERSION}"
pushd ../
docker build . -t ${IMAGE_NAME}:${VERSION} -f docker/Dockerfile_deps --cpuset-cpus "0-$ncores" --build-arg BASE_IMAGE=${BASE_IMAGE} --tag ${IMAGE_NAME}_${SUFFIX}:latest
popd

popd
docker push ${IMAGE_NAME}:${VERSION}
docker push ${IMAGE_NAME}:latest
fi
7 changes: 0 additions & 7 deletions docker/publish.sh

This file was deleted.

9 changes: 0 additions & 9 deletions docker/publish_deps.sh

This file was deleted.

0 comments on commit e2d5119

Please sign in to comment.