Skip to content

Commit

Permalink
deploy full stack on sandbox cloud server : ok
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpochat committed Jan 7, 2024
1 parent a42eabf commit 9593102
Show file tree
Hide file tree
Showing 25 changed files with 258 additions and 213 deletions.
2 changes: 2 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ WORKDIR /home/viandeendirect
COPY ./backend/pom.xml ./backend/pom.xml
COPY ./backend/gen/pom.xml ./backend/gen/pom.xml
COPY ./backend/app/pom.xml ./backend/app/pom.xml
COPY ./backend/model/pom.xml ./backend/model/pom.xml

RUN mvn -s /usr/share/maven/ref/settings-docker.xml -f ./backend/pom.xml dependency:go-offline

COPY ./backend/gen/src ./backend/gen/src
COPY ./backend/app/src ./backend/app/src
COPY ./backend/model/src ./backend/model/src

RUN mvn -s /usr/share/maven/ref/settings-docker.xml -f ./backend/pom.xml clean install

Expand Down
3 changes: 0 additions & 3 deletions backend/app/src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ spring.datasource.password=vndndrct-db-p4ssw0rd
#spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

# database / JPA config
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
#spring.jpa.hibernate.ddl-auto = create
spring.jpa.hibernate.ddl-auto = update
spring.jpa.show-sql=true
Expand Down
4 changes: 4 additions & 0 deletions backend/app/src/main/resources/application-oauth.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spring.security.oauth2.client.registration.keycloak.client-id=viandeendirect-frontend
spring.security.oauth2.client.registration.keycloak.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.keycloak.scope=openid
spring.security.oauth2.client.provider.keycloak.user-name-attribute=preferred_username
4 changes: 4 additions & 0 deletions backend/app/src/main/resources/application-postgre.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.hibernate.ddl-auto = create
8 changes: 0 additions & 8 deletions backend/app/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
server.port=8080
spring.jackson.date-format=eu.viandeendirect.RFC3339DateFormat
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false

# database / JPA config
spring.jpa.hibernate.ddl-auto = create

