Skip to content

Commit

Permalink
feat(docker): Add Haskell component
Browse files Browse the repository at this point in the history
Signed-off-by: Helio Chissini de Castro <[email protected]>
  • Loading branch information
heliocastro committed Sep 7, 2023
1 parent c685174 commit 0f4dc25
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 1 deletion.
91 changes: 91 additions & 0 deletions .github/workflows/docker-ort-haskell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright (C) 2023 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>)
#
# 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
1 change: 1 addition & 0 deletions .ortversions/haskell.versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HASKELL_STACK_VERSION=2.7.5
9 changes: 8 additions & 1 deletion scripts/docker_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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" \
"$@"
32 changes: 32 additions & 0 deletions scripts/docker_snippets/haskell.snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (C) 2023 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>)
#
# 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

0 comments on commit 0f4dc25

Please sign in to comment.