首页 > 数据库 >asp.netcore8 + vue3 + mysql 自用记账项目(四)项目部署

asp.netcore8 + vue3 + mysql 自用记账项目(四)项目部署

时间:2024-09-11 12:04:07浏览次数:1  
标签:asp IP app netcore8 nginx api vue3 docker bookkeeping

一、生成后台api服务

 1、在系统生成的Dockerfile基础上,添加时区标识

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
ENV TZ Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["Bookkeeping_API.csproj", "."]
RUN dotnet restore "./Bookkeeping_API.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "Bookkeeping_API.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Bookkeeping_API.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Bookkeeping_API.dll"]

2、docker-compose文件

services:
  bookkeeping_api:
    image: ${REGISTRY:-test}/bookkeeping_api:${PLATFORM:-linux}-${TAG:-v20240910-01}
    container_name: bookkeeping_api
    restart: always
    environment:
      - ASPNETCORE_ENVIRONMENT=Production
      - ASPNETCORE_URLS=https://+:443;http://+:80
      - ClientCredentialsUserOptions__Authority=http://IP:8001
      - SeqServerUrl=http://seq
      - ConnectionString=server=mysql8;port=3306;database=Bookkeeping;uid=root;pwd=密码;charset=utf8;
      - HttpsCert__PemPath=/app/Certs/IP+1.pem
      - HttpsCert__PrivateKeyPath=/app/Certs/IP+1-key.pem
    ports:
      - "8001:80"
    volumes:
      - /root/ssl/IP+1.pem:/app/Certs/IP+1.pem
      - /root/ssl/IP+1-key.pem:/app/Certs/IP+1-key.pem
    networks:  
      - data_net
 
networks:  
  data_net:  
    external: true

3、生成发布镜像

  由于服务器太小,不适合安装k8s等工具,故使用原始方法。

  1)本地生成镜像

进入目录:cd "D:\VS2019\Git\我的项目\Bookkeeping_API"
构建镜像:docker-compose build
镜像打包成压缩文件:docker save -o D:/系统发布/bookkeeping_api.tar test/bookkeeping_api:linux-v20240910-01
将压缩文件传入服务器:scp D:/系统发布/bookkeeping_api.tar root@IP:/root/bookkeeping_api.tar 

  2)服务器发布

解压镜像:docker load -i bookkeeping_api.tar
修改文件:vim docker-compose.bookkeeping_api.yml
验证文件是否正确修改:cat docker-compose.bookkeeping_api.yml
停用旧容器:docker-compose -f docker-compose.bookkeeping_api.yml down
启动新服务:docker-compose -f docker-compose.bookkeeping_api.yml up -d
查看容器是否正常运行:docker ps -a

二、基于nginx生成vue镜像

1、打包前,保证打包系统内有nginx镜像,然后build当前vue项目

npm run build

2、构建文件Dockerfile

FROM nginx

# 将本地的 dist 文件夹复制到 nginx 默认的静态文件目录
COPY ./dist /usr/share/nginx/html
# COPY ./index.html /usr/share/nginx/html/index.html

# 暴露 Nginx 默认端囗
EXPOSE 80

# 启动 Nginx 服务
CMD ["nginx","-g","daemon off;"]

3、基于nginx镜像,所以有其功能,配置文件my-vue-app.conf

