Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: true
matrix:
image: ["buildah", "finish", "go-toolset", "gradle-toolset", "helm", "sonar", "start", "pipeline-manager", "python-toolset", "node16-npm-toolset"]
image: ["buildah", "finish", "go-toolset", "gradle-toolset", "helm", "sonar", "start", "pipeline-manager", "python-toolset", "node16-npm-toolset", "sbt-toolset"]
steps:
-
name: Checkout
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
runs-on: ubuntu-latest
needs: build-images
env:
IMAGES: buildah finish go-toolset gradle-toolset helm sonar start pipeline-manager python-toolset node16-npm-toolset
IMAGES: buildah finish go-toolset gradle-toolset helm sonar start pipeline-manager python-toolset node16-npm-toolset sbt-toolset
steps:
-
name: Download image artifacts
Expand Down
53 changes: 53 additions & 0 deletions build/package/Dockerfile.sbt-toolset
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
FROM registry.access.redhat.com/ubi8/openjdk-11:1.14

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

ARG SBT_VERSION=1.7.2
ARG SBT_SHA256=e9e3814b2a5a83734d02bf8f1dd8ac285620e601e2f9b1c0fa18c8b38d0dabe3

ENV LANG=en_US.UTF-8 \
LC_ALL=en_US.UTF-8 \
HOME=/home/jboss \
COURSIER_CACHE=/home/jboss/.cache/coursier/v1

USER root

COPY build/package/files/sbt/test /tmp/sbttest

RUN microdnf install --nodocs openssl-${OPENSSL_VERSION}* git-${GIT_VERSION}* vim unzip && microdnf clean all

RUN SBT_INSTALL_DIR=/tmp/sbt-install && \
mkdir -p $SBT_INSTALL_DIR && \
cd $SBT_INSTALL_DIR && \
curl -LO https://github.com/sbt/sbt/releases/download/v${SBT_VERSION}/sbt-${SBT_VERSION}.zip && \
echo $SBT_SHA256 sbt-${SBT_VERSION}.zip | sha256sum -c - && \
unzip -d /opt sbt-${SBT_VERSION}.zip && \
ln -s /opt/sbt/bin/sbt /usr/local/bin/sbt && \
rm -rf $SBT_INSTALL_DIR

COPY build/package/files/sbt/sbtopts /opt/sbt/conf/sbtopts
# Add scripts
COPY build/package/scripts/cache-build.sh /usr/local/bin/cache-build
COPY build/package/scripts/copy-build-if-cached.sh /usr/local/bin/copy-build-if-cached
COPY build/package/scripts/copy-artifacts.sh /usr/local/bin/copy-artifacts
COPY build/package/scripts/build-sbt.sh /usr/local/bin/build-sbt
COPY build/package/scripts/supply-sonar-project-properties-default.sh /usr/local/bin/supply-sonar-project-properties-default

# Add sonar-project.properties
COPY build/package/sonar-project.properties.d/sbt.properties /usr/local/default-sonar-project.properties

# TODO set sbt http proxy COPY build/package/scripts/set-sbt-proxy.sh /usr/local/bin/set-sbt-proxy
RUN cd /tmp/sbttest && \
sbt 'set scalaVersion := "2.12.16"' compile && \
sbt 'set scalaVersion := "2.13.10"' compile && \
rm -rf /tmp/sbttest && \
chmod +x /usr/local/bin/build-sbt && \
chmod +x /usr/local/bin/cache-build && \
chmod +x /usr/local/bin/copy-build-if-cached && \
chmod +x /usr/local/bin/copy-artifacts && \
chmod +x /usr/local/bin/supply-sonar-project-properties-default && \
chown -R 1001:0 /home/jboss && \
chown -R 1001:0 /tmp/.sbt
# TODO set sbt http proxy chmod +x /usr/local/bin/set-sbt-proxy # TODO set sbt http proxy

USER 1001
49 changes: 49 additions & 0 deletions build/package/files/sbt/sbtopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# ------------------------------------------------ #
# The SBT Configuration file. #
# ------------------------------------------------ #


# Disable ANSI color codes
#
-no-colors

# Starts sbt even if the current directory contains no sbt project.
#
-sbt-create

# Path to global settings/plugins directory (default: ~/.sbt)
#
-sbt-dir /home/jboss/.sbt

# Path to shared boot directory (default: ~/.sbt/boot in 0.11 series)
#
-sbt-boot /home/jboss/.sbt/boot

# Path to local Ivy repository (default: ~/.ivy2)
#
-ivy /home/jboss/.ivy2

# set memory options
#
#-mem <integer>

# Use local caches for projects, no sharing.
#
#-no-share

# Put SBT in offline mode.
#
#-offline

# Sets the SBT version to use.
#-sbt-version 0.11.3

# Scala version (default: latest release)
#
#-scala-home <path>
#-scala-version <version>

