简体   繁体   English

Gitlab CI/CD 管道给出 Dockerfile 错误

[英]Gitlab CI/CD pipeline giving Dockerfile error

Good Evening, I am trying to deploy my nodeJS app to my Digital Ocean Server and its saying it cant find my Dockerfile.晚上好,我正在尝试将我的 nodeJS 应用程序部署到我的 Digital Ocean 服务器,它说它找不到我的 Dockerfile。 I did check and the Dockerfile does not have a.txt extension.我确实检查了 Dockerfile 没有.txt 扩展名。 Any guidance is appreciated.任何指导表示赞赏。 I have my variables set in my Gitlab project.我在 Gitlab 项目中设置了变量。 The pipeline throws the below error: "$ chmod og= $ID_RSA chmod: unrecognized option: ---BEGIN BusyBox v1.31.1 () multi-call binary. Usage: chmod [-Rcvf] MODE[,MODE]... FILE... Each MODE is one or more of the letters ugoa, one of the symbols +-= and one or more of the letters rwxst -R Recurse -c List changed files -v List all files -f Hide errors"管道抛出以下错误:“$ chmod og= $ID_RSA chmod: unrecognized option: ---BEGIN BusyBox v1.31.1 () multi-call binary. Usage: chmod [-Rcvf] MODE[,MODE]... FILE ... 每个 MODE 是一个或多个字母 ugoa、一个符号 +-= 和一个或多个字母 rwxst -R 递归 -c 列出更改的文件 -v 列出所有文件 -f 隐藏错误”

 stages: - build - publish - deploy variables: TAG_LATEST: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:latest TAG_COMMIT: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:$CI_COMMIT_SHORT_SHA build: image: node:latest stage: build script: - npm install - echo "ACCOUNT_SID=$ACCOUNT_SID" >>.env - echo "AUTH_TOKEN=$AUTH_TOKEN" >>.env - echo "API_KEY=$API_KEY" >>.env - echo "API_SECRET=$API_SECRET" >>.env - echo "PHONE_NUMBER=$PHONE_NUMBER" >>.env - echo "sengrid_api=$sengrid_api" >>.env publish: image: docker:latest stage: publish services: - docker:dind script: - docker build. -t $TAG_COMMIT -t $TAG_LATEST - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY - docker push $TAG_COMMIT - docker push $TAG_LATEST deploy: image: alpine:latest stage: deploy tags: - deployment script: - chmod og= $ID_RSA - apk update && apk add openssh-client - ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY" - ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker pull $TAG_COMMIT" - ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker container rm -f my-app || true" - ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker run -d -p 80:3000 --name my-app $TAG_COMMIT" environment: name: production url: http://167.172.225.124 only: - master

Check first if the docker build argument order is correct:首先检查docker 构建参数顺序是否正确:

Instead of:代替:

docker build -t $TAG_COMMIT -t $TAG_LATEST .

I would try:我会尝试:

docker build . -t $TAG_COMMIT -t $TAG_LATEST

Check also you are in the right path when you are running this build command.当您运行此构建命令时,还要检查您是否处于正确的路径中。
And that there is a file named Dockerfile (the default name needed by docker build ).并且有一个名为Dockerfile的文件( docker build所需的默认名称)。


Regarding the error:关于错误:

chmod og= $ID_RSA 
chmod: unrecognized option: ---BEGIN

You need to apply chmod on a file, not on a file content .您需要将chmod应用于文件,而不是文件内容
The variable ID_RSA includes the key itself, not the key filename.变量ID_RSA包括密钥本身,而不是密钥文件名。

Use ~/.ssh/id_rsa instead of $ID_RSA .使用~/.ssh/id_rsa而不是$ID_RSA

If you have followed this tutorial as I do (which looks to be the case), It looks the tutorial assumes to run on the master branch, protected.如果您像我一样遵循本教程(看起来就是这种情况),看起来本教程假定在主分支上运行,受保护。

I was running on another branch not protected.我在另一个不受保护的分支上运行。 So I had to unprotect all variables to work on unprotected branches.所以我必须取消保护所有变量才能在不受保护的分支上工作。 The job succeeds immediately.作业立即成功。

Make sure your ID_RSA variable is Type: file确保您的 ID_RSA 变量是类型:文件

chmod og= $ID_RSA 

For me it didn't work because i copied key without breakline symbol in the end,it turned out that is important.对我来说它不起作用,因为我最后复制了没有断线符号的密钥,结果证明这很重要。 Tried many solutions, spent almost a day before i got this /.尝试了很多解决方案,在我得到这个 / 之前花了将近一天的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM