Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker Deployment Example #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@

## front
**/*.lock

TODO
application.properties
.data
51 changes: 51 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
FROM maven:3.8.5-jdk-11-slim AS build

WORKDIR /usr/src/app

RUN apt-get update && apt-get install -y \
nodejs \
npm \
&& rm -rf /var/lib/apt/lists/* \
&& npm install -g yarn

# copy backend files
COPY ./jshERP-boot/src /usr/src/app/jshERP-boot/src
COPY ./jshERP-boot/pom.xml /usr/src/app/jshERP-boot/

# copy frontend files
COPY ./jshERP-web/public /usr/src/app/jshERP-web/public
COPY ./jshERP-web/src /usr/src/app/jshERP-web/src
COPY ./jshERP-web/yarn.lock ./jshERP-web/package.json \
./jshERP-web/vue.config.js ./jshERP-web/babel.config.js \
./jshERP-web/idea.config.js \
/usr/src/app/jshERP-web/

# build backend
RUN cd /usr/src/app/jshERP-boot && \
mvn -N wrapper:wrapper && \
unset MAVEN_CONFIG && \
./mvnw install -DskipTests
RUN mv /usr/src/app/jshERP-boot/target/jshERP.jar /usr/src/app/app.jar

# build frontend
RUN cd /usr/src/app/jshERP-web/ && \
yarn install --pure-lockfile && \
yarn build
RUN mv /usr/src/app/jshERP-web/dist /usr/src/app/web


# app image
FROM openjdk:11-jdk-slim AS app

WORKDIR /usr/src/app

COPY --from=build /usr/src/app/app.jar /usr/src/app/app.jar
CMD ["java", "-jar", "app.jar"]


# web image
FROM nginx:1.20.2-alpine AS web

WORKDIR /usr/src/app

COPY --from=build /usr/src/app/web /usr/share/nginx/html
40 changes: 40 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: "3.7"
services:
app:
build:
context: .
target: app
ports:
- 9999:9999
depends_on:
- db
- redis
volumes:
- ./.data/app:/opt/app
- ./.data/app/logs:/usr/src/app/logs.home_IS_UNDEFINED
- ./docker/application.properties:/usr/src/app/application.properties
web:
build:
context: .
target: web
ports:
- 80:80
depends_on:
- app
volumes:
- ./docker/nginx.conf:/etc/nginx/conf.d/default.conf
db:
image: mysql:5.7
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: pass123
ports:
- 3306:3306
volumes:
- .data/db:/var/lib/mysql
redis:
image: redis:7.0.0-alpine
expose:
- 6379
volumes:
- ./.data/redis:/data
17 changes: 17 additions & 0 deletions docker/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
server {
listen 80;

location / {
root /usr/share/nginx/html/;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}

location /jshERP-boot {
proxy_pass http://app:9999;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
2 changes: 1 addition & 1 deletion jshERP-boot/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
<appender-ref ref="CONSOLE"/>
<appender-ref ref="TIME_FILE"/>
</logger>
</configuration>
</configuration>
7 changes: 5 additions & 2 deletions jshERP-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"parser": "babel-eslint"
},
"rules": {
"template-curly-spacing" : "off",
"generator-star-spacing": "off",
"no-mixed-operators": 0,
"vue/max-attributes-per-line": [
Expand All @@ -88,9 +89,11 @@
"vue/no-use-v-if-with-v-for": 0,
"vue/html-closing-bracket-newline": 0,
"vue/no-parsing-error": 0,
"no-console": 0,
"no-console": 0,
"no-tabs": 0,
"indent": [1, 4]
"indent": ["error", 2, {
"ignoredNodes": ["TemplateLiteral"]
}]
}
},
"postcss": {
Expand Down