英文:
Circleci is not copying hidden files from repository while building
问题
我正在使用CircleCI来构建和测试TypeScript代码。当代码被推送并且CircleCI开始在Docker容器中构建时,我注意到它在复制到容器时忽略了一些存储库中的隐藏文件(点文件)。我通过在一个步骤中添加ls
命令来确保这一点。如何使CircleCI在复制其余代码文件的同时复制.env
文件从代码存储库中?
.circleci/config.yml
version: 2 # 使用CircleCI 2.0
jobs: # 步骤的集合
build: # 不使用工作流的运行必须具有`build`作业作为入口点
working_directory: ~/su-app-api # 步骤将运行的目录
docker: # 使用Docker运行步骤
- image: node:16-alpine3.16
steps: # 可执行命令的集合
- checkout # 特殊步骤,将源代码检出到工作目录
- add_ssh_keys:
fingerprints:
- "我的指纹"
- run:
name: ls
command: ls -al && ls api -al
- run:
name: 安装API依赖项
command: npm i
- run:
name: 构建API
command: npm run build:api
- run:
name: 测试API
command: npm run test
- deploy:
name: 部署
command: ssh -o "StrictHostKeyChecking no" user_name@ip "cd ~/su-app-api && git pull origin deploy && sh deploy.sh"
英文:
I am using Circleci to build and test typescript code. when code is pushed and Circleci starts building in a docker container, I noticed it ignores some hidden files (dot files) in the repository while copying to the container. I ensured that by adding ls
command in one of steps. How to make Circleci copy .env
from the code repository while copying the rest of the code files?
.circleci/config.yml
version: 2 # use CircleCI 2.0
jobs: # a collection of steps
build: # runs not using Workflows must have a `build` job as entry point
working_directory: ~/su-app-api # directory where steps will run
docker: # run the steps with Docker
- image: node:16-alpine3.16
steps: # a collection of executable commands
- checkout # special step to check out source code to working directory
- add_ssh_keys:
fingerprints:
- "my finger print"
- run:
name: ls
command: ls -al && ls api -al
- run:
name: Install API Dependencies
command: npm i
- run:
name: Build API
command: npm run build:api
- run:
name: Test API
command: npm run test
- deploy:
name: deployment
command: ssh -o "StrictHostKeyChecking no" user_name@ip "cd ~/su-app-api && git pull origin deploy && sh deploy.sh"
答案1
得分: 1
我找到了问题。我正在使用node-alpine
镜像,该镜像没有安装shh-client或git。结果,在Circleci中的检出步骤中,它会回退到CircleCI的本机git客户端[¹][¹],但行为可能与官方git不同。
我添加了一个步骤,在检出步骤之前安装ssh和git,然后它正常工作了。
- run:
name: 安装ssh和git
command: apk add --update openssh-client git
[¹]: https://support.circleci.com/hc/en-us/articles/360046718853-Checkout-Code-Step-Outputs-Either-git-or-ssh-required-by-git-to-clone-through-SSH-is-Not-Installed-in-the-Image- 'CircleCI支持中心:使用CircleCI:构建项目:检出代码步骤输出"未在镜像中安装git或ssh(git通过SSH克隆所需)"; 由Mike于2022年7月27日23:04发布'。
英文:
I found the problem. I was using the node-alpine
image which has no shh-client or git installed. As a result, the checkout step in Circleci was falling back to CircleCI's native git client[¹][¹] but the behavior may be different from official git.
I added a step to install ssh and git before the checkout step and it worked normally.
- run:
name: install ssh and git
command: apk add --update openssh-client git
¹ [Checkout Code Step Outputs "Either git or ssh (required by git to clone through SSH) is Not Installed in the Image"][¹]
[¹]: https://support.circleci.com/hc/en-us/articles/360046718853-Checkout-Code-Step-Outputs-Either-git-or-ssh-required-by-git-to-clone-through-SSH-is-Not-Installed-in-the-Image- 'CircleCI Support Center: Using CircleCI: Building Projects: Checkout Code Step Outputs "Either git or ssh (required by git to clone through SSH) is Not Installed in the Image"; by Mike July 27, 2022 23:04'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论