Skip to content

Commit

Permalink
Merge pull request #27 from AlexVCaron/feat/github_runner
Browse files Browse the repository at this point in the history
Fix actions-runner image building
  • Loading branch information
AlexVCaron authored Sep 23, 2024
2 parents ae6f0a4 + adfe358 commit 014a9fb
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 121 deletions.
58 changes: 30 additions & 28 deletions .github/workflows/actions-runner-builder.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
name: Build scilus/actions-runner image

on:
workflow_dispatch:
schedule:
- cron: "0 2 * * *" # Runs at 02:00 every day
workflow_dispatch:
schedule:
- cron: "0 7 * * *" # Runs at 02:00-EST (7:00-UTC) every day

jobs:
build-action-runner:
runs-on: ubuntu-latest
compute-dependencies-versions:
runs-on: scilus-org-runners
outputs:
runner_current_version: ${{ steps.github-runner.outputs.current_version }}
runner_latest_version: ${{ steps.github-runner.outputs.latest_version }}

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
steps:
- uses: ksivamuthu/actions-setup-gh-cli@v3
# From : https://github.com/actions/actions-runner-controller/blob/0bfa57ac504dfc818128f7185fc82830cbdb83f1/.github/workflows/arc-update-runners-scheduled.yaml#L14
- name: actions-runner version
id: github-runner
env:
GH_TOKEN: ${{ github.token }}
run: |
CURRENT_VERSION=$(echo -n $(cat /VERSION | grep 'runner =>' | cut -d '>' -f2 | tr -d '\n' | tr -d ' '))
LATEST_VERSION=$(gh release list --exclude-drafts --exclude-pre-releases --limit 1 -R actions/runner | grep -oP '(?<=v)[0-9.]+' | head -1)
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "latest_version=$LATEST_VERSION" >> $GITHUB_OUTPUT
- name: VTK version
id: vtk-version
run: |
version=$(cat versioning.hcl | grep vtk-version | sed 's/vtk-version="\(.*\)"/\1/')
echo "::set-output name=version::$version"
- name: actions-runner version
id: github-runner
uses: docker://ghcr.io/scilus/actions-runner:latest
with:
entrypoint: /bin/bash
args: -c "echo ::set-output name=version::$(cat /version.txt)"

- name: build
uses: ./docker-builder.yml
with:
target: actions-runner
tag: ${{ steps.github-runner.outputs.version }}-vtk${{ steps.vtk-version.outputs.version }}
update-latest: true
disable-builddate-tag: true
actions-runner-version: ${{ steps.github-runner.outputs.version }}
build-runner-image:
needs: [compute-dependencies-versions]
if: ${{ needs.compute-dependencies-versions.outputs.runner_current_version != needs.compute-dependencies-versions.outputs.runner_latest_version }}
uses: ./.github/workflows/docker-builder.yml
with:
target: actions-runner
update-latest: true
disable-builddate-tag: true
actions-runner-version: ${{ needs.compute-dependencies-versions.outputs.runner_latest_version }}
secrets: inherit
100 changes: 67 additions & 33 deletions .github/workflows/docker-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ on:
required: true
type: string
tag:
required: true
required: false
type: string
update-latest:
required: false
Expand Down Expand Up @@ -135,8 +135,7 @@ on:

