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

Refactor: monorepo folder structure #34

Merged
merged 7 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions .container_apps/onboarding-ms/container_app.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ data "azurerm_container_app_environment" "container_app_environment" {
name = "${local.project}-cae"
}

resource "azapi_resource" "container_app" {
resource "azapi_resource" "container_app_onboarding_ms" {
type = "Microsoft.App/containerApps@2023-05-01"
name = "${local.project}-${local.app_name}-ca"
location = data.azurerm_resource_group.resource_group_app.location
Expand Down Expand Up @@ -78,7 +78,7 @@ resource "azapi_resource" "container_app" {
resource "azurerm_key_vault_access_policy" "keyvault_containerapp_access_policy" {
key_vault_id = data.azurerm_key_vault.key_vault.id
tenant_id = data.azurerm_client_config.current.tenant_id
object_id = azapi_resource.container_app_onboarding.identity[0].principal_id
object_id = azapi_resource.container_app_onboarding_ms.identity[0].principal_id

secret_permissions = [
"Get",
Expand Down
4 changes: 2 additions & 2 deletions .container_apps/onboarding-ms/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
output "container_app_resource_group_name" {
value = azapi_resource.container_app_onboarding.location
value = azapi_resource.container_app_onboarding_ms.location
}

output "container_app_environment_name" {
value = data.azurerm_container_app_environment.container_app_environment.name
}

output "container_app_name" {
value = azapi_resource.container_app_onboarding.name
value = azapi_resource.container_app_onboarding_ms.name
}
7 changes: 6 additions & 1 deletion onboarding-ms/.dockerignore → .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
**/.dockerignore
**/.git
**/.gitignore
apps/onboarding-ms/.idea/.gitignore
**/bin
**/docker-compose*
**/Dockerfile*
Expand All @@ -12,6 +12,11 @@
LICENSE
README.md

**/.idea
.idea
**/.mvn
.mvn

# Created by .ignore support plugin (hsz.mobi)
### Maven template
target/
Expand Down
9 changes: 5 additions & 4 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
functions:
- onboarding-functions/**

ms:
- onboarding-ms/**
onboarding-ms:
- apps/onboarding-ms/**

sdk:
- onboarding-sdk/**
onboarding-sdk:
- apps/onboarding-sdk/**

ops:
- .github/**
- .container_apps/**
- .identity/**

docs:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/deploy_onboarding_ms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
- main
types: [closed]
paths:
- "onboarding-ms/**"
- "pom.xml"
- "apps/onboarding-ms/**"
- "apps/pom.xml"

workflow_dispatch:
inputs:
Expand All @@ -32,7 +32,7 @@ env:

jobs:
build:
name: Build OnBoarding Microservice
name: Build Onboarding Microservice
runs-on: ubuntu-latest
if: ${{ (github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == 'true') }}
environment: "${{ inputs.environment != null && inputs.environment || (github.base_ref == 'main' && 'prod' || (github.base_ref == 'develop' && 'uat' || 'dev')) }}-ci"
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
file: ./onboarding-ms/Dockerfile
file: ./apps/onboarding-ms/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release_onboarding_sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ jobs:
cache: maven

- name: Build with Maven
run: mvn -B package -f onboarding-sdk/pom.xml
run: mvn --projects :onboarding-sdk --also-make-dependents clean package -DskipTests
shell: bash

- name: Deploy to GitHub Package Registry
run: |
mvn -B deploy -f onboarding-sdk/pom.xml
mvn -B deploy -f libs/onboarding-sdk/pom.xml
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7 changes: 7 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# see https://help.github.com/en/articles/about-code-owners#example-of-a-codeowners-file

# Default owner
* @pagopa/selfcare-contributors

# Code owner for the applications
/apps/onboarding-ms/* @pagopa/selfcare-contributors
/apps/onboarding-functions/* @pagopa/selfcare-contributors


45 changes: 41 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
# Selfcare Onboarding

Repository that contains backend services for selfcare onboarding. It is a monorepo for onboarding domain that contains:
This repo structure and build monorepo with Apache Maven for selfcare onboarding domain.

- `onboarding-functions`: functions that handle all asynchronous activities related to preparing and completing the onboarding process. Indeed, they are activated by the onboarding microservice upon receiving an onboarding request
- `onboarding-ms`: microservice that implements CRUD operations for the 'onboarding' object and the business logic for the onboarding phase. During the onboarding process
- `onboarding-sdk`: Java utility classes that simplify the work of developers about onboarding activity
Applications under apps/ depend on shared code under libs/.


```
.

├── apps
│   ├── onboarding-functions
│   └── onboarding-ms
└── libs
   ├── onboarding-sdk
```

Look at single README module for more information.

## Infrastructure

The [`.container_apps/`] sub folder contains terraform files for deploying infrastructure as container apps in Azure.


## Continous integration

The [`.github/`] sub folder contains a self-contained ci-stack for building the monorepo with Github Actions.

## Maven basic actions for monorep

Maven is really not a monorepo-*native* build tool (e.g. lacks
trustworthy incremental builds, can only build java code natively, is recursive and
struggles with partial repo checkouts) but can be made good use of with some tricks
and usage of a couple of lesser known command line switches.

| Action | in working directory | with Maven |
|:---------------------------------------------------------------------------------------------------|:----------------------:|:-----------------------------------------------------------------------------------|
| Build the world | `.` | `mvn clean package -DskipTests` |
| Run `onboarding-ms` | `.` | `java -jar apps/onboarding-ms/target/onboarding-ms-0.0.1-SNAPSHOT.jar` |
| Build and test the world | `.` | `mvn clean package` |
| Build the world | `./apps/onboarding-ms` | `mvn --file ../.. clean package -DskipTests` |
| Build `onboarding-ms` and its dependencies | `.` | `mvn --projects :onboarding-ms --also-make clean package -DskipTests` |
| Build `onboarding-ms` and its dependencies | `./apps/onboarding-ms` | `mvn --file ../.. --projects :onboarding-ms --also-make clean package -DskipTests` |
| Build `onboarding-sdk` and its dependents (aka. reverse dependencies or *rdeps* in Bazel parlance) | `.` | `mvn --projects :onboarding-sdk --also-make-dependents clean package -DskipTests` |
| Print dependencies of `onboarding-sdk` | `./apps/onboarding-ms` | `mvn dependency:list` |

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding</artifactId>
<artifactId>onboarding-apps</artifactId>
<version>0.0.1</version>
</parent>

<artifactId>onboarding-functions</artifactId>
<version>1.0.0-SNAPSHOT</version>

<properties>
<compiler-plugin.version>3.11.0</compiler-plugin.version>
<maven.compiler.release>11</maven.compiler.release>
Expand All @@ -19,8 +21,9 @@
<quarkus.platform.version>3.3.3</quarkus.platform.version>
<skipITs>true</skipITs>
<surefire-plugin.version>3.1.2</surefire-plugin.version>
<onboarding-sdk.version>0.0.4</onboarding-sdk.version>
<onboarding-sdk.version>0.1.0</onboarding-sdk.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
Expand Down
File renamed without changes.
38 changes: 38 additions & 0 deletions apps/onboarding-ms/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# syntax=docker/dockerfile:1.6
FROM maven:3-eclipse-temurin-17 AS builder

WORKDIR /src
COPY --link ./pom.xml .

WORKDIR /src/libs
COPY --link ./libs/pom.xml .

WORKDIR /src/libs/onboarding-sdk
COPY ./libs/onboarding-sdk/ .

WORKDIR /src/apps
COPY --link ./apps/pom.xml .

WORKDIR /src/apps/onboarding-ms
COPY --link ./apps/onboarding-ms/pom.xml .
COPY ./apps/onboarding-ms/src/main/ ./src/main/

WORKDIR /src
RUN mvn --projects :onboarding-ms --also-make clean package -DskipTests

FROM openjdk:17-jdk AS runtime

ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'
ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"

WORKDIR /app

COPY --from=builder /src/apps/onboarding-ms/target/quarkus-app/lib/ ./lib/
COPY --from=builder /src/apps/onboarding-ms/target/quarkus-app/*.jar ./
COPY --from=builder /src/apps/onboarding-ms/target/quarkus-app/app/ ./app/
COPY --from=builder /src/apps/onboarding-ms/target/quarkus-app/quarkus/ ./quarkus/

EXPOSE 8080
USER 1001

ENTRYPOINT ["sh", "-c", "java $JAVA_OPTIONS -jar /app/quarkus-run.jar"]
File renamed without changes.
6 changes: 3 additions & 3 deletions onboarding-ms/pom.xml → apps/onboarding-ms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding</artifactId>
<artifactId>onboarding-apps</artifactId>
<version>0.0.1</version>
</parent>
<groupId>it.pagopa.selfcare</groupId>

<artifactId>onboarding-ms</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
Expand All @@ -22,7 +22,7 @@
<quarkus.platform.version>3.4.2</quarkus.platform.version>
<skipITs>true</skipITs>
<surefire-plugin.version>3.1.2</surefire-plugin.version>
<onboarding-sdk.version>0.0.4</onboarding-sdk.version>
<onboarding-sdk.version>0.1.0</onboarding-sdk.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down
40 changes: 40 additions & 0 deletions apps/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-root</artifactId>
<version>0.0.1</version>
</parent>

<artifactId>onboarding-apps</artifactId>
<packaging>pom</packaging>

<profiles>
<profile>
<id>onboarding-ms</id>
<activation>
<file>
<exists>onboarding-ms/pom.xml</exists>
</file>
</activation>
<modules>
<module>onboarding-ms</module>
</modules>
</profile>
<profile>
<id>onboarding-functions</id>
<activation>
<file>
<exists>onboarding-functions/pom.xml</exists>
</file>
</activation>
<modules>
<module>onboarding-functions</module>
</modules>
</profile>
</profiles>

</project>
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
restart: on-failure
build:
context: .
dockerfile: ./onboarding-ms/Dockerfile
dockerfile: ./apps/onboarding-ms/Dockerfile
ports:
- "8080:8080"
environment:
Expand Down
File renamed without changes.
8 changes: 2 additions & 6 deletions onboarding-sdk/pom.xml → libs/onboarding-sdk/pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding</artifactId>
<version>0.0.1</version>
</parent>

<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk</artifactId>
<packaging>pom</packaging>
<name>onboarding-sdk</name>
Expand All @@ -24,7 +20,7 @@

<distributionManagement>
<repository>
<id>github</id>
<id>selfcare-github</id>
<name>Selfcare Onboarding SDK</name>
<url>https://maven.pkg.github.com/pagopa/selfcare-onboarding</url>
</repository>
Expand Down
19 changes: 19 additions & 0 deletions libs/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-root</artifactId>
<version>0.0.1</version>
</parent>

<artifactId>onboarding-libs</artifactId>
<packaging>pom</packaging>

<modules>
<module>onboarding-sdk</module>
</modules>

</project>
5 changes: 0 additions & 5 deletions onboarding-functions/.dockerignore

This file was deleted.

30 changes: 0 additions & 30 deletions onboarding-ms/Dockerfile

This file was deleted.

Loading
Loading