How to write and read from CodeCatalyst Workflow Action Cache?

0

I have been going through CodeCatalyst and do not see a single example, or blueprint, that demonstrates how someone would use workflow caching for Docker. An example of this directly on the docs page would be great since its quite difficult to figure out with A) poor documentation on actual usage and B) a small-ish community.

https://docs.aws.amazon.com/codecatalyst/latest/userguide/workflows-caching.html

已提问 8 个月前255 查看次数
1 回答
0

Hey!!

Maybe you will need to write your own example using the reference for workflow actions:

Based on the workflow guide shared, you can start putting together your own workflow actions. Here’s a sample that shows how to implement caching for Docker builds. Just a heads-up, this example hasn’t been tested yet, but feel free to use it as a starting point. Also, it's a good idea to kick things off with the free tier to build and test your workflows without any cost.

Name: MyDockerBuildWorkflow
SchemaVersion: 1.0
Actions:
  BuildDockerImage:
    Identifier: aws/build@v1
    Compute:
      Type: EC2
      Fleet: Linux.x86-64.Large
    Environment:
      Name: my-build-environment
    Inputs:
      Sources:
        - WorkflowSource
    Caching:
      FileCaching:
        DockerLayersCache:
          Path: /path/to/docker/cache
          RestoreKeys:
            - docker-cache-${{ checksum "Dockerfile" }}-${{ checksum "dependencies.lock" }}-${{ WorkflowSource.BUILD_VERSION }}
    Configuration:
      Container:
        Registry: DockerHub
        Image: node:18.18.2
      Steps:
        - Run: |
            docker build . \
              --cache-from /path/to/docker/cache \
              --build-arg BUILD_VERSION=${{ WorkflowSource.BUILD_VERSION }} \
              -t myimage:latest
        - Run: docker save -o /path/to/docker/cache/image.tar myimage:latest
    Outputs:
      Artifacts:
        - Name: DockerImageArtifact
          Files:
            - /path/to/docker/cache/image.tar

Details

  1. Start EC2 Instance: Launch an EC2 instance with specific computing resources.
  2. Prepare Environment: Set up my-build-environment for the Docker build process.
  3. Fetch Source: Obtain the workflow source code to be used in the Docker image build.
  4. Check Cache: Use checksums of the Dockerfile, dependencies.lock, and build version to search for existing Docker layer caches.
  5. Build Docker Image: Execute Docker build commands, utilizing cached layers if available to speed up the process.
  6. Save Docker Image: After the build, save the Docker image as a tar file in the specified path.
  7. Output Artifact: Generate an artifact of the Docker image for deployment or further use.
profile picture
专家
已回答 8 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则