jobs:
build-container:
runs-on:
group: scilus-docker-builders
runs-on: scilus-docker-builders
steps:
-
name: Validate input parameters
Expand All @@ -147,7 +146,7 @@ jobs:
fi
-
name: Checkout build system
uses: actions/checkout@v3
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
repository: ${{ github.repository_owner }}/containers-scilus
ref: ${{ inputs.build-system-ref }}
Expand All @@ -156,34 +155,72 @@ jobs:
id: local-versioning
run: |
touch local-versioning.hcl
version () { if [ -n "$1" ]; then echo "${2}=\"${1}\"" >> local-versioning.hcl; fi }
echo "dockerhub-user-pull=\"${{ secrets.DOCKER_USERNAME }}\"" >> local-versioning.hcl
echo "dockerhub-user-push=\"${{ secrets.DOCKER_USERNAME }}\"" >> local-versioning.hcl
[ -z "${{ inputs.scilpy-version }}" ] || echo "scilpy-version=\"${{ inputs.scilpy-version }}\"" >> local-versioning.hcl
[ -z "${{ inputs.dmriqcpy-version }}" ] || echo "dmriqcpy-version=\"${{ inputs.dmriqcpy-version }}\"" >> local-versioning.hcl
[ -z "${{ inputs.nextflow-version }}" ] || echo "nextflow-version=\"${{ inputs.nextflow-version }}\"" >> local-versioning.hcl
[ -z "${{ inputs.tractoflow-version }}" ] || echo "tractoflow-version=\"${{ inputs.tractoflow-version }}\"" >> local-versioning.hcl
[ -z "${{ inputs.dmriqc-flow-version }}" ] || echo "dmriqc-flow-version=\"${{ inputs.dmriqc-flow-version }}\"" >> local-versioning.hcl
[ -z "${{ inputs.extractor-flow-version }}" ] || echo "extractor-flow-version=\"${{ inputs.extractor-flow-version }}\"" >> local-versioning.hcl
[ -z "${{ inputs.rbx-flow-version }}" ] || echo "rbx-flow-version=\"${{ inputs.rbx-flow-version }}\"" >> local-versioning.hcl
[ -z "${{ inputs.tractometry-flow-version }}" ] || echo "tractometry-flow-version=\"${{ inputs.tractometry-flow-version }}\"" >> local-versioning.hcl
[ -z "${{ inputs.register-flow-version }}" ] || echo "register-flow-version=\"${{ inputs.register-flow-version }}\"" >> local-versioning.hcl
[ -z "${{ inputs.disconets-flow-version }}" ] || echo "disconets-flow-version=\"${{ inputs.disconets-flow-version }}\"" >> local-versioning.hcl
[ -z "${{ inputs.freewater-flow-version }}" ] || echo "freewater-flow-version=\"${{ inputs.freewater-flow-version }}\"" >> local-versioning.hcl
[ -z "${{ inputs.noddi-flow-version }}" ] || echo "noddi-flow-version=\"${{ inputs.noddi-flow-version }}\"" >> local-versioning.hcl
[ -z "${{ inputs.bst-flow-version }}" ] || echo "bst-flow-version=\"${{ inputs.bst-flow-version }}\"" >> local-versioning.hcl
[ -z "${{ inputs.actions-runner-version }}" ] || echo "actions-runner-image=\"ghcr.io/actions/actions-runner:${{ inputs.actions-runner-version }}\"" >> local-versioning.hcl
version "${{ inputs.scilpy-version }}" scilpy-version
version "${{ inputs.dmriqcpy-version }}" dmriqcpy-version
version "${{ inputs.nextflow-version }}" nextflow-version
version "${{ inputs.tractoflow-version }}" tractoflow-version
version "${{ inputs.dmriqc-flow-version }}" dmriqc-flow-version
version "${{ inputs.extractor-flow-version }}" extractor-flow-version
version "${{ inputs.rbx-flow-version }}" rbx-flow-version
version "${{ inputs.tractometry-flow-version }}" tractometry-flow-version
version "${{ inputs.register-flow-version }}" register-flow-version
version "${{ inputs.disconets-flow-version }}" disconets-flow-version
version "${{ inputs.freewater-flow-version }}" freewater-flow-version
version "${{ inputs.noddi-flow-version }}" noddi-flow-version
version "${{ inputs.bst-flow-version }}" bst-flow-version
version "${{ inputs.actions-runner-version }}" actions-runner-version
echo "DEPS_TAG=\"${{ inputs.scilus-dependencies-tag }}\"" >> local-versioning.hcl
[ "${{ inputs.target }}" == "scilus-flows" ] && echo "SCILUS_TAG=\"${{ inputs.scilus-for-scilus-flows-tag }}\"" >> local-versioning.hcl
if [ "${{ inputs.target }}" == "scilus-flows" ]
then
version "${{ inputs.scilus-for-scilus-flows-tag }}" SCILUS_TAG
fi
vtk_version=$(cat versioning.hcl | grep vtk-version | cut -d "=" -f2)
vtk_version=$(echo $vtk_version | tr -d " " | tr -d "\"")
ACR_TAG=${{ inputs.actions-runner-version }}-vtk${vtk_version}
if [ -n "${{ inputs.actions-runner-version }}" ]
then
version "$ACR_TAG" ACR_TAG
fi
echo "bake-file=$PWD/local-versioning.hcl" >> $GITHUB_OUTPUT
-
name: Set output image tags and registry to publish to
id: dockerhub-tags
env:
IMAGE: ${{ secrets.DOCKER_USERNAME }}/${{ inputs.target }}
run: |
touch tag-publishing
echo "${{ inputs.target }}.output=type=registry" >> tag-publishing
echo "${{ inputs.target }}.tags=${{ secrets.DOCKER_USERNAME }}/${{ inputs.target }}:${{ inputs.tag }}" >> tag-publishing
[ "${{ inputs.disable-builddate-tag }}" != "true" ] && echo "${{ inputs.target }}.tags=${{ secrets.DOCKER_USERNAME }}/${{ inputs.target }}:${{ inputs.tag }}-$(date +'%Y%m%d')" >> tag-publishing
[ "${{ inputs.update-latest }}" == "true" ] && echo "${{ inputs.target }}.tags=${{ secrets.DOCKER_USERNAME }}/${{ inputs.target }}:latest" >> tag-publishing
[ -z ${{ inputs.tag }} ] || {
echo "${{ inputs.target }}.tags=${{ env.IMAGE }}:${{ inputs.tag }}" >> tag-publishing
}
[ "${{ inputs.disable-builddate-tag }}" != "true" ] && {
echo "${{ inputs.target }}.tags=${{ env.IMAGE }}-$(date +'%Y%m%d')" >> tag-publishing
}
if [ "${{ inputs.update-latest }}" == "true" ]
then
echo "${{ inputs.target }}.tags=${{ env.IMAGE }}:latest" >> tag-publishing
if [ "${{ inputs.target }}" == "actions-runner" ]
then
if [ -n "${{ inputs.actions-runner-version }}" ]
then
vtk_version=$(cat versioning.hcl | grep vtk-version | cut -d "=" -f2)
vtk_version=$(echo $vtk_version | tr -d " " | tr -d "\"")
ACR_TAG=${{ inputs.actions-runner-version }}-vtk${vtk_version}
echo "${{ inputs.target }}.tags=${{ env.IMAGE }}:$ACR_TAG" >> tag-publishing
fi
fi
fi
DELIM="$(echo $RANDOM | base64 | head -c 3; echo)"
echo "tags-file=$PWD/tag-publishing" >> $GITHUB_OUTPUT
echo "tags-string<<$DELIM" >> $GITHUB_OUTPUT
Expand All @@ -192,7 +229,7 @@ jobs:
echo "git-output=$GITHUB_OUTPUT" >> $GITHUB_OUTPUT
-
name: Upload versioning and caching hcl as artifacts
uses: actions/upload-artifact@v3.1.1
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
with:
name: HCL artifacts
path: |
Expand All @@ -201,21 +238,17 @@ jobs:
${{ steps.dockerhub-tags.outputs.git-output }}
-
name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
version: v0.11.0
driver-opts: |
image=moby/buildkit:v0.11.6
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1
-
name: Build container
id: container-build
uses: docker/bake-action@v3.1.0
uses: docker/bake-action@76cc8060bdff6d632a465001e4cf300684c5472c # v5.7.0
with:
targets: |
${{ inputs.target }}
Expand All @@ -224,7 +257,8 @@ jobs:
./versioning.hcl
./docker-bake.hcl
set: ${{ steps.dockerhub-tags.outputs.tags-string }}
push: true
pull: true
push: false
-
name: Save output container metadata to file
id: container-metadata
Expand All @@ -233,7 +267,7 @@ jobs:
echo "metadata=$PWD/container-metadata.json" >> $GITHUB_OUTPUT
-
name: Upload bake definition
uses: actions/upload-artifact@v3.1.1
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
with:
name: Baking artifacts
path: |
Expand Down
34 changes: 23 additions & 11 deletions cache-push.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,58 @@ variable "dockerhub-user-push" {
default = "scilus"
}