user  nginx;
worker_processes  auto;
error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    server {
        listen       8002;
        server_name  IP; # 修改为docker服务宿主机的ip
    
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }

        location /api{
            proxy_pass http://IP:8001;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
		}
    }
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
    include /etc/nginx/conf.d/*.conf;
}

4、服务启动文件docker-compose.vue.yml

services:
  # Vue演示服务
  my_vue_app:
    image: my_vue_app:20240724
    container_name: my_vue_app
    restart: unless-stopped
    ports:
      - "8002:80"  # 将主机端口 8080 映射到容器端口 80
    volumes: 
      - /root/my-vue-app.conf:/etc/nginx/nginx.conf

 5、后续操作同后台api发布,最终效果如下图

标签:asp,IP,app,netcore8,nginx,api,vue3,docker,bookkeeping
From: https://www.cnblogs.com/lx-bk/p/18398883

相关文章

  • asp.netcore8 + vue3 + mysql 自用记账项目(二)环境搭建
    一、vue1、node.js安装安装node.js的攻略网上有很多,这里就不多做赘述,安装完成后,验证是否正常然后就是配置淘宝镜像加速,配置环境变量等操作。2、vue安装上面安装完node.js之后,就可以安装vue环境了,网上同样很多,需要注意的是,vue安装完成了,最好将webpack模版、vue-cli、vue-rout......
  • asp.netcore8 + vue3 + mysql 自用记账项目(三)功能开发
    一、前端前端使用vue3+vant4组件实现页面功能。 1、创建vue3项目各个操作分别是:选择创建模式?手动创建选择项目模块?Babel,Kouter,Wuex,CSSPreprocessors选择vue版本?3.0是否使用历史路由模式?是样式的写法?Less项目配置放在哪?package.json文件里是否保存本次......
  • asp.netcore8 + vue3 + mysql 自用记账项目(一)背景简介
    一、背景18年的时候,用了一年多第三方免费的记账本不用了,两个方面原因,一是随着数据增多,APP用着越来越慢,二是相关数据被用于其他用途的风险很大且广告很烦。所以,后面通过MUI+asp.netcore+sqlserver实现记账web功能,在阿里云1核2G服务器的windows系统上发布了自用的服务,最......
  • vue3 中使用 icon 图标的 3 种方案
    1.element-iconElementPlus提供了一套常用的图标集合。1.1.安装#选择一个你喜欢的包管理器#NPM$npminstall@element-plus/icons-vue#Yarn$yarnadd@element-plus/icons-vue#pnpm$pnpminstall@element-plus/icons-vue#选择一个你喜欢的包管理器1.2.......
  • 使用Vue3.5的onWatcherCleanup封装自动cancel的fetch函数
    前言在欧阳的上一篇这应该是全网最详细的Vue3.5版本解读文章中有不少同学对Vue3.5新增的onWatcherCleanup有点疑惑,这个新增的API好像和watchAPI回调的第三个参数onCleanup功能好像重复了。今天这篇文章来讲讲新增的onWatcherCleanup函数的使用场景:封装一个自动cancel的fetch函......
  • 使用VSCode搭建UniApp + TS + Vue3 + Vite项目
    uniapp是一个使用Vue.js开发所有前端应用的框架,开发者编写一套代码,可发布到iOS、Android、以及各种小程序。深受广大前端开发者的喜爱。uniapp官方也提供了自己的IDE工具HBuilderX,可以快速开发uniapp项目。但是很多前端的同学已经比较习惯使用VSCode去开发项目,为了开发uniapp项目......
  • 学习Vue3的第三天
    Vue3生命周期概念:生命周期钩子是Vue组件在其生命周期内不同阶段触发的函数,允许开发者在这些关键时刻插入自定义逻辑。规律:生命周期整体分为四个阶段,分别是:创建、挂载、更新、销毁,每个阶段都有两个钩子,一前一后。Vue2生命周期钩子创建阶段beforeCreate:组件实例刚创......
  • vue3 内置特殊元素<slot> 与 插槽 Slots
    vue官网内置特殊元素<slot>插槽Slots<slot><slot>元素是一个插槽出口(slotoutlet),标示了父元素提供的插槽内容(slotcontent)将在哪里被渲染。Vue模板里的<slot>元素会被编译到JavaScript,因此不要与原生<slot>元素进行混淆。<slot>元素可以使用nameat......
  • vue3快速上手和基本特性
    1)vue使用方式1)cdn方式    该方式无需使用包管理工具,只要用script标签引入js文件即可,可以快速使用vue<scriptsrc="https://unpkg.com/vue@3/dist/vue.global.js"></script>2)创建vue项目    创建vue项目时需要nodejs环境,安装好nodejs后先为nodejs换一个国......
  • 【卷起来】VUE3.0教程-05-侦听器
    =========各位看官,在开始学习之前,请帮我点个关注和赞吧========== ......