Sign inSign up

ferdous/flyaway

By ferdous

Updated almost 6 years ago

# flyaway Journalism Without Fear or Favour

Image
1

50K+

ferdous/flyaway repository overview

flyaway

This application was generated using JHipster 6.7.1, you can find documentation and help at https://www.jhipster.tech/documentation-archive/v6.7.1.

This is a "gateway" application intended to be part of a microservice architecture, please refer to the Doing microservices with JHipster page of the documentation for more information.

This application is configured for Service Discovery and Configuration with the JHipster-Registry. On launch, it will refuse to start if it is not able to connect to the JHipster-Registry at http://localhost:8761. For more information, read our documentation on Service Discovery and Configuration with the JHipster-Registry.

Development

Before you can build this project, you must install and configure the following dependencies on your machine:

  1. Node.js: We use Node to run a development web server and build the project. Depending on your system, you can install Node either from source or as a pre-packaged bundle.
  2. Yarn: We use Yarn to manage Node dependencies. Depending on your system, you can install Yarn either from source or as a pre-packaged bundle.

After installing Node, you should be able to run the following command to install development tools. You will only need to run this command when dependencies change in package.json.

yarn install

We use yarn scripts and Webpack as our build system.

Run the following commands in two separate terminals to create a blissful development experience where your browser auto-refreshes when files change on your hard drive.

./mvnw
yarn start

Yarn is also used to manage CSS and JavaScript dependencies used in this application. You can upgrade dependencies by specifying a newer version in package.json. You can also run yarn update and yarn install to manage dependencies. Add the help flag on any command to see how you can use it. For example, yarn help update.

The yarn run command will list all of the scripts available to run for this project.

OAuth 2.0 / OpenID Connect

Congratulations! You've selected an excellent way to secure your JHipster application. If you're not sure what OAuth and OpenID Connect (OIDC) are, please see What the Heck is OAuth?

To log in to your app, you'll need to have Keycloak up and running. The JHipster Team has created a Docker container for you that has the default users and roles. Start Keycloak using the following command.

docker-compose -f src/main/docker/keycloak.yml up

The security settings in src/main/resources/config/application.yml are configured for this image.

spring:
  ...
  security:
    oauth2:
      client:
        provider:
          oidc:
            issuer-uri: http://localhost:9080/auth/realms/jhipster
        registration:
          oidc:
            client-id: web_app
            client-secret: web_app
Okta

If you'd like to use Okta instead of Keycloak, you'll need to change a few things. First, you'll need to create a free developer account at https://developer.okta.com/signup/. After doing so, you'll get your own Okta domain, that has a name like https://dev-123456.okta.com.

Modify src/main/resources/config/application.yml to use your Okta settings.

spring:
  ...
  security:
    oauth2:
      client:
        provider:
          oidc:
            issuer-uri: https://{yourOktaDomain}/oauth2/default
        registration:
          oidc:
            client-id: {clientId}
            client-secret: {clientSecret}
security:

Create an OIDC App in Okta to get a {clientId} and {clientSecret}. To do this, log in to your Okta Developer account and navigate to Applications > Add Application. Click Web and click the Next button. Give the app a name you’ll remember, specify http://localhost:8080 as a Base URI, and http://localhost:8080/login/oauth2/code/oidc as a Login Redirect URI. Click Done, then Edit and add http://localhost:8080 as a Logout redirect URI. Copy and paste the client ID and secret into your application.yml file.

Create a ROLE_ADMIN and ROLE_USER group and add users into them. Modify e2e tests to use this account when running integration tests. You'll need to change credentials in src/test/javascript/e2e/account/account.spec.ts and src/test/javascript/e2e/admin/administration.spec.ts.

Navigate to API > Authorization Servers, click the Authorization Servers tab and edit the default one. Click the Claims tab and Add Claim. Name it "groups", and include it in the ID Token. Set the value type to "Groups" and set the filter to be a Regex of .*.

After making these changes, you should be good to go! If you have any issues, please post them to Stack Overflow. Make sure to tag your question with "jhipster" and "okta".

PWA Support

JHipster ships with PWA (Progressive Web App) support, and it's turned off by default. One of the main components of a PWA is a service worker.

