diff --git a/.github/workflows/docker-ort-haskell.yml b/.github/workflows/docker-ort-haskell.yml new file mode 100644 index 0000000000000..db9077e99d93b --- /dev/null +++ b/.github/workflows/docker-ort-haskell.yml @@ -0,0 +1,91 @@ +# Copyright (C) 2023 The ORT Project Authors (see ) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# License-Filename: LICENSE + +name: Ort Docker Haskell Container + +on: + workflow_dispatch: + pull_request: + branches: + - main + push: + paths: + - '.ortversions/haskell.versions' + - '.github/workflows/docker-ort-base.yml' + workflow_run: + workflows: ["Ort Docker Base Image"] + types: + - completed + +env: + REGISTRY: ghcr.io + +permissions: write-all + +jobs: + build: + name: Build ORT Haskell Image + runs-on: ubuntu-22.04 + permissions: + contents: read + packages: write + + steps: + - name: Checkout main repository + uses: actions/checkout@v3 + + - name: Set environment variables + run: | + cat .ortversions/haskell.versions >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract components metadata (tags, labels) for base image + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ env.REGISTRY }}/${{ github.repository }}/haskell + tags: | + type=semver,pattern={{version}},value=${{ env.HASKELL_STACK_VERSION }} + + + - name: Build ORT Haskell container + uses: docker/build-push-action@v4 + with: + context: . + target: haskell + push: true + load: false + build-args: | + HASKELL_STACK_VERSION=${{ env.HASKELL_STACK_VERSION }} + tags: | + ${{ steps.meta.outputs.tags }} + ${{ env.REGISTRY }}/${{ github.repository }}/haskell:latest + labels: ${{ steps.meta.outputs.labels }} + build-contexts: | + ort-base-image=docker-image://${{ env.REGISTRY }}/${{ github.repository }}/base:latest + cache-from: type=gha,scope=orthaskell + cache-to: type=gha,scope=orthaskell,mode=max diff --git a/.ortversions/haskell.versions b/.ortversions/haskell.versions new file mode 100644 index 0000000000000..9e794390d449f --- /dev/null +++ b/.ortversions/haskell.versions @@ -0,0 +1 @@ +HASKELL_STACK_VERSION=2.7.5 \ No newline at end of file diff --git a/scripts/docker_build.sh b/scripts/docker_build.sh index b91c9acd317e9..ade18b5b4f4e5 100755 --- a/scripts/docker_build.sh +++ b/scripts/docker_build.sh @@ -20,7 +20,7 @@ set -e -o pipefail GIT_ROOT=$(git rev-parse --show-toplevel) -GIT_REVISION=$("$GIT_ROOT/gradlew" -q properties --property version | grep -oP "version: \K.+") +GIT_REVISION=$("$GIT_ROOT/gradlew" -q properties --property version | grep "version" | sed -e "s/version: //") DOCKER_IMAGE_ROOT="${DOCKER_IMAGE_ROOT:-ghcr.io/oss-review-toolkit}" echo "Setting ORT_VERSION to $GIT_REVISION." @@ -159,3 +159,10 @@ image_build dotnet dotnet "$DOTNET_VERSION" \ --build-arg DOTNET_VERSION="$DOTNET_VERSION" \ --build-arg NUGET_INSPECTOR_VERSION="$NUGET_INSPECTOR_VERSION" \ "$@" + +# Dotnet +# shellcheck disable=SC1091 +. .ortversions/haskell.versions +image_build dotnet dotnet "$HASKELL_STACK_VERSION" \ + --build-arg HASKELL_STACK_VERSION="$HASKELL_STACK_VERSION" \ + "$@" diff --git a/scripts/docker_snippets/haskell.snippet b/scripts/docker_snippets/haskell.snippet new file mode 100644 index 0000000000000..b974d2937c661 --- /dev/null +++ b/scripts/docker_snippets/haskell.snippet @@ -0,0 +1,32 @@ +# Copyright (C) 2023 The ORT Project Authors (see ) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# License-Filename: LICENSE + +ARG HASKELL_STACK_VERSION=2.7.5 +ENV HASKELL_HOME=/opt/haskell +ENV PATH=$PATH:$HASKELL_HOME/bin + +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + sudo apt-get update -qq \ + && DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-recommends \ + zlib1g-dev \ + && sudo rm -rf /var/lib/apt/lists/* + +RUN curl -sSL https://get.haskellstack.org/ | bash -s -- -d $HASKELL_HOME/bin + +FROM scratch AS haskell +COPY --from=haskellbuild /opt/haskell /opt/haskell \ No newline at end of file