Skip to content

Commit

Permalink
Merge pull request #518 from codacy/infra/add-support-for-linux-arm
Browse files Browse the repository at this point in the history
i
  • Loading branch information
CallMeLeopoldo authored Feb 18, 2025
2 parents 5568545 + e408fec commit 5ba2277
Showing 4 changed files with 286 additions and 9 deletions.
207 changes: 207 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -97,6 +97,8 @@ jobs:
mkdir -p ~/workdir/artifacts/
mv ~/workdir/tmp-artifacts/codacy-coverage-reporter-assembly.jar ~/workdir/artifacts/codacy-coverage-reporter-assembly.jar
upx --lzma -o ~/workdir/artifacts/codacy-coverage-reporter-linux ~/workdir/tmp-artifacts/codacy-coverage-reporter-linux
mv ~/workdir/tmp-artifacts/codacy-coverage-reporter-linux-arm-assembly.jar ~/workdir/artifacts/codacy-coverage-reporter-linux-arm-assembly.jar
upx --lzma -o ~/workdir/artifacts/codacy-coverage-reporter-linux-arm ~/workdir/tmp-artifacts/codacy-coverage-reporter-linux-arm
# upx binaries don't work on Mac OS Big Sur https://github.com/upx/upx/issues/424
# use upx again once the bug is fixed
# upx --lzma -o ~/workdir/artifacts/codacy-coverage-reporter-darwin ~/workdir/tmp-artifacts/codacy-coverage-reporter-darwin
@@ -164,6 +166,8 @@ jobs:
name: prepare the environment
command: |
brew install mockserver coreutils
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
export CODACY_REPORTER_TMP_FOLDER=".codacy-coverage"
version=$(cat .version)
mkdir -p $CODACY_REPORTER_TMP_FOLDER/$version
@@ -188,6 +192,201 @@ jobs:
if [ $ERROR_CODE -ne 0 ]; then echo "expected an error code 0 and got $ERROR_CODE instead"; exit 1; fi
echo "test completed with the expected error code: 0"
it_coverage_script_ubuntu_linux_arm:
resource_class: arm.medium
docker:
- image: cimg/base:2023.10 # ubuntu based image
- image: mockserver/mockserver:5.15.0
working_directory: ~/workdir
steps:
- attach_workspace:
at: ~/workdir
create_artifacts_linux_arm:
description: Default sbt job
environment:
AWS_DEFAULT_REGION: << parameters.region >>
AWS_PROFILE: << parameters.aws_profile >>
machine:
image: ubuntu-2204:current
resource_class: arm.medium
parameters:
aws_profile:
default: default
description: The AWS profile to be used
type: string
cache_prefix:
default: sbt-cache-032020
description: The prefix of cache to be used
type: string
cmd:
default: ''
description: SBT command to run
type: string
credentials_file_content:
default: >
[default]
aws_access_key_id=$ACCESS_KEY_ID
aws_secret_access_key=$SECRET_ACCESS_KEY
[maven]
source_profile = default
role_arn =
arn:aws:iam::$AWS_ACCOUNT_ID_PRODUCTION:role/$MAVEN_PUBLISHER_ROLE
description: AWS credentials file contents to grant access for the step
type: string
docker_scout_version:
default: 0.13.1
description: Version of the docker scout plugin to use
type: string
install_sbt_version:
default: ''
description: >-
Version of SBT to install. Ensure compatibility with openjdk_version. If
empty, the system one will be used
type: string
no_output_timeout:
default: 15m
description: The time to wait for the command without output
type: string
openjdk_version:
default: '11'
description: >-
OpenJDK major version to install. Ensure compatibility with
install_sbt_version. If empty, the system one will be used
type: string
persist_to_workspace:
default: true
description: Whether to persist the workspace or not at the end of the job
type: boolean
region:
default: eu-west-1
description: The AWS region for the deployment
type: string
save_cache:
default: true
description: Whether to save the cache or not at the end of the job
type: boolean
setup_docker_scout:
default: false
description: >-
Install and setup docker scout plugin to scan for docker image
vulnerabilities
type: boolean
steps:
default: [ ]
description: Steps to run
type: steps
steps_before_sbt:
default: [ ]
description: Steps to run before sbt starts
type: steps
store_test_results:
default: false
description: Whether to upload the test results back to CircleCI
type: boolean
use_sbt_native_client:
default: false
description: Use the sbt thin client
type: boolean
steps:
- checkout
- attach_workspace:
at: ~/workdir
- when:
condition: << parameters.openjdk_version >>
steps:
- run:
command: >
sudo apt update
sudo apt install openjdk-${OJDK_VERSION}-jre
sudo update-alternatives --set java
/usr/lib/jvm/java-${OJDK_VERSION}-openjdk-arm64/bin/java
environment:
OJDK_VERSION: << parameters.openjdk_version >>
name: Install openjdk << parameters.openjdk_version >>
- when:
condition: << parameters.install_sbt_version >>
steps:
- run:
command: >
# remove pre-installed sbt
sudo rm -rf /opt/sbt/
wget https://repo.scala-sbt.org/scalasbt/debian/sbt-<<
parameters.install_sbt_version >>.deb
sudo dpkg -i sbt-<< parameters.install_sbt_version >>.deb
rm -f sbt-<< parameters.install_sbt_version >>.deb
name: Install sbt << parameters.install_sbt_version >>
- when:
condition: << parameters.setup_docker_scout >>
steps:
- run:
command: >
curl -L https://github.com/docker/scout-cli/releases/download/v<<
parameters.docker_scout_version >>/docker-scout_<<
parameters.docker_scout_version >>_linux_amd64.tar.gz -o
docker-scout.tar.gz
mkdir -p $HOME/.docker/cli-plugins
tar -xvzf docker-scout.tar.gz -C $HOME/.docker/cli-plugins
chmod +x $HOME/.docker/cli-plugins/docker-scout
name: >-
Download and install docker scout <<
parameters.docker_scout_version >>
- run:
command: |
mkdir -p ~/.aws && touch ~/.aws/credentials
cat >> ~/.aws/credentials \<< EOF
<< parameters.credentials_file_content >>
EOF
name: Setup AWS Credentials
- run:
command: |
if [[ -f "targets.tar.gz" ]]; then
echo "unpacking persisted workspace" && tar -xf targets.tar.gz
else
echo "no persisted workspace found"
fi
name: Uncompress local targets
- run:
command: |
ARCH="arm" graalvm/build-deps.sh
export PATH=$HOME/.musl/arm-linux-musleabi-native/bin:$PATH
sbt "assembly;nativeImage"
mkdir -p ~/workdir/tmp-artifacts
mv target/native-image/codacy-coverage-reporter ~/workdir/tmp-artifacts/codacy-coverage-reporter-linux-arm
ls -al target
mv target/codacy-coverage-reporter-assembly-0.1.0-SNAPSHOT.jar ~/workdir/tmp-artifacts/codacy-coverage-reporter-linux-arm-assembly.jar
ls -al ~/workdir/tmp-artifacts
name: Generate binaries for Linux ARM
- when:
condition: << parameters.persist_to_workspace >>
steps:
- run:
command: >
find -name target -type d -exec tar -zcf targets.tar.gz -H posix
{} + | true
find -name target -type d -exec rm -rf {} + | true
name: Compressing targets
- persist_to_workspace:
paths:
- 'tmp-artifacts'
root: ~/workdir