The service worker initialization code is commented out by default. To enable it, uncomment the following code in src/main/webapp/index.html:

<script>
  if ('serviceWorker' in navigator) {
    navigator.serviceWorker.register('./service-worker.js').then(function() {
      console.log('Service Worker Registered');
    });
  }
</script>

Note: Workbox powers JHipster's service worker. It dynamically generates the service-worker.js file.

Managing dependencies

For example, to add Leaflet library as a runtime dependency of your application, you would run following command:

yarn add --exact leaflet

To benefit from TypeScript type definitions from DefinitelyTyped repository in development, you would run following command:

yarn add --dev --exact @types/leaflet

Then you would import the JS and CSS files specified in library's installation instructions so that Webpack knows about them: Note: There are still a few other things remaining to do for Leaflet that we won't detail here.

For further instructions on how to develop with JHipster, have a look at Using JHipster in development.

Building for production

Packaging as jar

To build the final jar and optimize the flyaway application for production, run:

./mvnw -Pprod clean verify

This will concatenate and minify the client CSS and JavaScript files. It will also modify index.html so it references these new files. To ensure everything worked, run:

java -jar target/*.jar

Then navigate to http://localhost:8080 in your browser.

Refer to Using JHipster in production for more details.

Packaging as war

To package your application as a war in order to deploy it to an application server, run:

./mvnw -Pprod,war clean verify

Testing

To launch your application's tests, run:

./mvnw verify
Client tests

Unit tests are run by Jest and written with Jasmine. They're located in src/test/javascript/ and can be run with:

yarn test

For more information, refer to the Running tests page.

Code quality

Sonar is used to analyse code quality. You can start a local Sonar server (accessible on http://localhost:9001) with:

docker-compose -f src/main/docker/sonar.yml up -d

You can run a Sonar analysis with using the sonar-scanner or by using the maven plugin.

Then, run a Sonar analysis:

./mvnw -Pprod clean verify sonar:sonar

If you need to re-run the Sonar phase, please be sure to specify at least the initialize phase since Sonar properties are loaded from the sonar-project.properties file.

./mvnw initialize sonar:sonar

or

For more information, refer to the Code quality page.

Using Docker to simplify development (optional)

You can use Docker to improve your JHipster development experience. A number of docker-compose configuration are available in the src/main/docker folder to launch required third party services.

For example, to start a postgresql database in a docker container, run:

docker-compose -f src/main/docker/postgresql.yml up -d

To stop it and remove the container, run:

docker-compose -f src/main/docker/postgresql.yml down

You can also fully dockerize your application and all the services that it depends on. To achieve this, first build a docker image of your app by running:

./mvnw -Pprod verify jib:dockerBuild

Then run:

docker-compose -f src/main/docker/app.yml up -d

For more information refer to Using Docker and Docker-Compose, this page also contains information on the docker-compose sub-generator (jhipster docker-compose), which is able to generate docker configurations for one or several JHipster applications.

Continuous Integration (optional)

To configure CI for your project, run the ci-cd sub-generator (jhipster ci-cd), this will let you generate configuration files for a number of Continuous Integration systems. Consult the Setting up Continuous Integration page for more information.

Regenerate Entities

jhipster enitity Answer --regenerate
jhipster enitity Attachment --regenerate
jhipster enitity Author --regenerate
jhipster enitity Category --regenerate
jhipster enitity City --regenerate
jhipster enitity Comment --regenerate
jhipster enitity Country --regenerate
jhipster enitity Department --regenerate
jhipster enitity District --regenerate
jhipster enitity Division --regenerate
jhipster enitity FlatPage --regenerate
jhipster enitity Gallery --regenerate
jhipster enitity Layout --regenerate
jhipster enitity Location --regenerate
jhipster enitity Magazine --regenerate
jhipster enitity Meta --regenerate
jhipster enitity News --regenerate
jhipster enitity NewsOption --regenerate
jhipster enitity Poll --regenerate
jhipster enitity Profile --regenerate
jhipster enitity Question --regenerate
jhipster enitity Quote --regenerate
jhipster enitity Region --regenerate
jhipster enitity Section --regenerate
jhipster enitity SocialLink --regenerate
jhipster enitity Tag --regenerate
jhipster enitity Upazilla --regenerate
jhipster enitity WebForm --regenerate

Export h2 table to csv

CALL CSVWRITE ('/Users/ferdous/Downloads/author.csv', 'SELECT * FROM AUTHOR  ORDER BY ID');

Use the following command to see all kafka topics:

kafka-topics.sh --bootstrap-server localhost:9092 --list

Create kafka topics

You may create required kafka topics using the following commands:

kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic topic_flyaway

Describe a topic

kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic topic_flyaway
kafka-topics.sh --zookeeper localhost:2181 --alter --topic topic_flyaway --config retention.ms=1000

Delete a topic

kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic topic_flyaway

Recreate topic

kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic topic_flyaway kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic topic_flyaway

Show last 5 messages using kafkacat please install kafkacat from here https://github.com/edenhill/kafkacat

kafkacat -C -b localhost:9092 -t topic_flyaway -p 0 -o -5 -e

export JAVA_OPTS=-Xmx4G

Kubernetes configuration

Preparation

You will need to push your image to a registry. If you have not done so, use the following commands to tag and push the images:

$ docker image tag flyaway ferdous/flyaway
$ docker push ferdous/flyaway

Deployment

You can deploy all your apps by running the below bash command:

./kubectl-apply.sh

Exploring your services

Use these commands to find your application's IP addresses:

$ kubectl get svc flyaway

Scaling your deployments

You can scale your apps using

$ kubectl scale deployment <app-name> --replicas <replica-count>

zero-downtime deployments

The default way to update a running app in kubernetes, is to deploy a new image tag to your docker registry and then deploy it using

$ kubectl set image deployment/<app-name>-app <app-name>=<new-image>

Using livenessProbes and readinessProbe allow you to tell Kubernetes about the state of your applications, in order to ensure availablity of your services. You will need minimum 2 replicas for every application deployment if you want to have zero-downtime deployed. This is because the rolling upgrade strategy first stops a running replica in order to place a new. Running only one replica, will cause a short downtime during upgrades.

Monitoring tools

JHipster console

Your application logs can be found in JHipster console (powered by Kibana). You can find its service details by

$ kubectl get svc jhipster-console
  • If you have chosen Ingress, then you should be able to access Kibana using the given ingress domain.
  • If you have chosen NodePort, then point your browser to an IP of any of your nodes and use the node port described in the output.
  • If you have chosen LoadBalancer, then use the IaaS provided LB IP

JHipster registry

The registry is deployed using a headless service in kubernetes, so the primary service has no IP address, and cannot get a node port. You can create a secondary service for any type, using:

$ kubectl expose service jhipster-registry --type=NodePort --name=exposed-registry

and explore the details using

$ kubectl get svc exposed-registry

For scaling the JHipster registry, use

$ kubectl scale statefulset jhipster-registry --replicas 3

Troubleshooting

my apps doesn't get pulled, because of 'imagePullBackof'

Check the docker registry your Kubernetes cluster is accessing. If you are using a private registry, you should add it to your namespace by kubectl create secret docker-registry (check the docs for more info)

my applications are stopped, before they can boot up

This can occur if your cluster has low resource (e.g. Minikube). Increase the initialDelaySeconds value of livenessProbe of your deployments

my applications are starting very slow, despite I have a cluster with many resources

The default setting are optimized for middle-scale clusters. You are free to increase the JAVA_OPTS environment variable, and resource requests and limits to improve the performance. Be careful!

WARNING! You will need to push your image to a registry. If you have not done so, use the following commands to tag and push the images: docker image tag flyaway ferdous/flyaway docker push ferdous/flyaway

INFO! Alternatively, you can use Jib to build and push image directly to a remote registry: ./mvnw -ntp -Pprod verify jib:build -Djib.to.image=ferdous/flyaway in /home/star/src/gateway

You can deploy all your apps by running the following script: bash kubectl-apply.sh

Use these commands to find your application's IP addresses: kubectl get svc flyaway -n tds

Tag summary

Content type

Image

Digest

Size

213.3 MB

Last updated

almost 6 years ago

docker pull ferdous/flyaway