spring.security.oauth2.client.registration.keycloak.client-id=viandeendirect-frontend
spring.security.oauth2.client.registration.keycloak.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.keycloak.scope=openid
spring.security.oauth2.client.provider.keycloak.user-name-attribute=preferred_username
20 changes: 9 additions & 11 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,18 @@ services:
- KC_DB_URL=jdbc:postgresql://localhost:${postgres_port:-5432}/identity
- KC_DB_USERNAME=identity
- KC_DB_PASSWORD=${identity_database_password:-dntt-db-p4ssw0rd}
- KC_HOSTNAME=localhost
- KC_HTTP_PORT=8180
- KC_HOSTNAME_URL=${identity_url:-http://localhost:8180}
- KC_HOSTNAME_ADMIN_URL=${identity_url:-http://localhost:8180}
- KC_HEALTH_ENABLED=true
- KC_PROXY=edge
healthcheck:
test: [ "CMD-SHELL", "curl -f http://localhost:8180/health || exit 1" ]
test: [ "CMD-SHELL", "curl -f http://localhost:8080/health || exit 1" ]
interval: 5s
timeout: 60s
retries: 5
command: start-dev
ports:
- ${keycloak_port:-8180}:8180
- ${identity_port:-8180}:8080
network_mode: "host"

backend:
Expand All @@ -58,11 +59,12 @@ services:
image: benjaminpochat/viandeendirect-backend:${DOCKER_IMAGE_TAG:-latest}
environment:
- SERVER_PORT=8080
- SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:${postgres_port:-5432}/viandeendirect
- SPRING_DATASOURCE_URL=jdbc:postgresql://database:5432/viandeendirect
- SPRING_DATASOURCE_USERNAME=viandeendirect
- SPRING_DATASOURCE_PASSWORD=${backend_database_password:-vndndrct-db-p4ssw0rd}
- SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_KEYCLOAK_ISSUER_URI=http://localhost:${keycloak_port:-8180}/realms/viandeendirect
- SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI=http://localhost:${keycloak_port:-8180}/realms/viandeendirect
- SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_KEYCLOAK_ISSUER_URI=${identity_url:-http://localhost:8180}/realms/viandeendirect
- SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI=${identity_url:-http://localhost:8180}/realms/viandeendirect
- SPRING_PROFILES_ACTIVE=oauth,postgre
depends_on:
database:
condition: service_healthy
Expand All @@ -76,10 +78,6 @@ services:
build:
context: "."
dockerfile: ./frontend/Dockerfile
args:
#REACT_APP_FRONTEND_URL: https://sandbox.viandeendirect.eu
REACT_APP_BACKEND_URL: https://sandbox.viandeendirect.eu:8080
#REACT_APP_IDENTITY_URL: https://sandbox.identity.viandeendirect.eu
image: benjaminpochat/viandeendirect-frontend:${DOCKER_IMAGE_TAG:-latest}
volumes:
- ${frontend_config_path:-./frontend-config}:/usr/local/apache2/htdocs/config
Expand Down
3 changes: 0 additions & 3 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ COPY ./frontend /frontend
COPY ./openapi /openapi
WORKDIR /frontend/app

ARG REACT_APP_BACKEND_URL
ENV REACT_APP_BACKEND_URL=${REACT_APP_BACKEND_URL}

RUN npm run generate:api
RUN npm run build:api
RUN npm run install:api
Expand Down
27 changes: 20 additions & 7 deletions frontend/app/package-lock.json

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

1 change: 1 addition & 0 deletions frontend/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@types/node": "^20.9.2",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"dotenv": "^16.3.1",
"typescript": "^5.2.2"
}
}
Binary file removed frontend/app/public/favicon.ico
Binary file not shown.
9 changes: 9 additions & 0 deletions frontend/app/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions frontend/app/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="icon" href="%PUBLIC_URL%/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
Expand All @@ -24,7 +24,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>Viande en direct</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
18 changes: 15 additions & 3 deletions frontend/app/src/api/AuthenticatedApiBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,30 @@ import DefaultApi from 'viandeendirect_eu/dist/api/DefaultApi'
import { MockApi } from './mock/MockApi.ts'

export class AuthenticatedApiBuilder {

backendUrl = undefined

async getBackendUrl() {
if (!this.backendUrl) {
let response = await fetch(window.location.origin + '/config/viandeendirect.json')
let config = await response.json()
this.backendUrl = config.backendUrl
}
return this.backendUrl
}

/**
*
* @param {*} keycloak
* @returns {DefaultApi | MockApi}
* @returns {Promise< DefaultApi | MockApi>}
*/
getAuthenticatedApi(keycloak) {
async getAuthenticatedApi(keycloak) {
if(process.env.REACT_APP_MOCK_API) {
return new MockApi()
} else {
let apiClient = ApiClient.instance
apiClient.authentications['oAuth2ForViandeEnDirect'].accessToken = keycloak.token
apiClient.basePath = 'http://localhost:8080'
apiClient.basePath = await this.getBackendUrl()
var api = new DefaultApi(apiClient)
return api
}
Expand Down
23 changes: 12 additions & 11 deletions frontend/app/src/domains/customer/views/CustomersList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ export default function CustomersList() {
}, [keycloak])

function loadCustomers() {
let api = authenticatedApiBuilder.getAuthenticatedApi(keycloak)
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
api.getCustomers((error, data, response) => {
if (error) {
console.error(error)
} else {
console.log('api.getSales called successfully. Returned data: ' + data)
setCustomers(data)
}
})
}, keycloak)
authenticatedApiBuilder.getAuthenticatedApi(keycloak).then(api => {
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
api.getCustomers((error, data, response) => {
if (error) {
console.error(error)
} else {
console.log('api.getSales called successfully. Returned data: ' + data)
setCustomers(data)
}
})
}, keycloak)
})
}

const rows: GridRowsProp = customers.map(customer => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import { useEffect, useState } from 'react';
import { useKeycloak } from '@react-keycloak/web'
import { Button, Card, CardActions, CardContent, Typography } from "@mui/material"
Expand All @@ -14,17 +15,18 @@ export default function BeefProductionCard({
const authenticatedApiBuilder = new AuthenticatedApiBuilder()

useEffect(() => {
let api = authenticatedApiBuilder.getAuthenticatedApi(keycloak);
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
api.getBeefProduction(production.id, (error, data, response) => {
if (error) {
console.error(error);
} else {
console.log('api.getBeefProduction called successfully. Returned data: ' + data);
setBeefProduction(data)
}
})
}, keycloak)
authenticatedApiBuilder.getAuthenticatedApi(keycloak).then(api => {
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
api.getBeefProduction(production.id, (error, data, response) => {
if (error) {
console.error(error);
} else {
console.log('api.getBeefProduction called successfully. Returned data: ' + data);
setBeefProduction(data)
}
})
}, keycloak)
})
}, [keycloak])

return (
Expand Down
Loading

0 comments on commit 9593102

Please sign in to comment.