Linux builds #71
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Linux | |
run-name: Linux builds | |
on: | |
push: | |
paths: | |
- "dockerfiles/**/linux/Dockerfile" | |
jobs: | |
changed_dockerfiles: | |
name: Get target dockerfiles | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.changed_dockerfiles.outputs.all_changed_files }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Get changed files | |
id: changed_dockerfiles | |
uses: tj-actions/changed-files@v41 | |
with: | |
json: true | |
escape_json: false | |
files: | | |
**/linux/Dockerfile | |
- name: Show changed dockerfiles | |
run: echo '${{ steps.changed_dockerfiles.outputs.all_changed_files }}' | |
get_nuke_sources: | |
name: Collect and upload Nuke sources | |
runs-on: ubuntu-latest | |
needs: [changed_dockerfiles] | |
strategy: | |
matrix: | |
files: ${{ fromJSON(needs.changed_dockerfiles.outputs.matrix) }} | |
fail-fast: false | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Get cache key | |
id: unique_name | |
run: | | |
unique_name=$(echo "${{ matrix.files }}" | sed 's/\//_/g') | |
echo "unique_name=${unique_name}" >> $GITHUB_ENV | |
cache_key=${unique_name}_${{ hashFiles('**/scripts/nuke_source_from_dockerfile.bash') }} | |
echo "cache_key=${cache_key}" >> $GITHUB_ENV | |
echo "Got key '$cache_key'" | |
- name: Get Nuke source files cache | |
id: cache_nuke_source | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/nuke_source_files | |
key: ${{ env.cache_key }} | |
- name: Collect Nuke source files | |
if: steps.cache_nuke_source.outputs.cache-hit != 'true' | |
timeout-minutes: 30 | |
run: | | |
mkdir /tmp/nuke_source_files | |
bash "${GITHUB_WORKSPACE}/scripts/nuke_source_from_dockerfile.bash" "${{ matrix.files }}" /tmp/nuke_source_files | |
- name: Create artifact tar | |
run: tar -czvf /tmp/nuke_source_files.tar.gz -C /tmp nuke_source_files | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: nuke_source_files_${{ env.unique_name}} | |
path: /tmp/nuke_source_files.tar.gz | |
build: | |
name: Build base | |
runs-on: ubuntu-latest | |
needs: [changed_dockerfiles, get_nuke_sources] | |
strategy: | |
matrix: | |
files: ${{ fromJSON(needs.changed_dockerfiles.outputs.matrix) }} | |
fail-fast: false | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Get unique name | |
id: unique_name | |
run: | | |
unique_name=$(echo "${{ matrix.files }}" | sed 's/\//_/g') | |
echo "unique_name=${unique_name}" >> $GITHUB_ENV | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: nuke_source_files_${{ env.unique_name }} | |
path: /tmp/ | |
- name: Prepare source files | |
run: | | |
DOCKERFILE_DIRECTORY=$(dirname ${{ github.workspace }}/${{ matrix.files }}) | |
echo "Directory set to $DOCKERFILE_DIRECTORY" | |
echo "dockerfile_directory=${DOCKERFILE_DIRECTORY}" >> "$GITHUB_ENV" | |
tar -xzf /tmp/nuke_source_files.tar.gz -C $DOCKERFILE_DIRECTORY | |
- name: Build and export | |
uses: docker/build-push-action@v5 | |
with: | |
context: ${{ env.dockerfile_directory }} | |
file: ${{ needs.get_nuke_sources.outputs.filename }} | |
tags: nukedockerbuild:latest | |
outputs: type=docker,dest=/tmp/nukedockerbuild.tar.gz | |
build-args: NUKE_SOURCE_FILES=nuke_source_files | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: docker_image_${{ env.unique_name }} | |
path: /tmp/nukedockerbuild.tar.gz | |
test_build: | |
name: Test base | |
needs: [changed_dockerfiles, build] | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
files: ${{ fromJSON(needs.changed_dockerfiles.outputs.matrix) }} | |
fail-fast: false | |
steps: | |
- name: Get unique name | |
id: unique_name | |
run: | | |
unique_name=$(echo "${{ matrix.files }}" | sed 's/\//_/g') | |
echo "unique_name=${unique_name}" >> $GITHUB_ENV | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: docker_image_${{ env.unique_name }} | |
path: /tmp/ | |
- name: Load image | |
run: | | |
docker load --input /tmp/nukedockerbuild.tar.gz | |
- name: Tests | |
run: | | |
mkdir /tmp/tests/ | |
docker run -v /tmp/tests:/nuke_build_directory nukedockerbuild:latest bash -c \ | |
"cd /usr/local/nuke_install/tests && cmake3 . -B /nuke_build_directory && cmake3 --build /nuke_build_directory" | |
- name: Prepare test results for upload | |
run: tar -czvf /tmp/test_run.tar.gz /tmp/tests | |
- name: Upload tests artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: tests_run_base_${{ env.unique_name }} | |
path: /tmp/test_run.tar.gz | |
build_slim: | |
name: Build slim | |
needs: [changed_dockerfiles, test_build] | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
files: ${{ fromJSON(needs.changed_dockerfiles.outputs.matrix) }} | |
fail-fast: false | |
steps: | |
- name: Get unique name | |
id: unique_name | |
run: | | |
unique_name=$(echo "${{ matrix.files }}" | sed 's/\//_/g') | |
echo "unique_name=${unique_name}" >> $GITHUB_ENV | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: docker_image_${{ env.unique_name }} | |
path: /tmp/ | |
- name: Load image | |
run: docker load --input /tmp/nukedockerbuild.tar.gz | |
- name: Setup SlimToolkit | |
run: | | |
curl -sL https://raw.githubusercontent.com/slimtoolkit/slim/master/scripts/install-slim.sh | sudo -E bash - | |
- name: Create Slim image | |
run: | | |
slim build \ | |
--target nukedockerbuild:latest \ | |
--http-probe=false \ | |
--exec "bash -c 'cd /usr/local/nuke_install/tests/ && echo $CMAKE_PREFIX_PATH $NUKE_VERSION && cmake3 . -B /nuke_build_directory && cmake3 --build /nuke_build_directory'" \ | |
--preserve-path /opt/rh \ | |
--preserve-path /usr/share/cmake \ | |
--preserve-path /usr/share/cmake3 \ | |
--preserve-path /usr/lib64 \ | |
--preserve-path /usr/include/ \ | |
--preserve-path /usr/local/nuke_install/ | |
docker save nukedockerbuild.slim:latest > /tmp/nukedockerbuild_slim.tar.gz | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: docker_image_slim_${{ env.unique_name }} | |
path: /tmp/nukedockerbuild_slim.tar.gz | |
test_slim: | |
name: Test slim | |
needs: [changed_dockerfiles, build_slim] | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
files: ${{ fromJSON(needs.changed_dockerfiles.outputs.matrix) }} | |
fail-fast: false | |
steps: | |
- name: Get unique name | |
id: unique_name | |
run: | | |
unique_name=$(echo "${{ matrix.files }}" | sed 's/\//_/g') | |
echo "unique_name=${unique_name}" >> $GITHUB_ENV | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: docker_image_slim_${{ env.unique_name }} | |
path: /tmp/ | |
- name: Load image | |
run: | | |
docker load --input /tmp/nukedockerbuild_slim.tar.gz | |
- name: Run tests | |
run: | | |
mkdir /tmp/tests | |
docker run -v /tmp/tests:/nuke_build_directory nukedockerbuild.slim:latest bash -c \ | |
"cd /usr/local/nuke_install/tests && cmake3 . -B /nuke_build_directory && cmake3 --build /nuke_build_directory" | |
- name: Prepare test results for upload | |
run: tar -czvf /tmp/test_run.tar.gz /tmp/tests | |
- name: Upload tests artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: tests_run_slim_${{ env.unique_name }} | |
path: /tmp/test_run.tar.gz | |
deploy: | |
name: Deploy | |
needs: [changed_dockerfiles, test_build, test_slim] | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
permissions: write-all | |
env: | |
PUSH_LOCATION: "ghcr.io/gillesvink/nukedockerbuild" | |
strategy: | |
matrix: | |
files: ${{ fromJSON(needs.changed_dockerfiles.outputs.matrix) }} | |
fail-fast: false | |
steps: | |
- name: Get unique name | |
id: unique_name | |
run: | | |
unique_name=$(echo "${{ matrix.files }}" | sed 's/\//_/g') | |
echo "unique_name=${unique_name}" >> $GITHUB_ENV | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: docker_image_${{ env.unique_name }} | |
path: /tmp/ | |
- uses: actions/download-artifact@v4 | |
with: | |
name: docker_image_slim_${{ env.unique_name }} | |
path: /tmp/ | |
- name: Load image | |
run: | | |
docker load --input /tmp/nukedockerbuild.tar.gz | |
docker load --input /tmp/nukedockerbuild_slim.tar.gz | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set tag and push | |
run: | | |
NUKE_VERSION=$(docker inspect -f '{{index .Config.Labels "com.nukedockerbuild.nuke_version"}}' nukedockerbuild:latest) | |
OPERATING_SYSTEM=$(docker inspect -f '{{index .Config.Labels "com.nukedockerbuild.operating_system"}}' nukedockerbuild:latest) | |
VERSION=$(docker inspect -f '{{index .Config.Labels "org.opencontainers.version"}}' nukedockerbuild:latest) | |
TAG=${NUKE_VERSION}-${OPERATING_SYSTEM} | |
docker tag nukedockerbuild:latest ${PUSH_LOCATION}:${TAG}-${VERSION} | |
docker tag nukedockerbuild:latest ${PUSH_LOCATION}:${TAG}-latest | |
docker tag nukedockerbuild.slim:latest ${PUSH_LOCATION}:${TAG}-slim-${VERSION} | |
docker tag nukedockerbuild.slim:latest ${PUSH_LOCATION}:${TAG}-slim-latest | |
docker image push ${PUSH_LOCATION}:${TAG}-${VERSION} | |
docker image push ${PUSH_LOCATION}:${TAG}-latest | |
docker image push ${PUSH_LOCATION}:${TAG}-slim-${VERSION} | |
docker image push ${PUSH_LOCATION}:${TAG}-slim-latest |