Skip to content

Commit

Permalink
misc cmake/make script improvements (#488)
Browse files Browse the repository at this point in the history
* move script actions to make commands

* fix platform script

* fix README

* Update doc/cmake.md

Co-authored-by: Christopher Degawa <[email protected]>

* make exit code >0

Co-authored-by: Christopher Degawa <[email protected]>
  • Loading branch information
xwu2git and 1480c1 committed May 5, 2020
1 parent 6194edb commit 468c15a
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 84 deletions.
39 changes: 6 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ cmake_minimum_required (VERSION 2.8)

Project(DockerFiles NONE)

add_custom_target(update_link)
add_custom_target(update_dockerfile)
add_custom_target(generate_readme)
add_custom_target(upload_readme)

if (NOT DEFINED BUILD_VERSION)
set(BUILD_VERSION "1.0")
endif()
Expand All @@ -14,38 +19,10 @@ if (NOT DEFINED BUILD_FDKAAC)
set(BUILD_FDKAAC "ON")
endif()

if (NOT DEFINED UPDATE_DOCKERFILES)
set(UPDATE_DOCKERFILES "OFF")
endif()

if (NOT DEFINED DOCKER_PREFIX)
set(DOCKER_PREFIX "openvisualcloud")
endif()

if (NOT DEFINED UPDATE_IMAGELIST)
set(UPDATE_IMAGELIST "OFF")
endif()

if (NOT DEFINED UPDATE_DOCKERHUB_README)
set(UPDATE_DOCKERHUB_README "OFF")
endif()

if (UPDATE_IMAGELIST STREQUAL "ON")
set(UPDATE_DOCKERFILES "ON")
endif()

if (NOT DEFINED UPDATE_IMAGE_README)
set(UPDATE_IMAGE_README "OFF")
endif()

if (UPDATE_IMAGE_README STREQUAL "ON")
set(UPDATE_DOCKERFILES "ON")
endif()

if (UPDATE_DOCKERHUB_README STREQUAL "ON")
set(UPDATE_DOCKERFILES "ON")
endif()

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/script/")

enable_testing()
Expand All @@ -59,8 +36,4 @@ message(
"-- Setting: BUILD_MP3LAME=${BUILD_MP3LAME}\n"
"-- Setting: BUILD_FDKAAC=${BUILD_FDKAAC}\n"
"-- Setting: DOCKER_PREFIX=${DOCKER_PREFIX}\n"
"-- Setting: UPDATE_DOCKERFILES=${UPDATE_DOCKERFILES}\n"
"-- Setting: UPDATE_IMAGELIST=${UPDATE_IMAGELIST}\n"
"-- Setting: UPDATE_IMAGE_README=${UPDATE_IMAGE_README}\n"
"-- Setting: UPDATE_DOCKERHUB_README=${UPDATE_DOCKERHUB_README}\n")

)
33 changes: 19 additions & 14 deletions doc/cmake.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@

### Customize Build Process:
### Customize the Build Process:

You can use the following build options to customize the build process:
- **BUILD_VERSION**: Specify the build version string.
- **DOCKER_PREFIX**: Specify the docker image prefix string.
- **BUILD_MP3LAME**: Set to ```ON``` (default) to build the ```libmp3lame``` in the docker images, or ```OFF``` to disable including ```libmp3lame``` in the docker images.
- **BUILD_FDKAAC**: Set to ```ON``` (default) to build the ```libfdk_aac``` in the docker images, or ```OFF``` to disable including ```libfdk_aac``` in the docker images.
- **UPDATE_DOCKERFILES**: Set to ```ON``` to update the Dockerfiles only without actually building them, or ```OFF``` (default) to update and build the Dockerfiles.
- **UPDATE_IMAGELIST**: Set to ```ON``` to update the image list in each platform README.md. Install `gawk` if it is not available on your platform.
- **UPDATE_IMAGE_README**: Set to ```ON``` to update/generate the README file for all Dockerfiles. Install `python3` if it is not available on your platform.
- **UPDATE_DOCKERHUB_README**: Set to ```ON``` to upload image README.md to docker hub. Install `jq` if it is not available on your platform.

Build examples:

```
```bash
cd build
cmake -DBUILD_MP3LAME=ON ..
```

```
```bash
cd build
cmake -DBUILD_FDKAAC=ON -DBUILD_MP3LAME=OFF ..
```
#### Generate README files:
`python3` is required on the host system to use this.

cd build
cmake -DUPDATE_IMAGE_README=ON ..
### Command Make Targets

- **update_link**: Update the image links in the platform README.md.
- **update_dockerfile**: Update the Dockerfiles. Do this after modifying any templates.
- **generate_readme**: Generate the image README.md for dockerhub.
- **upload_readme**: Upload the image README.md to dockerhub.

Example: Generate the dockerhub READMEs

```bash
cd build
cmake ..
make generate_readme
```

### Use Alternative Repo:

Expand All @@ -41,6 +49,3 @@ For a list of all REPOs and their versions, run the following command:
```bash
grep -E '_(REPO|VER)=' template/*.m4
```
~


19 changes: 6 additions & 13 deletions script/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ fi
BUILD_VERSION="${1:-1.0}"
BUILD_MP3LAME="${2:-ON}"
BUILD_FDKAAC="${3:-ON}"
UPDATE_DOCKERFILES="${4:-OFF}"
UPDATE_DOCKERHUB_README="${5:-OFF}"
DOCKER_PREFIX="${6:-openvisualcloud}"
DOCKER_PREFIX="${4:-openvisualcloud}"
SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)/"
BUILD_CACHE=""
FULL_CACHE=""
Expand All @@ -29,14 +27,9 @@ if [[ $1 == -n ]]; then
exit 0
fi