variable "cache-parameters" {
default = "mode=max,image-manifest=true,oci-mediatypes=true,compression=zstd,compression-level=9,force-compression=true"
}

target "actions-runner" {
cache-to = ["type=registry,${cache-parameters},ref=${dockerhub-user-push}/build-cache:actions-runner"]
}

target "actions-runner-vtk" {
cache-to = ["type=registry,${cache-parameters},ref=${dockerhub-user-push}/build-cache:actions-runner-vtk"]
}

target "scilus" {
cache-to = ["type=registry,mode=max,ref=${dockerhub-user-push}/build-cache:scilus"]
cache-to = ["type=registry,${cache-parameters},ref=${dockerhub-user-push}/build-cache:scilus"]
}

target "scilus-base" {
cache-to = ["type=registry,mode=max,ref=${dockerhub-user-push}/build-cache:scilus-base"]
cache-to = ["type=registry,${cache-parameters},ref=${dockerhub-user-push}/build-cache:scilus-base"]
}

target "scilpy-base" {
cache-to = ["type=registry,mode=max,ref=${dockerhub-user-push}/build-cache:scilpy"]
cache-to = ["type=registry,${cache-parameters},ref=${dockerhub-user-push}/build-cache:scilpy"]
}

target "dmriqcpy-base" {
cache-to = ["type=registry,mode=max,ref=${dockerhub-user-push}/build-cache:dmriqcpy"]
cache-to = ["type=registry,${cache-parameters},ref=${dockerhub-user-push}/build-cache:dmriqcpy"]
}

