Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Java 11 #107

Merged
merged 13 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
lindseydew marked this conversation as resolved.
Show resolved Hide resolved

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
lindseydew marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/setup-java@v4
with:
java-version: 8
distribution: temurin
java-version: 11
distribution: corretto
lindseydew marked this conversation as resolved.
Show resolved Hide resolved
cache: sbt

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

- name: Create artifacts
run: sbt "project mobile-save-for-later" assembly
lindseydew marked this conversation as resolved.
Show resolved Hide resolved

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)
)
)
)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this chunk of code has come from project/MergeFilesStrategy.scala, and taken on some more modifications?

It's quite a big and obscure bit of code though, so I feel like keeping it in its own file in MergeFilesStrategy.scala is not a bad idea - we should probably include some explanation or references for it (like, where did we get this code, and what prompted the changes to it that are occurring now?)

case _ => MergeStrategy.first
},
dependencyOverrides ++= Seq(
Expand All @@ -68,7 +106,6 @@ val commonSettings: immutable.Seq[Def.Setting[_]] = List(
"-deprecation",
"-encoding",
"UTF-8",
lindseydew marked this conversation as resolved.
Show resolved Hide resolved
"-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,
lindseydew marked this conversation as resolved.
Show resolved Hide resolved
app,
fileName: `${app}.jar`,
};
Expand Down
Loading
Loading