【问题标题】:CircleCI reports mkdir successful, but can't find directoryCircleCI 报告 mkdir 成功,但找不到目录
【发布时间】:2020-01-22 23:45:48
【问题描述】:

这里有新的 CircleCI 用户。我一直在努力尝试执行mkdir 命令。或者,更准确地说,是找到命令执行的结果

该步骤在我的工作流程中成功退出,但该文件夹似乎实际上并不存在。我无法在文件系统中的任何位置找到它。

这是我的 config.yml 文件:

# PHP CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-php/ for more details
#
version: 2
jobs:
  build:
    branches:
      only:
        - staging
    working_directory: ~/build
    docker:
      - image: circleci/php:7.2-node-browsers

    steps:
      - checkout

      - run: 
          name: APT Installs (ZIP, PDO, MySQL, Composer)
          command: |        
            sudo docker-php-ext-install zip
            sudo docker-php-ext-install pdo pdo_mysql
            sudo apt-get install software-properties-common
            sudo composer self-update

      - run: 
          name: Install Python and PIP
          command: |
            sudo apt-get install -y python3.7
            sudo apt install -y python3-pip
            sudo pip3 install --upgrade pip
            sudo pip3 install --upgrade awscli
            sudo pip3 install --upgrade awsebcli

      - run:
          name: Create Image Directory (if not exists)
          command: |            
            sudo mkdir -m 0755 -p /var/user_image
            ls -l /var/user_image

      - run:
          name: Setup AWS credentials
          command: |
            mkdir ~/.aws && printf "[profile eb-cli]\naws_access_key_id = $REDACTED\naws_secret_access_key = $REDACTED" > ~/.aws/config

      - deploy:
          name: Deploy to Elastic Beanstalk
          command: |
            eb deploy PixapadTest-env

      # Download and cache dependencies
      - restore_cache:
          keys:
            # "composer.lock" can be used if it is committed to the repo
            - v1-dependencies-{{ checksum "composer.json" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-      

      - restore_cache:
          keys:
            - node-v1-{{ checksum "package.json" }}
            - node-v1-

      - run: 
          name: Install app dependencies
          command: |       
            composer install -n --prefer-dist

      - save_cache:
          key: v1-dependencies-{{ checksum "composer.json" }}
          paths:
            - ./vendor

      - run:
          name: Database Setup
          command: |
            vendor/bin/phinx migrate -e staging

这是最近成功的工作流程的屏幕截图:

我哪里错了?

编辑 #1: 在 CircleCI 用户的建议下,我将 ls -l /var/user_image 添加到我的 config.yml 中,就在 sudo mkdir -m 0755 -p /var/user_image 下方。工作流步骤输出以下内容:

没有错误,但我仍然找不到目录。我怀疑此时它正在被某个进程删除...我只是不确定为什么。

编辑 #2: 更新为完整的 config.yml。

【问题讨论】:

  • 如何检查目录是否存在?
  • 使用sudo find /var/user_imagesudo find *user_image* 以及手动打开文件夹和使用ll。此外,在 CircleCI 用户的推荐下,我在我的 config.yml 中添加了ls -l /var/user_image。它输出“total 0”而没有错误。该文件夹似乎已创建,但可能在某个时候被删除。
  • 我们需要查看更多配置或构建链接,以了解发生了什么。我运行了您的配置的简化版本,它对我来说很好用。 circleci.com/gh/felicianotech/cci-testing-pub/927
  • 太棒了!更新。感谢您的观看!
  • 嗯,刚上床我就有了一个启示。我正在寻找生产箱上的文件夹,同时告诉 CircleCI 在容器中创建它。哦!如果它在我的 Elastic Beanstalk 实例中不存在,我只需要弄清楚如何创建它。

标签: ubuntu circleci amazon-linux


【解决方案1】:

最后,我把这个复杂化了并且误解了这个过程。

我的目标是在我的应用程序服务器上创建一个目录,该目录托管在 Elastic Beanstalk 中。虽然我想在服务器上创建目录,但我在 config.yml 文件中使用的命令正在容器中创建目录。 CircleCI 表现得非常好。我没有!

相反,我只需将命令添加到位于我的 .ebextensions 源文件夹中的配置文件中。

这是 .ebextensions 文件夹中的完整配置文件,供遇到此问题的任何人使用。

files:
    "/root/.ssh/config":
        owner: root
        group: root
        mode: "000600"
        content: |
            Host github.com
                User git
                Hostname github.com
                IdentityFile /root/.ssh/battlestardigitalbot-github-deploy
    "/root/.ssh/known_hosts":
        owner: root
        group: root
        mode: "000644"
        content: |
            [REDACTED]


commands:
    01-command:
        command: sudo aws s3 cp s3://battlestar-deployment-key/battlestardigitalbot-github-deploy /root/.ssh
    02-command:
        command: sudo chmod 600 /root/.ssh/battlestardigitalbot-github-deploy
    03-command:
        command: sudo mkdir -m 0755 -p /var/user_image

特别感谢FelicianoTech,他们耐心的问题最终让我有些摸不着头脑!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-02
    • 2015-12-25
    • 1970-01-01
    • 2016-08-24
    • 1970-01-01
    相关资源
    最近更新 更多