我正在使用 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 在服务器上成功启动
我发现这个问题经常是由于工作文件夹不正确而发生的,但就我而言,一切都应该没问题。
- name: Checkout code
uses: actions/checkout@v3
- 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