tomcat, Java Spring boot, vueJS integration

main
Yik Teng Hie 5 years ago
parent 90a8eb8260
commit 53af8f6d9e

@ -0,0 +1,129 @@
# Build Dockerfile
* Dockerfile for nodejs app (Size: 250MB)
```sh
FROM node:12-alpine
# Create app directory
WORKDIR /app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN npm install --only=production
# If you are building your code for production
# RUN npm ci --only=production
# Bundle app source
COPY . .
EXPOSE 5009
CMD [ "node", "server.js" ]
```
* use multi-stage (Size: 195MB)
```sh
# in comparison with node:12-alpine image build, this will reduce by further 50MB
# node:12-alpine : 257MB
# multistage alpine:3.12 : 195MB
#
# ------base node------
FROM alpine:3.12 AS base
# install node
RUN apk add --no-cache nodejs nodejs-npm
# Create app directory
WORKDIR /app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
# ------dependencies-------
FROM base AS dependencies
RUN npm install --only=production
# If you are building your code for production
# RUN npm ci --only=production
# copy production node_modules aside
RUN cp -R node_modules prod_node_modules
# -----test------
# add npm run test if needed
# -----release--------
FROM base AS release
# copy production node_modules
COPY --from=dependencies /app/prod_node_modules ./node_modules
# Bundle app source
COPY . .
EXPOSE 5009
CMD [ "node", "server.js" ]
```
* build
```sh
$ docker build [-f Dockerfile] . -t razerpay/visa-backend-api
// push image
$ docker push razerpay/visa-backend-api
```
* run
```sh
$ docker run razerpay/visa-backend-api
// enter shell
$ docker exec -it <container-name> sh
```
* docker-compose
```yaml
version: '2'
services:
api:
image: razerpay/visa-backend-api-multi:latest
#build: .
#command: npm server.js
volumes:
- ./runconfig/default.json:/app/config/default.json
- ./runconfig/ca.crt:/app/config/ca.crt
- ./runconfig/root.crt:/app/config/root.crt
ports:
- "5009:5009"
#depends_on:
# - postgres
#environment:
# DATABASE_URL: postgres://todoapp@postgres/todos
#postgres:
# image: postgres:9.6.2-alpine
# environment:
# POSTGRES_USER: todoapp
# POSTGRES_DB: todos
```
* run docker-compose
```sh
$ docker-compose up -d
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

@ -0,0 +1,42 @@
# Quick Guide for Tomcat
* [Download](https://tomcat.apache.org/download-80.cgi) and install the Tomcat server
* Tomcat management [page](http://localhost:8080/manager)
* ![](./tomcat-manager.PNG)
* Build the java spring boot project `gradle build`. Artifacts in `build\libs\something.war`
* Copy java `something.WAR` file to `C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps\ROOT.war`
* run the server on CLI
```sh
// "jpda" to allow remote attach to debug java code @ port 8000
///
C:\Program Files\Apache Software Foundation\Tomcat 8.5\bin> .\catalina.bat jpda start
```
* Tomcat will extract WAR file to `C:\Program Files\Apache Software Foundation\Tomcat 8.5\ROOT`
* Build vueJS FE `npm run-script build`. Build artifacts will be created under `dist`
* Copy vueJS build artifacts contents `dist` to `C:\Program Files\Apache Software Foundation\Tomcat 8.5\ROOT\WEB-INF\classes\public`
* Reload tomcat to refresh the FE component
* ![](./FE.PNG)
* Now you can access the web from browser
* FE page : `http://localhost:8080`
* BE api : `http://localhost:8080/v1/merchant/...`
# Remote Debugging (IntelliJ)
* Setup remote debugging configuration for
* localhost:8000
* ![](./intelliJ-remotedebug.PNG)
* ![](./tomcat-start.PNG)

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 KiB

Loading…
Cancel
Save