# java version (default: java from PATH, currently $(java -version |& grep version))
#
#-java-home <path>
-Duser.home=/home/jboss
3 changes: 3 additions & 0 deletions build/package/files/sbt/test/test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Test {
val x = "nothing here"
}
78 changes: 78 additions & 0 deletions build/package/scripts/build-sbt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash
set -eu

function timestamped() {
echo "$(date "+%Y/%m/%d %H:%M:%S") $1"
}

OUTPUT_DIR="docker"
WORKING_DIR="."
ROOT_DIR=$(pwd)
export ARTIFACTS_DIR=$ROOT_DIR/.ods/artifacts

# might be needed for several task executions that would publish to the same artefact path...
ARTIFACT_PREFIX=
DEBUG="${DEBUG:-false}"

while [[ "$#" -gt 0 ]]; do
case $1 in

--working-dir) WORKING_DIR="$2"; shift;;
--working-dir=*) WORKING_DIR="${1#*=}";;

--output-dir) OUTPUT_DIR="$2"; shift;;
--output-dir=*) OUTPUT_DIR="${1#*=}";;

*) echo "Unknown parameter passed: $1"; exit 1;;
esac; shift; done

if [ "${WORKING_DIR}" != "." ]; then
WORKING_DIR="${ROOT_DIR}"
ARTIFACT_PREFIX="${WORKING_DIR/\//-}-"
fi

if [ "${DEBUG}" == "true" ]; then
set -x
fi

echo "Using NEXUS_URL=$NEXUS_URL"
echo "Using ARTIFACTS_DIR=$ARTIFACTS_DIR"

echo
cd "${WORKING_DIR}"
echo "Working on SBT project in '${WORKING_DIR}'..."
echo
export ODS_OUTPUT_DIR=${OUTPUT_DIR}
echo "Exported env var 'ODS_OUTPUT_DIR' with value '${OUTPUT_DIR}'"
echo
echo "Building (Compile and Test) ..."
# shellcheck disable=SC2086

# check format of sbt and source files, activate coverage and test with coverage report
timestamped "run tests and coverage"
UNIT_TEST_ARTIFACTS_DIR="${ARTIFACTS_DIR}/xunit-reports"
CODE_COVERAGE_ARTIFACTS_DIR="${ARTIFACTS_DIR}/code-coverage"
export UNIT_TEST_RESULT_DIR="${UNIT_TEST_ARTIFACTS_DIR}/${ARTIFACT_PREFIX}"
export CODE_COVERAGE_TARGET_FILE="${CODE_COVERAGE_ARTIFACTS_DIR}/${ARTIFACT_PREFIX}scoverage.xml"
sbt -no-colors -v clean scalafmtSbtCheck scalafmtCheckAll coverage test coverageReport copyOdsReports clean stage

timestamped "Verifying unit test report was generated ..."
if ls "${UNIT_TEST_RESULT_DIR}"*.xml >/dev/null 2>&1 ; then
timestamped "unit test results exist under ${UNIT_TEST_RESULT_DIR}"
else
timestamped "Build failed: no unit test results found in ${UNIT_TEST_RESULT_DIR}"
exit 1
fi

timestamped "Verifying unit test coverage report was generated ..."
if [ -f "${CODE_COVERAGE_TARGET_FILE}" ]; then
timestamped "unit test coverage report was found at ${CODE_COVERAGE_TARGET_FILE}"
else
timestamped "Build failed: no unit test coverage report was found at ${CODE_COVERAGE_TARGET_FILE}"
exit 1
fi

