Skip to content

Commit 5ba2277

Browse files
Merge pull request #518 from codacy/infra/add-support-for-linux-arm
i
2 parents 5568545 + e408fec commit 5ba2277

File tree

4 files changed

+286
-9
lines changed

4 files changed

+286
-9
lines changed

.circleci/config.yml

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ jobs:
9797
mkdir -p ~/workdir/artifacts/
9898
mv ~/workdir/tmp-artifacts/codacy-coverage-reporter-assembly.jar ~/workdir/artifacts/codacy-coverage-reporter-assembly.jar
9999
upx --lzma -o ~/workdir/artifacts/codacy-coverage-reporter-linux ~/workdir/tmp-artifacts/codacy-coverage-reporter-linux
100+
mv ~/workdir/tmp-artifacts/codacy-coverage-reporter-linux-arm-assembly.jar ~/workdir/artifacts/codacy-coverage-reporter-linux-arm-assembly.jar
101+
upx --lzma -o ~/workdir/artifacts/codacy-coverage-reporter-linux-arm ~/workdir/tmp-artifacts/codacy-coverage-reporter-linux-arm
100102
# upx binaries don't work on Mac OS Big Sur https://github.com/upx/upx/issues/424
101103
# use upx again once the bug is fixed
102104
# upx --lzma -o ~/workdir/artifacts/codacy-coverage-reporter-darwin ~/workdir/tmp-artifacts/codacy-coverage-reporter-darwin
@@ -164,6 +166,8 @@ jobs:
164166
name: prepare the environment
165167
command: |
166168
brew install mockserver coreutils
169+
sudo rm -rf /Library/Developer/CommandLineTools
170+
sudo xcode-select --install
167171
export CODACY_REPORTER_TMP_FOLDER=".codacy-coverage"
168172
version=$(cat .version)
169173
mkdir -p $CODACY_REPORTER_TMP_FOLDER/$version
@@ -188,6 +192,201 @@ jobs:
188192
if [ $ERROR_CODE -ne 0 ]; then echo "expected an error code 0 and got $ERROR_CODE instead"; exit 1; fi
189193
echo "test completed with the expected error code: 0"
190194
195+
196+
197+
it_coverage_script_ubuntu_linux_arm:
198+
resource_class: arm.medium
199+
docker:
200+
- image: cimg/base:2023.10 # ubuntu based image
201+
- image: mockserver/mockserver:5.15.0
202+
working_directory: ~/workdir
203+
steps:
204+
- attach_workspace:
205+
at: ~/workdir
206+
create_artifacts_linux_arm:
207+
description: Default sbt job
208+
environment:
209+
AWS_DEFAULT_REGION: << parameters.region >>
210+
AWS_PROFILE: << parameters.aws_profile >>
211+
machine:
212+
image: ubuntu-2204:current
213+
resource_class: arm.medium
214+
parameters:
215+
aws_profile:
216+
default: default
217+
description: The AWS profile to be used
218+
type: string
219+
cache_prefix:
220+
default: sbt-cache-032020
221+
description: The prefix of cache to be used
222+
type: string
223+
cmd:
224+
default: ''
225+
description: SBT command to run
226+
type: string
227+
credentials_file_content:
228+
default: >
229+
[default]
230+
231+
aws_access_key_id=$ACCESS_KEY_ID
232+
233+
aws_secret_access_key=$SECRET_ACCESS_KEY
234+
235+
[maven]
236+
237+
source_profile = default
238+
239+
role_arn =
240+
arn:aws:iam::$AWS_ACCOUNT_ID_PRODUCTION:role/$MAVEN_PUBLISHER_ROLE
241+
description: AWS credentials file contents to grant access for the step
242+
type: string
243+
docker_scout_version:
244+
default: 0.13.1
245+
description: Version of the docker scout plugin to use
246+
type: string
247+
install_sbt_version:
248+
default: ''
249+
description: >-
250+
Version of SBT to install. Ensure compatibility with openjdk_version. If
251+
empty, the system one will be used
252+
type: string
253+
no_output_timeout:
254+
default: 15m
255+
description: The time to wait for the command without output
256+
type: string
257+
openjdk_version:
258+
default: '11'
259+
description: >-
260+
OpenJDK major version to install. Ensure compatibility with
261+
install_sbt_version. If empty, the system one will be used
262+
type: string
263+
persist_to_workspace:
264+
default: true
265+
description: Whether to persist the workspace or not at the end of the job
266+
type: boolean
267+
region:
268+
default: eu-west-1
269+
description: The AWS region for the deployment
270+
type: string
271+
save_cache:
272+
default: true
273+
description: Whether to save the cache or not at the end of the job
274+
type: boolean
275+
setup_docker_scout:
276+
default: false
277+
description: >-
278+
Install and setup docker scout plugin to scan for docker image
279+
vulnerabilities
280+
type: boolean
281+
steps:
282+
default: [ ]
283+
description: Steps to run
284+
type: steps
285+
steps_before_sbt:
286+
default: [ ]
287+
description: Steps to run before sbt starts
288+
type: steps
289+
store_test_results:
290+
default: false
291+
description: Whether to upload the test results back to CircleCI
292+
type: boolean
293+
use_sbt_native_client:
294+
default: false
295+
description: Use the sbt thin client
296+
type: boolean
297+
steps:
298+
- checkout
299+
- attach_workspace:
300+
at: ~/workdir
301+
- when:
302+
condition: << parameters.openjdk_version >>
303+
steps:
304+
- run:
305+
command: >
306+
sudo apt update
307+
308+
sudo apt install openjdk-${OJDK_VERSION}-jre
309+
310+
sudo update-alternatives --set java
311+
/usr/lib/jvm/java-${OJDK_VERSION}-openjdk-arm64/bin/java
312+
environment:
313+
OJDK_VERSION: << parameters.openjdk_version >>
314+
name: Install openjdk << parameters.openjdk_version >>
315+
- when:
316+
condition: << parameters.install_sbt_version >>
317+
steps:
318+
- run:
319+
command: >
320+
# remove pre-installed sbt
321+
322+
sudo rm -rf /opt/sbt/
323+
324+
wget https://repo.scala-sbt.org/scalasbt/debian/sbt-<<
325+
parameters.install_sbt_version >>.deb
326+
327+
sudo dpkg -i sbt-<< parameters.install_sbt_version >>.deb
328+
329+
rm -f sbt-<< parameters.install_sbt_version >>.deb
330+
name: Install sbt << parameters.install_sbt_version >>
331+
- when:
332+
condition: << parameters.setup_docker_scout >>
333+
steps:
334+
- run:
335+
command: >
336+
curl -L https://github.com/docker/scout-cli/releases/download/v<<
337+
parameters.docker_scout_version >>/docker-scout_<<
338+
parameters.docker_scout_version >>_linux_amd64.tar.gz -o
339+
docker-scout.tar.gz
340+
341+
mkdir -p $HOME/.docker/cli-plugins
342+
343+
tar -xvzf docker-scout.tar.gz -C $HOME/.docker/cli-plugins
344+
345+
chmod +x $HOME/.docker/cli-plugins/docker-scout
346+
name: >-
347+
Download and install docker scout <<
348+
parameters.docker_scout_version >>
349+
- run:
350+
command: |
351+
mkdir -p ~/.aws && touch ~/.aws/credentials
352+
cat >> ~/.aws/credentials \<< EOF
353+
<< parameters.credentials_file_content >>
354+
EOF
355+
name: Setup AWS Credentials
356+
- run:
357+
command: |
358+
if [[ -f "targets.tar.gz" ]]; then
359+
echo "unpacking persisted workspace" && tar -xf targets.tar.gz
360+
else
361+
echo "no persisted workspace found"
362+
fi
363+
name: Uncompress local targets
364+
- run:
365+
command: |
366+
ARCH="arm" graalvm/build-deps.sh
367+
export PATH=$HOME/.musl/arm-linux-musleabi-native/bin:$PATH
368+
sbt "assembly;nativeImage"
369+
mkdir -p ~/workdir/tmp-artifacts
370+
mv target/native-image/codacy-coverage-reporter ~/workdir/tmp-artifacts/codacy-coverage-reporter-linux-arm
371+
ls -al target
372+
mv target/codacy-coverage-reporter-assembly-0.1.0-SNAPSHOT.jar ~/workdir/tmp-artifacts/codacy-coverage-reporter-linux-arm-assembly.jar
373+
ls -al ~/workdir/tmp-artifacts
374+
name: Generate binaries for Linux ARM
375+
- when:
376+
condition: << parameters.persist_to_workspace >>
377+
steps:
378+
- run:
379+
command: >
380+
find -name target -type d -exec tar -zcf targets.tar.gz -H posix
381+
{} + | true
382+
383+
find -name target -type d -exec rm -rf {} + | true
384+
name: Compressing targets
385+
- persist_to_workspace:
386+
paths:
387+
- 'tmp-artifacts'
388+
root: ~/workdir
389+
191390
workflows:
192391
compile_test_deploy:
193392
jobs:
@@ -265,10 +464,14 @@ workflows:
265464
persist_to_workspace_path: "tmp-artifacts/codacy-coverage-reporter-darwin"
266465
requires:
267466
- compile_and_test
467+
- create_artifacts_linux_arm:
468+
requires:
469+
- compile_and_test
268470
- package_artifacts:
269471
requires:
270472
- create_artifacts
271473
- create_artifacts_for_osx
474+
- create_artifacts_linux_arm
272475
- codacy/shell:
273476
name: generate_checksums
274477
cmd: |
@@ -284,6 +487,10 @@ workflows:
284487
- it_coverage_script_macosx:
285488
requires:
286489
- package_artifacts
490+
- it_coverage_script_ubuntu_linux_arm:
491+
name: it_coverage_script_ubuntu_linux_arm
492+
requires:
493+
- package_artifacts
287494
- it_coverage_script_alpine:
288495
requires:
289496
- package_artifacts

