Bitbucket 管道设置中的缓存步骤

时间:2021-04-04 08:27:31

标签: docker bitbucket bitbucket-pipelines

我的 bitbucket 管道如下。

pipelines:
  branches:
    master:
      - step:
          script:
            - apt-get update
            - apt-get install -y zip
            - zip -r web.zip .
            - pipe: atlassian/aws-code-deploy:0.2.5

当它在 bitbucket 管道上运行时,我可以看到它总是下载 docker 映像并在每次部署时执行相同的操作,有没有办法在管道中缓存以下步骤?

pipe: atlassian/aws-code-deploy:0.2.5
2s
+ docker container run \
   --volume=/opt/atlassian/pipelines/agent/build:/opt/atlassian/pipelines/agent/build \
   --volume=/opt/atlassian/pipelines/agent/ssh:/opt/atlassian/pipelines/agent/ssh:ro \
   --volume=/usr/local/bin/docker:/usr/local/bin/docker:ro \
   --volume=/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes:/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes \
   --volume=/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes/atlassian/aws-code-deploy:/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes/atlassian/aws-code-deploy \
   --workdir=$(pwd) \
   --label=org.bitbucket.pipelines.system=true \
   --env=BITBUCKET_STEP_TRIGGERER_UUID="$BITBUCKET_STEP_TRIGGERER_UUID" \
   --env=BITBUCKET_REPO_FULL_NAME="$BITBUCKET_REPO_FULL_NAME" \
   --env=BITBUCKET_GIT_HTTP_ORIGIN="$BITBUCKET_GIT_HTTP_ORIGIN" \
   --env=BITBUCKET_PROJECT_UUID="$BITBUCKET_PROJECT_UUID" \
   --env=BITBUCKET_REPO_IS_PRIVATE="$BITBUCKET_REPO_IS_PRIVATE" \
   --env=BITBUCKET_WORKSPACE="$BITBUCKET_WORKSPACE" \
   --env=BITBUCKET_REPO_OWNER_UUID="$BITBUCKET_REPO_OWNER_UUID" \
   --env=BITBUCKET_BRANCH="$BITBUCKET_BRANCH" \
   --env=BITBUCKET_REPO_UUID="$BITBUCKET_REPO_UUID" \
   --env=BITBUCKET_PROJECT_KEY="$BITBUCKET_PROJECT_KEY" \
   --env=BITBUCKET_REPO_SLUG="$BITBUCKET_REPO_SLUG" \
   --env=CI="$CI" \
   --env=BITBUCKET_REPO_OWNER="$BITBUCKET_REPO_OWNER" \
   --env=BITBUCKET_STEP_RUN_NUMBER="$BITBUCKET_STEP_RUN_NUMBER" \
   --env=BITBUCKET_BUILD_NUMBER="$BITBUCKET_BUILD_NUMBER" \
   --env=BITBUCKET_GIT_SSH_ORIGIN="$BITBUCKET_GIT_SSH_ORIGIN" \
   --env=BITBUCKET_PIPELINE_UUID="$BITBUCKET_PIPELINE_UUID" \
   --env=BITBUCKET_COMMIT="$BITBUCKET_COMMIT" \
   --env=BITBUCKET_CLONE_DIR="$BITBUCKET_CLONE_DIR" \
   --env=PIPELINES_JWT_TOKEN="$PIPELINES_JWT_TOKEN" \
   --env=BITBUCKET_STEP_UUID="$BITBUCKET_STEP_UUID" \
   --env=BITBUCKET_DOCKER_HOST_INTERNAL="$BITBUCKET_DOCKER_HOST_INTERNAL" \
   --env=DOCKER_HOST="tcp://host.docker.internal:2375" \
   --env=BITBUCKET_PIPE_SHARED_STORAGE_DIR="/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes" \
   --env=BITBUCKET_PIPE_STORAGE_DIR="/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes/atlassian/aws-code-deploy" \
   --env=APPLICATION_NAME="$APPLICATION_NAME" \
   --env=AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID" \
   --env=AWS_DEFAULT_REGION="$AWS_DEFAULT_REGION" \
   --env=AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY" \
   --env=COMMAND="deploy" \
   --env=DEPLOYMENT_GROUP="$DEPLOYMENT_GROUP" \
   --env=FILE_EXISTS_BEHAVIOR="OVERWRITE" \
   --env=IGNORE_APPLICATION_STOP_FAILURES="true" \
   --env=S3_BUCKET="$S3_BUCKET" \
   --env=VERSION_LABEL="-web-1.0.2" \
   --env=WAIT="true" \
   --add-host="host.docker.internal:$BITBUCKET_DOCKER_HOST_INTERNAL" \
   bitbucketpipelines/aws-code-deploy:0.2.5

3 个答案:

答案 0 :(得分:1)

您可以使用以下作为缓存节点的示例

- step:
   caches:
     - docker

答案 1 :(得分:0)

Bitbucket Pipes 实际上只是 docker run 命令的包装器。您可以看到输出 --pull always 命令中没有 run 标志。所以你可以利用 docker caching Pipelines 提供的。

- step:
    script:
      - ...
    caches:
      - docker

答案 2 :(得分:-1)

我正在研究这个。到目前为止,管道似乎不可缓存。