if [[ ${UPDATE_DOCKERFILES} == OFF ]]; then
build_args=$(env | cut -f1 -d= | grep -E '_(proxy|REPO|VER)$' | sed 's/^/--build-arg /')
if grep -q 'AS build' "${DIR}/Dockerfile"; then
docker build --network=host ${BUILD_CACHE} --target build -t "${DOCKER_PREFIX}/${IMAGE}:build" "$DIR" $build_args
fi

docker build --network=host ${FULL_CACHE} -t "${DOCKER_PREFIX}/${IMAGE}:${BUILD_VERSION}" -t "${DOCKER_PREFIX}/${IMAGE}:latest" "$DIR" $build_args
elif [[ ${UPDATE_DOCKERHUB_README} == ON ]]; then
README_FILEPATH="$(echo "$PWD/README.md" | sed 's/build\///')"
${SCRIPT_ROOT}/update-dockerhub-readme.sh ${DOCKER_PREFIX} ${IMAGE} ${README_FILEPATH}
build_args=$(env | cut -f1 -d= | grep -E '_(proxy|REPO|VER)$' | sed 's/^/--build-arg /')
if grep -q 'AS build' "${DIR}/Dockerfile"; then
docker build --network=host ${BUILD_CACHE} --target build -t "${DOCKER_PREFIX}/${IMAGE}:build" "$DIR" $build_args
fi

docker build --network=host ${FULL_CACHE} -t "${DOCKER_PREFIX}/${IMAGE}:${BUILD_VERSION}" -t "${DOCKER_PREFIX}/${IMAGE}:latest" "$DIR" $build_args
22 changes: 9 additions & 13 deletions script/generate_readme.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os
#!/usr/bin/python3

from pathlib import Path
import re
import os
import sys

REPO_LINK = "https://github.com/OpenVisualCloud/Dockerfiles/blob/master/"

Expand Down Expand Up @@ -121,14 +124,6 @@
# M4 files for which no license is needed
license_exclude = ['automake', 'build-tools', 'build-tools-hddl', 'build-tools-hddl-layer', 'cleanup', 'cmake', 'install', 'install.pkgs', 'install.pkgs.owt', 'libfdk-aac', 'libmp3lame', 'nasm', 'nginx-cert', 'nginx-conf', 'qat', 'transform360', 'yasm', 'libva-utils', 'ospray-example_san-miguel', 'ospray-example_xfrog','libusb']

# Walk through the repo and find folder with Dockerfiles.m4
def walk_path(path):
for root, dirs, files in os.walk(path):
for my_file in files:
if ( my_file == 'Dockerfile.m4' ):
path_components = parse_ingredients(root)
create_readme(root, path_components)

# Find image platform / OS / image type / image name from file path
def parse_ingredients(path):
path_components = path.split('/')
Expand Down Expand Up @@ -312,8 +307,9 @@ def create_readme(path, path_components):
my_file.write(generate_license(path, image_name, image_type, image_os, image_platform))
my_file.close()

def main():
walk_path(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
if len(sys.argv)<1:
print("Usage: <README path>\n")
exit(1)

if __name__ == "__main__":
main()
path=sys.argv[1]
create_readme(path, parse_ingredients(path))
10 changes: 9 additions & 1 deletion script/image.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
add_custom_target(build_${image} ALL "${CMAKE_CURRENT_SOURCE_DIR}/build.sh" ${BUILD_VERSION} ${BUILD_MP3LAME} ${BUILD_FDKAAC} ${UPDATE_DOCKERFILES} ${UPDATE_DOCKERHUB_README} ${DOCKER_PREFIX})
add_custom_target(build_${image} ALL "${CMAKE_CURRENT_SOURCE_DIR}/build.sh" ${BUILD_VERSION} ${BUILD_MP3LAME} ${BUILD_FDKAAC} ${DOCKER_PREFIX})
if(dep_image)
add_dependencies(build_${image} build_${dep_image})
endif()
add_custom_target(shell_${image} "${CMAKE_CURRENT_SOURCE_DIR}/shell.sh" ${DOCKER_PREFIX})

add_custom_target(update_${image}_dockerfile COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/build.sh" -n ${BUILD_MP3LAME} ${BUILD_FDKAAC} ${DOCKER_PREFIX})
add_dependencies(update_dockerfile update_${image}_dockerfile)

add_custom_target(generate_${image}_readme COMMAND "${CMAKE_SOURCE_DIR}/script/generate_readme.py" "${CMAKE_CURRENT_SOURCE_DIR}")
add_dependencies(generate_readme generate_${image}_readme)

add_custom_target(upload_${image}_readme COMMAND "${CMAKE_SOURCE_DIR}/script/upload-dockerhub-readme.sh" ${DOCKER_PREFIX} ${image} "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
add_dependencies(upload_readme upload_${image}_readme)
12 changes: 2 additions & 10 deletions script/platform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ foreach(dir ${os_dirs})
endforeach()

if(platform)
if(UPDATE_IMAGELIST STREQUAL "ON")
add_custom_target(build_${platform} ALL COMMAND ${CMAKE_SOURCE_DIR}/script/update-imagelist.sh ${DOCKER_PREFIX} ${platform} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
endif()

if(platform)
if(UPDATE_IMAGE_README STREQUAL "ON")
add_custom_target(build_${platform} ALL COMMAND sudo python3 ${CMAKE_SOURCE_DIR}/script/generate_readme.py )
endif()
add_custom_target(update_${platform}_link COMMAND ${CMAKE_SOURCE_DIR}/script/update-image-link.sh ${DOCKER_PREFIX} ${platform} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_dependencies(update_link update_${platform}_link)
endif()

File renamed without changes.
File renamed without changes.

0 comments on commit 468c15a

Please sign in to comment.