feat: 添加docker配置
parent
69976a67f8
commit
277601fdf9
|
|
@ -0,0 +1,68 @@
|
||||||
|
name: 自动部署
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
paths-ignore:
|
||||||
|
- ".gitignore"
|
||||||
|
- "README.md"
|
||||||
|
- ".vscode/**"
|
||||||
|
|
||||||
|
env:
|
||||||
|
docker_host: ${{ secrets.DOCKER_REGISTRY }}
|
||||||
|
docker_image: ${{ secrets.DOCKER_REGISTRY }}/${{ gitea.repository }}
|
||||||
|
docker_user: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
docker_pass: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
deploy_host: ${{ secrets.DEPLOY_HOSTNAME }}
|
||||||
|
deploy_port: ${{ secrets.DEPLOY_PORT }}
|
||||||
|
deploy_user: ${{ secrets.DEPLOY_USERNAME }}
|
||||||
|
deploy_pass: ${{ secrets.DEPLOY_PASSWORD }}
|
||||||
|
deploy_name: demo_server
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: catthehacker/ubuntu:act-latest
|
||||||
|
steps:
|
||||||
|
- name: 检出代码
|
||||||
|
id: checkout
|
||||||
|
uses: https://gitea.com/actions/checkout@v3
|
||||||
|
|
||||||
|
# - name: 设置环境
|
||||||
|
# uses: https://gitea.com/actions/setup-node@v2
|
||||||
|
|
||||||
|
# - name: 安装依赖
|
||||||
|
# run: |
|
||||||
|
# npm install --registry https://registry.npmmirror.com/
|
||||||
|
|
||||||
|
# - name: 构建产物
|
||||||
|
# run: npm run build
|
||||||
|
|
||||||
|
# - name: 打印目录
|
||||||
|
# run: ls ./dist
|
||||||
|
|
||||||
|
- name: 构建镜像
|
||||||
|
run: |
|
||||||
|
docker build -t ${{ env.docker_image }}:latest .
|
||||||
|
|
||||||
|
- name: 登陆镜像
|
||||||
|
run: |
|
||||||
|
docker login -u "${{env.docker_user}}" -p "${{env.docker_pass}}" ${{env.docker_host}}
|
||||||
|
|
||||||
|
- name: 推送镜像
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
docker push ${{ env.docker_image }}:latest
|
||||||
|
|
||||||
|
- name: 更新服务
|
||||||
|
uses: http://git.dev.juetan.cn/mirror/ssh-action@v1.0.0
|
||||||
|
with:
|
||||||
|
host: ${{ env.deploy_host }}
|
||||||
|
port: ${{ env.deploy_port }}
|
||||||
|
username: ${{ env.deploy_user }}
|
||||||
|
password: ${{ env.deploy_pass }}
|
||||||
|
script: |
|
||||||
|
docker service ls | grep -q ${{ env.deploy_name }} || exit 0
|
||||||
|
docker service update --image ${{ env.docker_image }}:latest ${{ env.deploy_name }}
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
FROM node:18-alpine As development
|
||||||
|
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
|
COPY --chown=node:node package*.json ./
|
||||||
|
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
COPY --chown=node:node . .
|
||||||
|
|
||||||
|
USER node
|
||||||
|
|
||||||
|
FROM node:18-alpine As build
|
||||||
|
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
|
COPY --chown=node:node package*.json ./
|
||||||
|
|
||||||
|
COPY --chown=node:node --from=development /usr/src/app/node_modules ./node_modules
|
||||||
|
|
||||||
|
COPY --chown=node:node . .
|
||||||
|
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
ENV NODE_ENV production
|
||||||
|
|
||||||
|
RUN npm ci --only=production && npm cache clean --force
|
||||||
|
|
||||||
|
USER node
|
||||||
|
|
||||||
|
FROM node:18-alpine As production
|
||||||
|
|
||||||
|
COPY --chown=node:node --from=build /usr/src/app/node_modules ./node_modules
|
||||||
|
COPY --chown=node:node --from=build /usr/src/app/dist ./dist
|
||||||
|
|
||||||
|
CMD [ "node", "dist/main.js" ]
|
||||||
|
|
||||||
Binary file not shown.
571
pnpm-lock.yaml
571
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue