I have a Spring Boot application.
And my Liquibase doesn't create the DATABASECHANGELOG table.
It proceeds the changelog and after that throws an error.
Any ideas what could be wrong?
Something is missing?
error:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'addressbook.DATABASECHANGELOG' doesn't exist
config:
spring:
jpa:
show-sql: false
hibernate:
ddl-auto: none
datasource:
url: jdbc:mysql://localhost:3306/addressbook?characterEncoding=UTF-8
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
liquibase:
enabled: true
change-log: "classpath:db/liquibase-changelog.yml"
changelog:
databaseChangeLog:
- changeSet:
id: 1
author: me
changes:
- sqlFile:
path: sql/20181025_startup.sql
relativeToChangelogFile: true
stripComments: true
- changeSet:
id: 2
author: me
changes:
- sqlFile:
path: sql/20181026_create_table_contacts.sql
relativeToChangelogFile: true
stripComments: true
dependencies:
gradleVersion=4.10.2
springCloudVersion=Finchley.SR2
springBootVersion=2.0.6.RELEASE
mysqlVersion=5.1.47
liquibaseVersion=3.6.2
Related
In my next.config.js, I have a part that looks like this:
module.exports = {
serverRuntimeConfig: { // Will only be available on the server side
mySecret: 'secret'
},
publicRuntimeConfig: { // Will be available on both server and client
PORT: process.env.PORT,
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
BACKEND_URL: process.env.BACKEND_URL
}
I have a .env file and when run locally, the Next.js application succesfully fetches the environment variables from the .env file.
I refer to the env variables like this for example:
axios.get(publicRuntimeConfig.BACKOFFICE_BACKEND_URL)
However, when I have this application deployed onto my Kubernetes cluster, the environment variables set in the deploy file are not being collected. So they return as undefined.
I read that .env files cannot be read due to the differences between frontend (browser based) and backend (Node based), but there must be some way to make this work.
Does anyone know how to use environment variables saved in your pods/containers deploy file on your frontend (browser based) application?
Thanks.
EDIT 1:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "38"
creationTimestamp: xx
generation: 40
labels:
app: appname
name: appname
namespace: development
resourceVersion: xx
selfLink: /apis/extensions/v1beta1/namespaces/development/deployments/appname
uid: xxx
spec:
progressDeadlineSeconds: xx
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: appname
tier: sometier
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: appname
tier: sometier
spec:
containers:
- env:
- name: NODE_ENV
value: development
- name: PORT
value: "3000"
- name: SOME_VAR
value: xxx
- name: SOME_VAR
value: xxxx
image: someimage
imagePullPolicy: Always
name: appname
readinessProbe:
failureThreshold: 3
httpGet:
path: /healthz
port: 3000
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
resources:
requests:
cpu: 100m
memory: 100Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status:
availableReplicas: 1
conditions:
- lastTransitionTime: xxx
lastUpdateTime: xxxx
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
observedGeneration: 40
readyReplicas: 1
replicas: 1
updatedReplicas: 1
You can create a config-map and then mount it as a file in your deployment with your custom environment variables.
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "38"
creationTimestamp: xx
generation: 40
labels:
app: appname
name: appname
namespace: development
resourceVersion: xx
selfLink: /apis/extensions/v1beta1/namespaces/development/deployments/appname
uid: xxx
spec:
progressDeadlineSeconds: xx
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: appname
tier: sometier
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: appname
tier: sometier
spec:
containers:
- env:
- name: NODE_ENV
value: development
- name: PORT
value: "3000"
- name: SOME_VAR
value: xxx
- name: SOME_VAR
value: xxxx
volumeMounts:
- name: environment-variables
mountPath: "your/path/to/store/the/file"
readOnly: true
image: someimage
imagePullPolicy: Always
name: appname
readinessProbe:
failureThreshold: 3
httpGet:
path: /healthz
port: 3000
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
resources:
requests:
cpu: 100m
memory: 100Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumes:
- name: environment-variables
configMap:
name: environment-variables
items:
- key: .env
path: .env
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status:
availableReplicas: 1
conditions:
- lastTransitionTime: xxx
lastUpdateTime: xxxx
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
observedGeneration: 40
readyReplicas: 1
replicas: 1
updatedReplicas: 1
I added the following configuration in your deployment file:
volumeMounts:
- name: environment-variables
mountPath: "your/path/to/store/the/file"
readOnly: true
volumes:
- name: environment-variables
configMap:
name: environment-variables
items:
- key: .env
path: .env
You can then create a config map with key ".env" with your environment variables on kubernetes.
Configmap like this:
apiVersion: v1
kind: ConfigMap
metadata:
name: environment-variables
namespace: your-namespace
data:
.env: |
variable1: value1
variable2: value2
I'm working with Symfony 4 and i have installed JMS serializer with FOSRest bundle.
So every time i've got an error i've got this message :
JMS\Serializer\Exception\RuntimeException: Resources are not supported in serialized data. Path: Monolog\Handler\StreamHandler -> Symfony\Bridge\Monolog\Logger -> Symfony\Component\Cache\Adapter\PhpFilesAdapter -> Symfony\Component\Cache\Adapter\TraceableAdapter -> Symfony\Component\Cache\Adapter\PhpArrayAdapter -> Symfony\Component\Cache\DoctrineProvider -> Doctrine\Common\Annotations\CachedReader -> Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener -> Symfony\Component\EventDispatcher\EventDispatcher -> Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher -> ContainerYCXy4ht\srcTestDebugProjectContainer -> FOS\RestBundle\Request\ParamFetcher -> Symfony\Component\HttpFoundation\ParameterBag -> Symfony\Component\HttpFoundation\Request -> Symfony\Component\HttpKernel\Exception\HttpException
And after the real error and i dont understand why ? I use JMS contrib recipe :
/packages/dev/jms_serializer.yaml
jms_serializer:
visitors:
json:
options:
- JSON_PRETTY_PRINT
- JSON_UNESCAPED_SLASHES
- JSON_PRESERVE_ZERO_FRACTION
/packages/prod/jms_serializer.yaml
jms_serializer:
visitors:
json:
options:
- JSON_UNESCAPED_SLASHES
- JSON_PRESERVE_ZERO_FRACTION
/packages/jms_serializer
jms_serializer:
visitors:
xml:
format_output: '%kernel.debug%'
So i don't understand why this behavior ?
If someone could help me ?
Thanks by advance
I found the solution it was an fos_rest configuration error
Before
fos_rest:
exception:
enabled: true
exception_controller: 'fos_rest.exception.controller:showAction'
param_fetcher_listener: force
body_listener: true
format_listener:
enabled: true
rules:
- { path: '^/api', priorities: ['json'], prefer_extension: true}
- { path: '^/', priorities: [ 'html', '*/*'], fallback_format: html, prefer_extension: true }
view:
view_response_listener: 'force'
After
fos_rest:
param_fetcher_listener: force
format_listener:
enabled: true
rules:
- { path: '^/api', priorities: ['json'], prefer_extension: true}
- { path: '^/', priorities: [ 'html', '*/*'], fallback_format: html, prefer_extension: true }
view:
view_response_listener: 'force'
Here is my application.yml
dataSources:
dataSource:
loggingSql: true
pooled: true
jmxExport: true
driverClassName: org.h2.Driver
username: sa
password:
environments:
development:
dataSources:
dataSource:
dbCreate: validate
url: jdbc:oracle:thin:#hostname:1521/mydb driverClassName: oracle.jdbc.OracleDriver
dialect: org.hibernate.dialect.Oracle10gDialect
jndiName: java:comp/env/jdbc/devapp
grails.naming.entries:
jdbc:
devapp:
type: javax.sql.DataSource
driverClassName: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:#hostname:1521/mydb
username: "username"
password: "password"
properties:
maxActive: 20
maxIdle: 4
initialSize: 4
maxWait: -1
And here is my build.gradle entries:
runtime "oracle:ojdbc6:11.2.0.4.0"
Build fails with the following error.
Error Could not resolve all dependencies for configuration ':testRuntime'. Type 'gradle dependencies' for more information
When I placed the following dependency in build.gradle, it worked.
compile 'com.oracle:ojdbc6:11.2.0.3'
I am using LexikJWTBundle to authenticate an ionic angularjs app to a symfony2REST API.
My issue is that when I try to authenticate the user, Symfony returns : no route found for POST /api/login_check.
EDIT
I had put the route in my rest routing file so the resulting route was /api/api/login_check.
Now the error is: Unable to find the controller for path "/api/login_check".
It looks like LexikJWTBundle doesn't intercept the call.
End EDIT
I precise that my api is working fine w/o authentication and uses CORS though NelmioCorsBundle.
Here is my routing.yml portion:
api_login_check:
path: /api/login_check
Here is my config.yml
lexik_jwt_authentication:
private_key_path: %kernel.root_dir%/var/jwt/private.pem # ssh private key path
public_key_path: %kernel.root_dir%/var/jwt/public.pem # ssh public key path
pass_phrase: 'passphrase' # ssh key pass phrase
token_ttl: 86400 # token ttl - defaults to 86400
Here is my security.yml:
# app/config/security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
firewalls:
dev:
pattern: ^/{_{profiler|wdt}}/
security: false
switch_user: true
main:
pattern: .*
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout: true
anonymous: true
switch_user: true
# JWT SETUP
login:
pattern: ^/api/login
stateless: true
anonymous: true
form_login:
check_path: /api/login_check
username_parameter: username
password_parameter: password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
require_previous_session: false
# JWT SETUP
api:
pattern: ^/api
stateless: true
lexik_jwt:
authorization_header:
enabled: true
prefix: Bearer
query_parameter:
enabled: true
name: bearer
access_control:
# JWT SETUP
- { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
Ok I found the issue: the firewall main should be located at the end because all routes maches this pattern and therefore prevent from going through other firewalls.
Stupid mistake again !
Thank you #keyboardSmaher for your help.
Now the security.yml looks like this:
# app/config/security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
firewalls:
dev:
pattern: ^/{_{profiler|wdt}}/
security: false
switch_user: true
api_login:
pattern: ^/api/login
stateless: true
anonymous: true
provider: fos_userbundle
form_login:
check_path: api_login_check
require_previous_session: false
username_parameter: username
password_parameter: password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
api:
pattern: ^/api
stateless: true
provider: fos_userbundle
lexik_jwt: ~
main:
pattern: .*
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout: true
anonymous: true
switch_user: true
# JWT SETUP
# JWT SETUP
role_hierarchy:
ROLE_DELEGATION: [ROLE_USER]
ROLE_EXPORT: [ROLE_USER]
ROLE_USER_ADMIN: [ROLE_USER]
ROLE_LIST_ADMIN: [ROLE_USER]
ROLE_IMPORT: [ROLE_USER]
ROLE_MOBILE: [ROLE_USER]
ROLE_ADMIN: [ROLE_USER, ROLE_ALLOWED_TO_SWITCH]
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ALLOWED_TO_SWITCH]
access_control:
- { path: ^/$, role: ROLE_USER}
# - { path: ^/api, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/contacts, role: ROLE_USER }
- { path: ^/profile, roles: ROLE_USER }
- { path: ^/entites, role: ROLE_USER }
- { path: ^/export, role: ROLE_EXPORT }
- { path: ^/titres, roles: ROLE_ADMIN }
- { path: ^/categories, roles: ROLE_ADMIN }
- { path: ^/services, roles: ROLE_ADMIN }
- { path: ^/groupes, roles: ROLE_ADMIN }
- { path: ^/admin, roles: ROLE_ADMIN }
- { path: ^/imports, roles: ROLE_IMPORT }
- { path: ^/utilisateurs, roles: ROLE_USER_ADMIN }
- { path: ^/register, role: ROLE_SUPER_ADMIN }
- { path: ^/group, roles: ROLE_USER_ADMIN }
# JWT SETUP
- { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
For form log in to work, you need to create the check_path route. The route has to point to an empty controller and it is intercepted by the security system.
Just create an empty controller for /api/login_check and point your api_login_check route to it.
This information is in the documentation below.
Documentation
I am building an app with angularjs frontend and symfony backend with the help of FOSOAuthServerBundle and FOSUserBundles for security.
Registration works fine but logging back in has an issue. When you provide your username/ password, authentication works fine and a token is generated but then a login form is presented to the user again to log in when they try to access a resource using the token.
I know it's a misconfiguration somewhere hoping someone will have the eye to point it our for me ;-)
security.yml
security:
encoders:
AppBundle\Entity\User:
algorithm: sha1
encode_as_base64: false
iterations: 1
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
oauth_token:
pattern: ^/oauth/v2/token
security: false
oauth_authorize:
pattern: ^/oauth/v2/auth
form_login:
provider: fos_userbundle
check_path: _security_check
login_path: _demo_login
anonymous: true
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout: true
anonymous: true
api:
pattern: ^/api
fos_oauth: true
stateless: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
- { path: ^/api, roles: [ IS_AUTHENTICATED_FULLY ] }
config.yml
fos_user:
db_driver: orm
firewall_name: main
user_class: AppBundle\Entity\User
fos_oauth_server:
db_driver: orm
client_class: AppBundle\Entity\Client
access_token_class: AppBundle\Entity\AccessToken
refresh_token_class: AppBundle\Entity\RefreshToken
auth_code_class: AppBundle\Entity\AuthCode
service:
user_provider: fos_user.user_manager
options:
supported_scopes: user