k3s 中使用 Argo CD 部署的问题:npm error Missing script: "start"

问题描述 投票:0回答:1

我正在使用 argo cd 部署在带有 k3s 的服务器上。我需要部署的映像在我的 k8s 设备上本地运行良好。但不是在带有 k3s 的服务器上。

我的 Dockerfile:

FROM node:alpine

WORKDIR /app
COPY package.json .
RUN npm install --only=prod
COPY . .

CMD ["npm", "start"]

部署文件:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: auth
  template:
    metadata:
      labels:
        app: auth 
    spec:
      containers:
        - name: auth 
          image: My-username/auth
          env:
            - name: JWT_KEY
              valueFrom:
                secretKeyRef:
                  name: some-secret
                  key: JWT_KEY
            - name: MONGO_URI
              value: 'some-value'

我的package.json

...
 "scripts": {
    "start": "ts-node-dev src/index.ts",
    "test": "jest --watchAll --no-cache",
    "test:ci": "jest"
  },
...

但是我在 argo cd 界面中看到一个错误:

npm error Missing script: "start"
npm error
npm error Did you mean one of these?
npm error   npm star # Mark your favorite packages
npm error   npm stars # View packages marked as favorites
npm error
npm error To see a list of scripts, run:
npm error   npm run
npm error A complete log of this run can be found in: /root/.npm_logs/2024-05-25T20_23_24_072Z-debug-0.log

该图像是使用 GitHub Actions 构建的

name: deploy-auth

on:
  push:
    branches:
      - main
    paths:
      - 'auth/**'

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v3
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      -
        name: Login to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      -
        name: Build and push
        uses: docker/build-push-action@v5
        with:
          push: true
          file: auth/Dockerfile
          tags: My-username/auth:latest
          platforms: linux/amd64

此外,如果我在本地设备上创建图像,该图像会使用 Argo cd 在服务器上成功启动

我发现这个问题经常是由于工作文件夹不正确而发生的,但就我而言,一切都应该没问题。

node.js docker kubernetes argocd k3s
1个回答
0
投票
  1. 尝试添加签出作为第一步,这是复制存储库所必需的:
- name: Checkout code
  uses: actions/checkout@v3
  1. 在 build-push-action 参数中,您应该指定上下文:
- name: Build and push
  uses: docker/build-push-action@v5
  with:
    push: true
    context: ./auth
    file: ./auth/Dockerfile
    tags: your-docker-account-name/auth:latest
© www.soinside.com 2019 - 2024. All rights reserved.