diff --git a/.docker/admin-server/Dockerfile b/.docker/admin-server/Dockerfile new file mode 100644 index 00000000..d04bb17b --- /dev/null +++ b/.docker/admin-server/Dockerfile @@ -0,0 +1,19 @@ +FROM openjdk:21-jdk as builder +RUN microdnf install findutils + +WORKDIR /app + +COPY . /app + +RUN chmod +x ./gradlew + +RUN ./gradlew :modules:admin-server:jar -x test -x allTests -x jsBrowserTest + +FROM openjdk:21-jdk as runner + +WORKDIR /app + +COPY .env .env +COPY --from=builder /app/modules/admin-server/build/libs/admin-server-0.0.1.jar ./admin-server-0.0.1.jar + +ENTRYPOINT ["java", "-jar", "admin-server-0.0.1.jar"] diff --git a/.docker/federation-server/Dockerfile b/.docker/federation-server/Dockerfile new file mode 100644 index 00000000..5f7ae6cf --- /dev/null +++ b/.docker/federation-server/Dockerfile @@ -0,0 +1,19 @@ +FROM openjdk:21-jdk as builder +RUN microdnf install findutils + +WORKDIR /app + +COPY . /app + +RUN chmod +x ./gradlew + +RUN ./gradlew :modules:federation-server:jar -x test -x allTests -x jsBrowserTest + +FROM openjdk:21-jdk as runner + +WORKDIR /app + +COPY .env .env +COPY --from=builder /app/modules/federation-server/build/libs/federation-server-0.0.1.jar ./federation-server-0.0.1.jar + +ENTRYPOINT ["java", "-jar", "federation-server-0.0.1.jar"] diff --git a/.env b/.env index b5c1af1c..4ac71d15 100644 --- a/.env +++ b/.env @@ -1,5 +1,5 @@ -DATASOURCE_URL=jdbc:postgresql://localhost:5432/openid-federation-db +DATASOURCE_URL=jdbc:postgresql://db:5432/openid-federation-db DATASOURCE_USER=openid-federation-db-user DATASOURCE_PASSWORD=openid-federation-db-password DATASOURCE_DB=openid-federation-db -APP_KEY=Nit5tWts42QeCynT1Q476LyStDeSd4xb \ No newline at end of file +APP_KEY=Nit5tWts42QeCynT1Q476LyStDeSd4xb diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66a729c6..92c81164 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: java-version: 17 - name: Build the stack - run: docker compose -f docker-compose.yaml up -d + run: docker compose -f docker-compose.yaml up db -d env: DATASOURCE_USER: ${{ secrets.DATASOURCE_USER }} DATASOURCE_PASSWORD: ${{ secrets.DATASOURCE_PASSWORD }} diff --git a/.gitignore b/.gitignore index 0a8ce54c..a9c966b0 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,4 @@ captures /.temp/ /docker/.env /.run/* -kotlin-js-store/ \ No newline at end of file +kotlin-js-store/ diff --git a/README.md b/README.md index feb4eedb..f720af5f 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ In the context of OpenID Federation, Entity Statements play a crucial role. Thes about the entity, such as its public keys and metadata. This framework allows entities to assert their identity and capabilities in a standardized manner, enabling seamless integration and interoperability within federations. -## Key Concepts +# Key Concepts - **Federation**: A group of organizations that agree to interoperate under a set of common rules defined in a federation policy. @@ -92,3 +92,38 @@ purposes. **It is not intended for use in production environments** due to signi - Entity Statements can include additional claims as required by applications and protocols. - Metadata in Subordinate Statements overrides that in the Entity’s own configuration. + +# Servers Deployment Instructions + +## Docker Setup + +For seamless deployment of the OpenID Federation servers, Docker and Docker Compose offer the most efficient and +straightforward approach. + +## Essential Commands + +### Build Docker Images + +- `docker compose build` - Compile the Docker images for the services. +- `docker compose build --no-cache` - Compile the Docker images without utilizing the build cache, ensuring a clean + build. + +### Manage Services: + +- `docker compose up` - Initiate the services. +- `docker compose up -d` - Launch the services in detached mode, allowing them to run in the background. +- `docker compose down` - Terminate the services. +- `docker compose down -v` - Terminate the services and remove associated volumes. +- `docker compose up db -d` - Start only the database container in detached mode for isolated database operations. +- `docker compose up federation-server -d` - Start only the Federation Server in detached mode. + +## API Endpoints via Docker + +* Federation API: Accessible at http://localhost:8080 +* Admin Server API: Accessible at http://localhost:8081 + +## Local Key Management System - Important Notice + +Local Key Management Service is designed primarily for testing, development, and local experimentation +purposes. **It is not intended for use in production environments** due to significant security and compliance risks. + diff --git a/docker-compose.yaml b/docker-compose.yaml index 3a726859..2395a962 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -5,13 +5,55 @@ services: environment: POSTGRES_USER: ${DATASOURCE_USER} POSTGRES_PASSWORD: ${DATASOURCE_PASSWORD} - POSTGRES_DB: openid-federation-db + POSTGRES_DB: ${DATASOURCE_DB} ports: - "5432:5432" volumes: - postgres_data:/var/lib/postgresql/data networks: - openid_network + healthcheck: + test: [ "CMD-SHELL", "pg_isready -U ${DATASOURCE_DB}" ] + interval: 3s + timeout: 5s + retries: 20 + + federation-server: + build: + context: . + dockerfile: ./.docker/federation-server/Dockerfile + ports: + - "8080:8080" + container_name: openid-federation-server + environment: + DATASOURCE_URL: ${DATASOURCE_URL} + DATASOURCE_USER: ${DATASOURCE_USER} + DATASOURCE_PASSWORD: ${DATASOURCE_PASSWORD} + depends_on: + admin-server: + condition: service_started + db: + condition: service_healthy + networks: + - openid_network + + admin-server: + build: + context: . + dockerfile: ./.docker/admin-server/Dockerfile + ports: + - "8081:8080" + container_name: openid-federation-server-admin + environment: + DATASOURCE_URL: ${DATASOURCE_URL} + DATASOURCE_USER: ${DATASOURCE_USER} + DATASOURCE_PASSWORD: ${DATASOURCE_PASSWORD} + APP_KEY: ${APP_KEY} + depends_on: + db: + condition: service_healthy + networks: + - openid_network networks: openid_network: diff --git a/modules/admin-server/src/main/resources/application.properties b/modules/admin-server/src/main/resources/application.properties index 49841a4e..8ba9c117 100644 --- a/modules/admin-server/src/main/resources/application.properties +++ b/modules/admin-server/src/main/resources/application.properties @@ -1,5 +1,5 @@ spring.config.import=optional:file:../../.env[.properties] -spring.application.name=OpenID Federation +spring.application.name=OpenID Federation Admin Server spring.datasource.url=${DATASOURCE_URL} spring.datasource.username=${DATASOURCE_USER} spring.datasource.password=${DATASOURCE_PASSWORD} diff --git a/modules/openid-federation-common/build.gradle.kts b/modules/openid-federation-common/build.gradle.kts index f4ffe611..09aab985 100644 --- a/modules/openid-federation-common/build.gradle.kts +++ b/modules/openid-federation-common/build.gradle.kts @@ -138,7 +138,6 @@ kotlin { } val jsTest by getting { - dependsOn(commonTest) dependencies { implementation(kotlin("test-js")) implementation(kotlin("test-annotations-common"))