Skip to content

Commit

Permalink
Add Github CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ch4mpy committed Oct 9, 2023
1 parent de2aa68 commit d85b08d
Show file tree
Hide file tree
Showing 17 changed files with 176 additions and 50 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: CI

#env:
# JDK_JAVA_OPTIONS: --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED
# MAVEN_USERNAME: ch4mpy

on: [push]

jobs:
build-and-deploy:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'

- uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Make Maven Wrapper executable
if: contains(matrix.os, 'win') == false
run: chmod +x ./api/mvnw

- name: Build with Maven
run: |
cd ./api
./mvnw clean install -Popenapi,h2
./mvnw spring-boot:build-image -DskipTests
- name: Set VERSION environment variable
run: |
cd ./api
echo "VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Docker Tag-Push gateway ${{ env.VERSION }}
run: |
docker tag bff:${{ env.VERSION }} ${{ secrets.DOCKERHUB_USERNAME }}/quiz-bff
docker push ${{ secrets.DOCKERHUB_USERNAME }}/quiz-bff
- name: Docker Tag-Push API ${{ env.VERSION }}
run: |
docker tag quiz-api:${{ env.VERSION }} ${{ secrets.DOCKERHUB_USERNAME }}/quiz-api
docker push ${{ secrets.DOCKERHUB_USERNAME }}/quiz-api
- name: Docker Build-Tag-Push Angular UI
uses: docker/build-push-action@v4
with:
context: ./angular-ui
file: ./angular-ui/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/quiz-ui

- name: Rollout Restart OVH quiz
run: |
mkdir ${HOME}/.kube
echo ${{ secrets.OVH_KUBECONFIG }} | base64 --decode > ${HOME}/.kube/config
kubectl config use-context kubernetes-admin@c4-staging
kubectl rollout restart -n quiz deployment.apps/quiz-ui deployment.apps/bff deployment.apps/quiz-api
4 changes: 2 additions & 2 deletions angular-ui/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
Expand Down
12 changes: 12 additions & 0 deletions angular-ui/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Stage 1
FROM node:18 as node
COPY ./ /usr/local/app
WORKDIR /usr/local/app
RUN apt-get update && apt-get install -y openjdk-17-jre
RUN npm install
RUN npm run build