workflows:
compile_test_deploy:
jobs:
@@ -265,10 +464,14 @@ workflows:
persist_to_workspace_path: "tmp-artifacts/codacy-coverage-reporter-darwin"
requires:
- compile_and_test
- create_artifacts_linux_arm:
requires:
- compile_and_test
- package_artifacts:
requires:
- create_artifacts
- create_artifacts_for_osx
- create_artifacts_linux_arm
- codacy/shell:
name: generate_checksums
cmd: |
@@ -284,6 +487,10 @@ workflows:
- it_coverage_script_macosx:
requires:
- package_artifacts
- it_coverage_script_ubuntu_linux_arm:
name: it_coverage_script_ubuntu_linux_arm
requires:
- package_artifacts
- it_coverage_script_alpine:
requires:
- package_artifacts
7 changes: 5 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -51,8 +51,10 @@ enablePlugins(NativeImagePlugin)
nativeImageVersion := "22.3.0"

val osSpecificOptions =
if (sys.props("os.name") == "Mac OS X") Seq.empty[String]
else Seq("--static", "--libc=musl")
(Platform.os, Platform.arch) match {
case (Platform.OS.Linux, Platform.Arch.Intel) => Seq("--static", "--libc=musl")
case _ => Seq.empty[String]
}

nativeImageOptions := Seq(
"--verbose",
@@ -62,6 +64,7 @@ nativeImageOptions := Seq(
"--enable-url-protocols=http,https,jar",
"--enable-all-security-services",
"-H:+JNI",
"-H:-CheckToolchain",
"-H:IncludeResourceBundles=com.sun.org.apache.xerces.internal.impl.msg.XMLMessages",
"-H:+ReportExceptionStackTraces",
"--no-fallback",
24 changes: 17 additions & 7 deletions graalvm/build-deps.sh
Original file line number Diff line number Diff line change
@@ -2,13 +2,23 @@

set -e +o pipefail

mkdir -p $HOME/.musl
cd $HOME/.musl
if [ "$ARCH" == "arm" ];
then
mkdir -p $HOME/.gcc
cd $HOME/.gcc
curl https://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz --output gcc.tgz
tar -xf gcc.tgz
TOOLCHAIN_DIR=$HOME/.gcc/gcc-11.2.0
else
mkdir -p $HOME/.musl
cd $HOME/.musl
echo "http://more.musl.cc/10/x86_64-linux-musl/x86_64-linux-musl-native.tgz --output musl.tgz"
curl http://more.musl.cc/10/x86_64-linux-musl/x86_64-linux-musl-native.tgz --output musl.tgz
tar -xf musl.tgz
TOOLCHAIN_DIR=$HOME/.musl/x86_64-linux-musl-native
export CC=$TOOLCHAIN_DIR/bin/gcc
fi

curl http://more.musl.cc/10/x86_64-linux-musl/x86_64-linux-musl-native.tgz --output musl.tgz
tar -xf musl.tgz
TOOLCHAIN_DIR=$HOME/.musl/x86_64-linux-musl-native
export CC=$TOOLCHAIN_DIR/bin/gcc

zlib='zlib-1.2.13'
zlibtargz=$zlib.tar.gz
@@ -22,4 +32,4 @@ tar -xf $zlibtargz
sudo make install
)

echo "$TOOLCHAIN_DIR/bin"
echo "$TOOLCHAIN_DIR/bin"
57 changes: 57 additions & 0 deletions project/Platform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
object Platform {
sealed abstract class OS(val string: String) extends Product with Serializable

object OS {
case object Windows extends OS("windows")
case object MacOS extends OS("osx")
case object Linux extends OS("linux")
case object Unknown extends OS("unknown")

val all: List[OS] = List(Windows, MacOS, Linux, Unknown)

def detect(osNameProp: String): OS = normalise(osNameProp) match {
case p if p.startsWith("linux") => OS.Linux
case p if p.startsWith("windows") => OS.Windows
case p if p.startsWith("osx") || p.startsWith("macosx") => OS.MacOS
case _ => OS.Unknown
}
}

sealed abstract class Arch extends Product with Serializable {}

object Arch {
case object Intel extends Arch {}
case object Arm extends Arch {}

val all: List[Arch] = List(Intel, Arm)

def detect(osArchProp: String): Arch = normalise(osArchProp) match {
case "amd64" | "x64" | "x8664" | "x86" => Intel
case "aarch64" | "arm64" => Arm
}
}

sealed abstract class Bits extends Product with Serializable

object Bits {
case object x32 extends Bits
case object x64 extends Bits

def detect(sunArchProp: String): Bits =
sunArchProp match {
case "64" => x64
case "32" => x32
}
}

case class Target(os: OS, arch: Arch, bits: Bits)

lazy val os: OS = OS.detect(sys.props.getOrElse("os.name", ""))
lazy val arch: Arch = Arch.detect(sys.props.getOrElse("os.arch", ""))
lazy val bits: Bits = Bits.detect(sys.props.getOrElse("sun.arch.data.model", ""))
lazy val target: Target = Target(os, arch, bits)

private def normalise(s: String) =
s.toLowerCase(java.util.Locale.US).replaceAll("[^a-z0-9]+", "")

}

0 comments on commit 5ba2277

Please sign in to comment.