Skip to content

Commit

Permalink
Upgrade to Java 11
Browse files Browse the repository at this point in the history
Some changes in this commit:

* Non scala changes for java upgrade
* Remove jackson mapper
* Add notes for testing on CODE
  • Loading branch information
lindseydew authored and rtyley committed Mar 27, 2024
1 parent 0a8aab6 commit 6b346d4
Show file tree
Hide file tree
Showing 17 changed files with 5,114 additions and 53 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci-mobile-save-for-later-user-deletion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
distribution: temurin
cache: sbt

- name: Run Tests
run: sbt "project mobile-save-for-later-user-deletion" test

- name: Create artifacts
run: sbt "project mobile-save-for-later-user-deletion" assembly

Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/ci-mobile-save-for-later.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ jobs:
id-token: write
contents: read
steps:
- uses: actions/checkout@v3
- uses: aws-actions/configure-aws-credentials@v1
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.GU_RIFF_RAFF_ROLE_ARN }}
aws-region: eu-west-1
- name: Set up JDK 8
uses: actions/setup-java@v3
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: 8
distribution: temurin
java-version: 11
distribution: corretto
cache: sbt

- name: Run Tests
run: sbt "project mobile-save-for-later" test

- name: Create artifacts
run: sbt "project mobile-save-for-later" assembly