target "cmake" {
cache-to = ["type=registry,mode=max,ref=${dockerhub-user-push}/build-cache:cmake"]
cache-to = ["type=registry,${cache-parameters},ref=${dockerhub-user-push}/build-cache:cmake"]
}

target "vtk" {
cache-to = ["type=registry,mode=max,ref=${dockerhub-user-push}/build-cache:vtk"]
cache-to = ["type=registry,${cache-parameters},ref=${dockerhub-user-push}/build-cache:vtk"]
}

target "ants" {
cache-to = ["type=registry,mode=max,ref=${dockerhub-user-push}/build-cache:ants"]
cache-to = ["type=registry,${cache-parameters},ref=${dockerhub-user-push}/build-cache:ants"]
}

target "mrtrix" {
cache-to = ["type=registry,mode=max,ref=${dockerhub-user-push}/build-cache:mrtrix"]
cache-to = ["type=registry,${cache-parameters},ref=${dockerhub-user-push}/build-cache:mrtrix"]
}

target "fsl" {
cache-to = ["type=registry,mode=max,ref=${dockerhub-user-push}/build-cache:fsl"]
cache-to = ["type=registry,${cache-parameters},ref=${dockerhub-user-push}/build-cache:fsl"]
}

target "scilus-flows" {
cache-to = ["type=registry,mode=max,ref=${dockerhub-user-push}/build-cache:scilus-flows"]
cache-to = ["type=registry,${cache-parameters},ref=${dockerhub-user-push}/build-cache:scilus-flows"]
}

target "scilus-fsl" {
cache-to = ["type=registry,mode=max,ref=${dockerhub-user-push}/build-cache:scilus-deps"]
cache-to = ["type=registry,${cache-parameters},ref=${dockerhub-user-push}/build-cache:scilus-deps"]
}
11 changes: 10 additions & 1 deletion containers/actions-runner.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ FROM actions-runner-base AS actions-runner

ARG CONTAINER_INSTALL_USER
ARG CONTAINER_RUN_USER
ARG RUNNER_VERSION
ARG RUNNER_HOOK_VERSION

ENV USER=${USER:-0}
ENV USER=0
ENV CONTAINER_INSTALL_USER=${CONTAINER_INSTALL_USER:-USER}
ENV CONTAINER_RUN_USER=${CONTAINER_RUN_USER:-USER}
ENV DEBIAN_FRONTEND=noninteractive
ENV RUNNER_VERSION=${RUNNER_VERSION:-2.319.1}
ENV RUNNER_HOOK_VERSION=${RUNNER_HOOK_VERSION:-0.6.1}

USER $CONTAINER_INSTALL_USER

