Skip to content

Commit

Permalink
feat: Use native image (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfyda authored Jul 9, 2024
1 parent 61ef58f commit d73720c
Showing 22 changed files with 53 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ RUNNING_PID
target
vendor
tests
.codacyrc

project/*
!project/build.properties
36 changes: 24 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
FROM sbtscala/scala-sbt:eclipse-temurin-jammy-11.0.22_7_1.9.9_2.13.13 as builder
FROM sbtscala/scala-sbt:eclipse-temurin-jammy-11.0.22_7_1.9.9_2.13.13 as doc-generator

WORKDIR /app
COPY composer.json .

RUN wget https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.4.3/phpDocumentor.phar && \
mv phpDocumentor.phar /usr/local/bin/phpdoc && \
chmod +x /usr/local/bin/phpdoc

COPY build.sbt .
COPY docs /docs
COPY project project
COPY doc-generator doc-generator

RUN sbt 'doc-generator/runMain codacy.codesniffer.docsgen.GeneratorMain'

FROM sbtscala/scala-sbt:graalvm-ce-22.3.3-b1-java17_1.9.9_3.4.0 AS builder

WORKDIR /app

COPY build.sbt .
COPY project project
COPY src src

RUN wget https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.4.3/phpDocumentor.phar && \
mv phpDocumentor.phar /usr/local/bin/phpdoc && \
chmod +x /usr/local/bin/phpdoc && \
sbt 'runMain codacy.codesniffer.docsgen.GeneratorMain'
RUN sbt stage
RUN --mount=type=cache,target=/root/.cache/coursier \
sbt nativeImage

FROM php:8.2-alpine

@@ -22,7 +34,7 @@ ENV COMPOSER_ALLOW_SUPERUSER 1
ENV PATH ${COMPOSER_HOME}/vendor/bin:${PATH}

# Install necessary packages
RUN apk --no-cache add php82 openjdk11-jre-headless
RUN apk --no-cache add php82

# Configure PHP settings
RUN sed 's/.*short_open_tag.*=.*/short_open_tag=On/' /etc/php82/php.ini -i
@@ -32,15 +44,15 @@ RUN curl -sS https://getcomposer.org/installer | php
COPY composer.* ${COMPOSER_HOME}
RUN php composer.phar global install

# Cleanup and miscellaneous
# Cleanup and miscellaneous
RUN rm -rf /tmp/* && \
adduser -u 2004 -D docker

# Copy codacy-codesniffer and docs
COPY --chown=docker:docker --from=builder /app/target/universal/stage scala
COPY --chown=docker:docker --from=builder /docs /docs
COPY --chown=docker:docker --from=builder /app/target/native-image/codacy-codesniffer bin/codacy-codesniffer
COPY --chown=docker:docker --from=doc-generator /docs /docs

WORKDIR /src

USER docker
ENTRYPOINT ["/app/scala/bin/codacy-codesniffer"]
ENTRYPOINT ["/app/bin/codacy-codesniffer"]
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@ See the [codacy-engine-scala-seed](https://github.com/codacy/codacy-engine-scala
You can create the docker by doing:

```bash
sbt Docker / publishLocal
docker build -t codacy-codesniffer .
```

@@ -40,7 +39,7 @@ sudo chmod +x /usr/local/bin/phpdoc
Update the versions in `composer.json` and run

```bash
sbt "runMain codacy.codesniffer.docsgen.GeneratorMain"
sbt "doc-generator/runMain codacy.codesniffer.docsgen.GeneratorMain"
```

This will create updated `patterns.json`, `description.json` and the individual documentation Markdown files.
37 changes: 26 additions & 11 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
name := "codacy-codesniffer"
ThisBuild / scalaVersion := "2.13.14"

scalaVersion := "2.13.13"
lazy val `doc-generator` = project
.settings(
libraryDependencies ++= Seq("org.scala-lang.modules" %% "scala-xml" % "2.2.0",
"org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.4",
"com.codacy" %% "codacy-engine-scala-seed" % "6.1.2",
"com.lihaoyi" %% "ujson" % "3.1.2",
"com.github.pathikrit" %% "better-files" % "3.9.2"
)
)

libraryDependencies ++= Seq("org.scala-lang.modules" %% "scala-xml" % "2.2.0",
"org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.4",
"com.codacy" %% "codacy-engine-scala-seed" % "6.1.2",
"com.lihaoyi" %% "ujson" % "3.1.2",
"com.github.pathikrit" %% "better-files" % "3.9.2")

enablePlugins(AshScriptPlugin)

Compile / mainClass := Some("codacy.Engine")
lazy val root = project
.in(file("."))
.settings(name := "codacy-codesniffer",
libraryDependencies ++= Seq("org.scala-lang.modules" %% "scala-xml" % "2.2.0",
"com.codacy" %% "codacy-engine-scala-seed" % "6.1.2"
),
mainClass in Compile := Some("codacy.Engine"),
nativeImageOptions ++= List("-O1",
"-H:+ReportExceptionStackTraces",
"--no-fallback",
"--no-server",
"--static"
)
)
.enablePlugins(NativeImagePlugin)
.enablePlugins(JavaAppPackaging)
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
addSbtPlugin("com.codacy" % "codacy-sbt-plugin" % "25.2.0")
addSbtPlugin("org.scalameta" % "sbt-native-image" % "0.3.0")

0 comments on commit d73720c

Please sign in to comment.