Expand All @@ -41,4 +44,4 @@ jobs:
- cdk/cdk.out/MobileSaveForLater-CODE.template.json
- cdk/cdk.out/MobileSaveForLater-PROD.template.json
mobile-save-for-later:
- mobile-save-for-later/target/scala-2.12/mobile-save-for-later.jar
- mobile-save-for-later/target/scala-2.12/mobile-save-for-later.jar
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,51 @@ Try(mapper.readValue[List[SavedArticle]](json)) match {
*NB: I found that when a user record has 350+ articles the resultant string in too long for idea to handle.
## Running apps locally
### Pre-requisites
- Mobile credentials from [Janus](https://janus.gutools.co.uk/login)
- Install [AWS Sam](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html)
- Install [Docker](https://docs.docker.com/engine/install/)
- Make sure you run the app with Java 11
### Mobile Save For Later
Build a jar of the project by running:
- `sbt "project mobile-save-for-later" riffRaffPackageType`
Navigate to the project
- `cd mobile-save-for-later`
Run the lambda service
- `DOCKER_HOST=unix://$HOME/.docker/run/docker.sock sam local start-lambda --debug`
Execute a function locally
- `DOCKER_HOST=unix://$HOME/.docker/run/docker.sock sam local invoke`
Execute a function using AWS cli
- `aws lambda invoke --function-name "mobilesaveforlaterFETCHcdkCODE" --endpoint-url "http://127.0.0.1:3001" --no-verify-ssl out.txt --profile mobile --region eu-west-1`
### Mobile Save For Later User Deletion
Build a jar of the project by running:
- `sbt "project mobile-save-for-later-user-deletion" riffRaffPackageType`
Navigate to the project
- `cd mobile-save-for-later-user-deletion`
Run the lambda service
- `DOCKER_HOST=unix://$HOME/.docker/run/docker.sock sam local start-lambda --debug`
Execute a function locally
- `DOCKER_HOST=unix://$HOME/.docker/run/docker.sock sam local invoke`
Execute a function using AWS cli
- `aws lambda invoke --function-name "mobilesaveforlateruserdeletionCODE" --endpoint-url "http://127.0.0.1:3001" --no-verify-ssl out.txt --profile mobile --region eu-west-1`
## Testing the Apps on CODE
[Save For Later App](docs/testing/save-for-later.md)
[User Deletion App](docs/testing/user-deletion.md)
47 changes: 42 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def projectMaker(projectName: String) = Project(projectName, file(projectName))
.dependsOn(common % "compile->compile")
.aggregate(common)

ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always
def commonAssemblySettings(module: String): immutable.Seq[Def.Setting[_]] =
commonSettings ++ List(
assemblyJarName := s"${name.value}.jar",
Expand All @@ -38,7 +39,6 @@ val commonSettings: immutable.Seq[Def.Setting[_]] = List(
awsJavaSdk,
jackson,
jacksonDataFormat,
jacksonJdk8DataType,
jacksonJsrDataType,
log4j,
commonsIo,
Expand All @@ -49,10 +49,48 @@ val commonSettings: immutable.Seq[Def.Setting[_]] = List(
specsScalaCheck,
specsMock
),
assembly / assemblyMergeStrategy := {
ThisBuild / assemblyMergeStrategy := {
case "META-INF/MANIFEST.MF" => MergeStrategy.discard
case "META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat" =>
new MergeFilesStrategy
case PathList(ps @ _*) if ps.last equalsIgnoreCase "Log4j2Plugins.dat" =>
import java.io.FileInputStream
import java.io.FileOutputStream
import org.apache.logging.log4j.core.config.plugins.processor.PluginCache

import scala.collection.JavaConverters.asJavaEnumerationConverter

import sbt.io.{IO, Using}
import sbtassembly.Assembly.Dependency

CustomMergeStrategy("Log4j2Plugins") { conflicts =>
val dependencyStreamResource =
Using.resource((dependency: Dependency) => dependency.stream())
val tempDir = "target/log4j2-plugin-cache"
val urls = conflicts
.map { conflict =>
dependencyStreamResource(conflict) { is =>
val file = new File(
s"$tempDir/${conflict.module.get.jarName}-Log4j2Plugins.dat"
)
IO.write(file, IO.readBytes(is))
file.toURI.toURL
}
}
val aggregator = new PluginCache()
aggregator.loadCacheFiles(urls.toIterator.asJavaEnumeration)
val pluginCache = new File(s"$tempDir/Log4j2Plugins.dat")
val pluginCacheOutputStream = new FileOutputStream(pluginCache)
aggregator.writeCache(pluginCacheOutputStream)
pluginCacheOutputStream.close()
Right(
Vector(
JarEntry(
conflicts.head.target,
() => new FileInputStream(pluginCache)
)
)
)
}

case _ => MergeStrategy.first
},
dependencyOverrides ++= Seq(
Expand All @@ -68,7 +106,6 @@ val commonSettings: immutable.Seq[Def.Setting[_]] = List(
"-deprecation",
"-encoding",
"UTF-8",
"-target:jvm-1.8",
"-Ypartial-unification",
"-Ywarn-dead-code"
)
Expand Down
8 changes: 4 additions & 4 deletions cdk/lib/__snapshots__/mobile-save-for-later.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ Object {
"Arn",
],
},
"Runtime": "java8",
"Runtime": "java11",
"Tags": Array [
Object {
"Key": "App",
Expand Down Expand Up @@ -980,7 +980,7 @@ Object {
"Arn",
],
},
"Runtime": "java8",
"Runtime": "java11",
"Tags": Array [
Object {
"Key": "App",
Expand Down Expand Up @@ -2002,7 +2002,7 @@ Object {
"Arn",
],
},
"Runtime": "java8",
"Runtime": "java11",
"Tags": Array [
Object {
"Key": "App",
Expand Down Expand Up @@ -2232,7 +2232,7 @@ Object {
"Arn",
],
},
"Runtime": "java8",
"Runtime": "java11",
"Tags": Array [
Object {
"Key": "App",
Expand Down
2 changes: 1 addition & 1 deletion cdk/lib/mobile-save-for-later.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class MobileSaveForLater extends GuStack {
const app = "mobile-save-for-later";

const commonLambdaProps = {
runtime: Runtime.JAVA_8, // We should upgrade to Java 11 in a future PR
runtime: Runtime.JAVA_11,
app,
fileName: `${app}.jar`,
};
Expand Down
Loading

0 comments on commit 6b346d4

Please sign in to comment.