Expand All @@ -27,4 +31,9 @@ ENV LANGUAGE="en_US.UTF-8"
RUN locale-gen "en_US.UTF-8" && \
update-locale LANG=en_US.UTF-8

WORKDIR /
RUN ( [ -f "VERSION" ] || touch VERSION ) && \
echo "runner => ${RUNNER_VERSION}\n" >> VERSION && \
echo "runner-hook => ${RUNNER_HOOK_VERSION}\n" >> VERSION

USER $CONTAINER_RUN_USER
2 changes: 1 addition & 1 deletion containers/ants.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# syntax=docker.io/docker/dockerfile:1.6.0
# syntax=docker.io/docker/dockerfile:1.10.0

FROM ants-builder as ants

Expand Down
22 changes: 13 additions & 9 deletions containers/cmake.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# syntax=docker.io/docker/dockerfile:1.6.0
# syntax=docker.io/docker/dockerfile:1.10.0

FROM scratch as clone

Check warning on line 3 in containers/cmake.Dockerfile

View workflow job for this annotation

GitHub Actions / build-runner-image / build-container

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

Check warning on line 3 in containers/cmake.Dockerfile

View workflow job for this annotation

GitHub Actions / build-runner-image / build-container

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

Check warning on line 3 in containers/cmake.Dockerfile

View workflow job for this annotation

GitHub Actions / build-runner-image / build-container

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

Check warning on line 3 in containers/cmake.Dockerfile

View workflow job for this annotation

GitHub Actions / build-runner-image / build-container

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

Check warning on line 3 in containers/cmake.Dockerfile

View workflow job for this annotation

GitHub Actions / build-runner-image / build-container

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

Check warning on line 3 in containers/cmake.Dockerfile

View workflow job for this annotation

GitHub Actions / build-runner-image / build-container

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

Check warning on line 3 in containers/cmake.Dockerfile

View workflow job for this annotation

GitHub Actions / build-runner-image / build-container

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

Check warning on line 3 in containers/cmake.Dockerfile

View workflow job for this annotation

GitHub Actions / build-runner-image / build-container

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

ARG CMAKE_REVISION

ENV CMAKE_REVISION=${CMAKE_REVISION:-v3.16.3}

ADD https://github.com/Kitware/CMake.git#${CMAKE_REVISION} /cmake


FROM cmake-builder AS cmake

Expand All @@ -16,19 +25,14 @@ RUN --mount=type=cache,sharing=locked,target=/var/cache/apt \
wget && \
rm -rf /var/lib/apt/lists/*

WORKDIR /tmp
ADD https://github.com/Kitware/CMake.git#${CMAKE_REVISION} /tmp/cmake

WORKDIR /tmp/cmake
RUN ./bootstrap && \
WORKDIR /cmake
RUN --mount=type=bind,rw,from=clone,source=/cmake,target=/cmake \
./bootstrap && \
[ -z "$CMAKE_BUILD_NTHREADS" ] && \
{ make -j $(nproc --all); } || \
{ make -j ${CMAKE_BUILD_NTHREADS}; } && \
make install

WORKDIR /tmp
RUN rm -rf cmake

WORKDIR /
RUN ( [ -f "VERSION" ] || touch VERSION ) && \
echo "CMake => ${CMAKE_REVISION}\n" >> VERSION
2 changes: 1 addition & 1 deletion containers/dmriqcpy.context/dmriqcpy.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# syntax=docker.io/docker/dockerfile:1.6.0
# syntax=docker.io/docker/dockerfile:1.10.0

FROM dmriqcpy-base as dmriqcpy

Expand Down
2 changes: 1 addition & 1 deletion containers/fsl.context/fsl.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# syntax=docker.io/docker/dockerfile:1.6.0
# syntax=docker.io/docker/dockerfile:1.10.0

FROM fsl-builder as fsl

Expand Down
2 changes: 1 addition & 1 deletion containers/mrtrix.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# syntax=docker.io/docker/dockerfile:1.6.0
# syntax=docker.io/docker/dockerfile:1.10.0

FROM mrtrix-builder as mrtrix

Expand Down
Loading

0 comments on commit 014a9fb

Please sign in to comment.