BUILD_DIR="target"
STAGING_DIR="${BUILD_DIR}/universal/stage"
timestamped "Copying contents of ${STAGING_DIR} to ${OUTPUT_DIR}/dist ..."
cp -r "${STAGING_DIR}/." "${OUTPUT_DIR}/dist"
5 changes: 5 additions & 0 deletions build/package/sonar-project.properties.d/sbt.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# this is just a fallback sonar properties. A matching one should be provided by each project
sonar.sources=src
sonar.sourceEncoding=UTF-8
sonar.scala.version=2.13
sonar.scala.scapegoat.disable=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{if or .Values.global.enabledTasks.buildSbt .Values.sbtToolset}}
kind: BuildConfig
apiVersion: build.openshift.io/v1
metadata:
name: ods-sbt-toolset
labels:
{{- include "chart.labels" . | nindent 4}}
spec:
nodeSelector: null
output:
to:
kind: ImageStreamTag
name: 'ods-sbt-toolset:{{.Values.global.imageTag | default .Chart.AppVersion}}'
resources: {}
successfulBuildsHistoryLimit: 5
failedBuildsHistoryLimit: 5
postCommit: {}
strategy:
type: Docker
dockerStrategy:
buildArgs:
- name: imageTag
value: '{{.Values.global.imageTag | default .Chart.AppVersion}}'
- name: privateCertServer
value: '{{.Values.privateCertServer}}'
source:
dockerfile: |-
{{- .Files.Get "docker/Dockerfile.sbt-toolset" | nindent 6}}
runPolicy: Serial
{{end}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{if or .Values.global.enabledTasks.buildSbt .Values.sbtToolset}}
apiVersion: image.openshift.io/v1
kind: ImageStream
metadata:
name: ods-sbt-toolset
labels:
{{- include "chart.labels" . | nindent 4}}
annotations:
"helm.sh/resource-policy": keep
{{end}}
122 changes: 122 additions & 0 deletions deploy/ods-pipeline/charts/tasks/templates/task-ods-build-sbt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{{if .Values.global.enabledTasks.buildSbt }}
apiVersion: tekton.dev/v1beta1
kind: '{{default "Task" .Values.global.taskKind}}'
metadata:
name: '{{default "ods" .Values.taskPrefix}}-build-sbt{{- include "taskSuffix" .}}'
annotations:
"helm.sh/resource-policy": keep
spec:
description: |
sbt build - TBD
params:
- name: working-dir
description: |
Working directory. The path must be relative to the root of the repository,
without leading `./` and trailing `/`.
type: string
default: "."
- name: output-dir
description: >-
Path to the directory into which the resulting build artifact should be copied, relative to `working-dir`.
This directory may then later be used as Docker context for example.
type: string
default: docker
- name: cache-build
description: >-
If enabled tasks uses or populates cache with the output dir contents (and artifacts) so that
a build can be skipped if the `working-dir` contents did not change.
For single build repos enabling build caching has limited benefits. For multi build repos enabling this is recommended unless the build is dependant on files outside of the working directory. See ADR caching-build-tasks for more details and workarounds.
type: string
default: "false"
- name: build-script
description: >-
Build script to execute. The
link:https://github.com/opendevstack/ods-pipeline/blob/master/build/package/scripts/build-sbt.sh[default script]
is located in the container image. If you specify a relative path
instead, it will be resolved from the workspace. See the task definition
for details how the build script is invoked.
type: string
default: "/usr/local/bin/build-sbt"
- name: sonar-quality-gate
description: Whether the SonarQube quality gate needs to pass for the task to succeed.
type: string
default: "false"
- name: sonar-skip
description: Whether to skip SonarQube analysis or not.
type: string
default: "false"
results:
- description: The cache location that the build task used. If caching is not enabled this will be an empty string.
name: build-reused-from-location
{{- with ((.Values.sbt).sidecars) }}
sidecars:
{{- toYaml . | nindent 4 }}
{{- end }}
steps:
- name: build-sbt-binary
# Image is built from build/package/Dockerfile.sbt-toolset.
image: '{{.Values.registry}}/{{default .Release.Namespace .Values.namespace}}/ods-sbt-toolset:{{.Values.global.imageTag | default .Chart.AppVersion}}'
env:
- name: DEBUG
valueFrom:
configMapKeyRef:
key: debug
name: ods-pipeline
- name: HOME
value: '/tekton/home'
- name: CI
value: "true"
- name: NEXUS_URL
valueFrom:
configMapKeyRef:
key: url
name: ods-nexus
- name: NEXUS_USERNAME
valueFrom:
secretKeyRef:
key: username
name: ods-nexus-auth
- name: NEXUS_PASSWORD
valueFrom:
secretKeyRef:
key: password
name: ods-nexus-auth
resources:
{{- (.Values.sbt).resources | default dict | toYaml | nindent 8 }}
script: |
supply-sonar-project-properties-default
echo -n "" > $(results.build-reused-from-location.path)
cache_build_key=sbt
if copy-build-if-cached \
--cache-build=$(params.cache-build) \
--cache-build-key="$cache_build_key" \
--cache-location-used-path=$(results.build-reused-from-location.path) \
--working-dir=$(params.working-dir) \
--output-dir=$(params.output-dir) \
--debug=${DEBUG} ; then
exit 0
fi
# Default build script is build/package/scripts/build-sbt.sh.
set +e
$(params.build-script) \
--working-dir=$(params.working-dir) \
--output-dir=$(params.output-dir)
build_exit=$?
set -e
copy-artifacts --debug=${DEBUG}
if [ $build_exit -ne 0 ]; then
exit $build_exit
fi
if [ "$(params.cache-build)" == "true" ]; then
cache-build \
--cache-build-key="$cache_build_key" \
--cache-location-used-path=$(results.build-reused-from-location.path) \
--working-dir=$(params.working-dir) \
--output-dir=$(params.output-dir) \
--debug=${DEBUG}
fi
workingDir: $(workspaces.source.path)
{{- include "sonar-step" . | indent 4}}
workspaces:
- name: source
{{end}}
1 change: 1 addition & 0 deletions deploy/ods-pipeline/charts/tasks/values.docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ global:
buildGradle: true
buildPython: true
buildNPM: true
buildSbt: true
packageImage: true
deployHelm: true

Expand Down
1 change: 1 addition & 0 deletions deploy/ods-pipeline/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ global:
buildGradle: true
buildPython: true
buildNPM: true
buildSbt: true
packageImage: true
deployHelm: true

Expand Down
Loading