# Stage 2
FROM nginx
COPY --from=node /usr/local/app/dist/quiz/* /usr/share/nginx/html/ui/
COPY nginx.conf /etc/nginx/nginx.conf
15 changes: 15 additions & 0 deletions angular-ui/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
events{}

http {

include /etc/nginx/mime.types;

server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
location /ui/ {
try_files $uri $uri/ /ui/index.html;
}
}
}
1 change: 1 addition & 0 deletions angular-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions angular-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
"name": "angular-ui",
"version": "0.0.0",
"scripts": {
"postinstall": "npm run bff-api && npm run quiz-api",
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"bff-api:generate": "npx openapi-generator-cli generate -i ../bff.openapi.json -g typescript-angular --type-mappings AnyType=any --additional-properties=serviceSuffix=Api,npmName=@c4-soft/bff-api,npmVersion=0.0.1,stringEnums=true,enumPropertyNaming=camelCase,supportsES6=true,withInterfaces=true --remove-operation-id-prefix -o projects/c4-soft/bff-api",
"build": "ng build quiz",
"bff-api:generate": "npx openapi-generator-cli generate -i ./bff.openapi.json -g typescript-angular --type-mappings AnyType=any --additional-properties=serviceSuffix=Api,npmName=@c4-soft/bff-api,npmVersion=0.0.1,stringEnums=true,enumPropertyNaming=camelCase,supportsES6=true,withInterfaces=true --remove-operation-id-prefix -o projects/c4-soft/bff-api",
"bff-api:build": "npm run ng -- build @c4-soft/bff-api --configuration production",
"bff-api": "npm run bff-api:generate && npm run bff-api:build",
"quiz-api:generate": "npx openapi-generator-cli generate -i ../quiz-api.openapi.json -g typescript-angular --type-mappings AnyType=any --additional-properties=serviceSuffix=Api,npmName=@c4-soft/quiz-api,npmVersion=0.0.1,stringEnums=true,enumPropertyNaming=camelCase,supportsES6=true,withInterfaces=true --remove-operation-id-prefix -o projects/c4-soft/quiz-api",
"quiz-api:generate": "npx openapi-generator-cli generate -i ./quiz-api.openapi.json -g typescript-angular --type-mappings AnyType=any --additional-properties=serviceSuffix=Api,npmName=@c4-soft/quiz-api,npmVersion=0.0.1,stringEnums=true,enumPropertyNaming=camelCase,supportsES6=true,withInterfaces=true --remove-operation-id-prefix -o projects/c4-soft/quiz-api",
"quiz-api:build": "npm run ng -- build @c4-soft/quiz-api --configuration production",
"quiz-api": "npm run quiz-api:generate && npm run quiz-api:build",
"watch": "ng build --watch --configuration development",
Expand Down
1 change: 0 additions & 1 deletion angular-ui/projects/c4-soft/bff-api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ encoder.ts
git_push.sh
index.ts
karma.conf.js
package.json
package-lock.json
param.ts
README.md
Expand Down
12 changes: 12 additions & 0 deletions angular-ui/projects/c4-soft/bff-api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@c4-soft/bff-api",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^16.0.0",
"@angular/core": "^16.0.0"
},
"dependencies": {
"tslib": "^2.3.0"
},
"sideEffects": false
}
1 change: 0 additions & 1 deletion angular-ui/projects/c4-soft/quiz-api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ encoder.ts
git_push.sh
index.ts
karma.conf.js
package.json
package-lock.json
param.ts
README.md
Expand Down
12 changes: 12 additions & 0 deletions angular-ui/projects/c4-soft/quiz-api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@c4-soft/quiz-api",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^16.0.0",
"@angular/core": "^16.0.0"
},
"dependencies": {
"tslib": "^2.3.0"
},
"sideEffects": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
"description": "Authorization server 'issuer' URI"
},
{
"name": "oauth2-client-id",
"name": "keycloak-host",
"type": "java.lang.String",
"description": "OAuth2 client ID for the gateway"
"description": "Scheme, hostname and port for Keycloak server"
},
{
"name": "oauth2-client-secret",
"name": "keycloak-realm",
"type": "java.lang.String",
"description": "OAuth2 client secret for the gateway"
"description": "Keycloak 'realm'"
},
{
"name": "gateway-uri",
Expand Down
22 changes: 11 additions & 11 deletions api/bff/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
scheme: http
oauth2-issuer: https://oidc.c4-soft.com/auth/realms/quiz
oauth2-client-id: quiz-bff
oauth2-client-secret: change-me
keycloak-host: https://oidc.c4-soft.com
keycloak-realm: quiz
oauth2-issuer: ${keycloak-host}/auth/realms/${keycloak-realm}

gateway-uri: ${scheme}://localhost:${server.port}
quiz-api-uri: ${scheme}://localhost:7084
Expand All @@ -24,15 +24,15 @@ spring:
oauth2:
client:
provider:
oauth2:
keycloak:
issuer-uri: ${oauth2-issuer}
user-name-attribute: preferred_username
registration:
authorization-code:
quiz-bff:
provider: keycloak
client-id: quiz-bff
client-secret: change-me
authorization-grant-type: authorization_code
client-id: ${oauth2-client-id}
client-secret: ${oauth2-client-secret}
provider: oauth2
scope:
- openid
- profile
Expand All @@ -49,7 +49,7 @@ spring:
predicates:
- Path=/
filters:
- RedirectTo=301,${gateway-uri}/ui
- RedirectTo=301,${gateway-uri}/ui/
# Serve the Angular app through the gateway
- id: ui
uri: ${ui-host}
Expand Down Expand Up @@ -103,8 +103,8 @@ com:
- /me
- /bff/**
csrf: cookie-accessible-from-js
post-login-redirect-path: /ui
post-logout-redirect-path: /ui
post-login-redirect-path: /ui/
post-logout-redirect-path: /ui/
# OAuth2 resource server configuration
resourceserver:
permit-all:
Expand Down
29 changes: 12 additions & 17 deletions api/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
Expand All @@ -16,28 +16,27 @@
<packaging>pom</packaging>

<properties>
<java.version>21</java.version>
<java.version>17</java.version>
<spring-cloud-dependencies.version>2022.0.4</spring-cloud-dependencies.version>
<com.c4-soft.springaddons.version>7.1.10</com.c4-soft.springaddons.version>
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
<org.mapstruct.version>1.5.5.Final</org.mapstruct.version>
<swagger-annotations.version>2.2.15</swagger-annotations.version>
<springdoc-openapi.version>2.2.0</springdoc-openapi.version>
<springdoc-openapi-maven-plugin.version>1.4</springdoc-openapi-maven-plugin.version>
<springdoc-openapi.output-dir>${project.basedir}/../../angular-ui</springdoc-openapi.output-dir>
<integration-tests.scheme>http</integration-tests.scheme>
<integration-tests.hostname>localhost</integration-tests.hostname>
<integration-tests.port>8080</integration-tests.port>
<ca-certificates.binding>${project.basedir}/bindings/ca-certificates</ca-certificates.binding>
<springdoc-openapi.output-dir>${project.basedir}/../../</springdoc-openapi.output-dir>
<springdoc-openapi.output-dir>${project.basedir}/../../angular-ui</springdoc-openapi.output-dir>
<db-vendor>postgresql</db-vendor>
</properties>

<modules>
<module>bff</module>
<module>quiz-api</module>
</modules>

<dependencyManagement>
<dependencies>
<dependency>
Expand All @@ -47,7 +46,7 @@
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
Expand All @@ -73,7 +72,7 @@
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
<version>${springdoc-openapi.version}</version>
</dependency>

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
Expand All @@ -89,7 +88,7 @@
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>

<dependency>
<groupId>com.c4-soft.springaddons</groupId>
<artifactId>spring-addons-starter-oidc</artifactId>
Expand All @@ -102,7 +101,7 @@
</dependency>
</dependencies>
</dependencyManagement>

<build>
<pluginManagement>
<plugins>
Expand Down Expand Up @@ -141,19 +140,14 @@
<enableAssociationManagement>true</enableAssociationManagement>
</configuration>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<bindings>
<binding>${ca-certificates.binding}:/platform/bindings/ca-certificates:ro</binding>
<binding>
${ca-certificates.binding}:/platform/bindings/ca-certificates:ro</binding>
</bindings>
</image>
<excludes>
Expand All @@ -169,7 +163,8 @@
<artifactId>springdoc-openapi-maven-plugin</artifactId>
<version>${springdoc-openapi-maven-plugin.version}</version>
<configuration>
<apiDocsUrl>${integration-tests.scheme}://${integration-tests.hostname}:${integration-tests.port}/v3/api-docs</apiDocsUrl>
<apiDocsUrl>
${integration-tests.scheme}://${integration-tests.hostname}:${integration-tests.port}/v3/api-docs</apiDocsUrl>
<outputFileName>${project.artifactId}.openapi.json</outputFileName>
<outputDir>${springdoc-openapi.output-dir}</outputDir>
<skip>false</skip>
Expand Down
8 changes: 1 addition & 7 deletions api/quiz-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

<!-- Tests -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -163,7 +158,7 @@
<dependencies>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
</dependency>
</dependencies>
<build>
Expand All @@ -189,7 +184,6 @@
<executions>
<execution>
<id>pre-integration-test</id>
<configuration></configuration>
<goals>
<goal>start</goal>
</goals>
Expand Down
Loading

0 comments on commit d85b08d

Please sign in to comment.