build.sbt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ enablePlugins(NativeImagePlugin)
5151
nativeImageVersion := "22.3.0"
5252

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

5759
nativeImageOptions := Seq(
5860
"--verbose",
@@ -62,6 +64,7 @@ nativeImageOptions := Seq(
6264
"--enable-url-protocols=http,https,jar",
6365
"--enable-all-security-services",
6466
"-H:+JNI",
67+
"-H:-CheckToolchain",
6568
"-H:IncludeResourceBundles=com.sun.org.apache.xerces.internal.impl.msg.XMLMessages",
6669
"-H:+ReportExceptionStackTraces",
6770
"--no-fallback",

graalvm/build-deps.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22

33
set -e +o pipefail
44

5-
mkdir -p $HOME/.musl
6-
cd $HOME/.musl
5+
if [ "$ARCH" == "arm" ];
6+
then
7+
mkdir -p $HOME/.gcc
8+
cd $HOME/.gcc
9+
curl https://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz --output gcc.tgz
10+
tar -xf gcc.tgz
11+
TOOLCHAIN_DIR=$HOME/.gcc/gcc-11.2.0
12+
else
13+
mkdir -p $HOME/.musl
14+
cd $HOME/.musl
15+
echo "http://more.musl.cc/10/x86_64-linux-musl/x86_64-linux-musl-native.tgz --output musl.tgz"
16+
curl http://more.musl.cc/10/x86_64-linux-musl/x86_64-linux-musl-native.tgz --output musl.tgz
17+
tar -xf musl.tgz
18+
TOOLCHAIN_DIR=$HOME/.musl/x86_64-linux-musl-native
19+
export CC=$TOOLCHAIN_DIR/bin/gcc
20+
fi
721

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

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

25-
echo "$TOOLCHAIN_DIR/bin"
35+
echo "$TOOLCHAIN_DIR/bin"

project/Platform.scala

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
object Platform {
2+
sealed abstract class OS(val string: String) extends Product with Serializable
3+
4+
object OS {
5+
case object Windows extends OS("windows")
6+
case object MacOS extends OS("osx")
7+
case object Linux extends OS("linux")
8+
case object Unknown extends OS("unknown")
9+
10+
val all: List[OS] = List(Windows, MacOS, Linux, Unknown)
11+
12+
def detect(osNameProp: String): OS = normalise(osNameProp) match {
13+
case p if p.startsWith("linux") => OS.Linux
14+
case p if p.startsWith("windows") => OS.Windows
15+
case p if p.startsWith("osx") || p.startsWith("macosx") => OS.MacOS
16+
case _ => OS.Unknown
17+
}
18+
}
19+
20+
sealed abstract class Arch extends Product with Serializable {}
21+
22+
object Arch {
23+
case object Intel extends Arch {}
24+
case object Arm extends Arch {}
25+
26+
val all: List[Arch] = List(Intel, Arm)
27+
28+
def detect(osArchProp: String): Arch = normalise(osArchProp) match {
29+
case "amd64" | "x64" | "x8664" | "x86" => Intel
30+
case "aarch64" | "arm64" => Arm
31+
}
32+
}
33+
34+
sealed abstract class Bits extends Product with Serializable
35+
36+
object Bits {
37+
case object x32 extends Bits
38+
case object x64 extends Bits
39+
40+
def detect(sunArchProp: String): Bits =
41+
sunArchProp match {
42+
case "64" => x64
43+
case "32" => x32
44+
}
45+
}
46+
47+
case class Target(os: OS, arch: Arch, bits: Bits)
48+
49+
lazy val os: OS = OS.detect(sys.props.getOrElse("os.name", ""))
50+
lazy val arch: Arch = Arch.detect(sys.props.getOrElse("os.arch", ""))
51+
lazy val bits: Bits = Bits.detect(sys.props.getOrElse("sun.arch.data.model", ""))
52+
lazy val target: Target = Target(os, arch, bits)
53+
54+
private def normalise(s: String) =
55+
s.toLowerCase(java.util.Locale.US).replaceAll("[^a-z0-9]+", "")
56+
57+
}

0 commit comments

Comments
 (0)