seek-oss/docker-ecr-cache-buildkite-plugin

caching node modules

shavo007 opened this issue · 2 comments

Hi,

Can I get a brief explanation of how this plugin works?

The doc does not go into details about what is happening.

I see an ecr repo is created on the fly first time.
But what about the logic defining whether the image already exists or not. How does that work? Is it a checksum of your lock file, or something else?

As without any lock file changes I see in the buildkite log # BUILDKITE_PLUGIN_DOCKER_IMAGE changed

Thanks,
Shane.

For reference, here is snippets from my dockerfile and pipeline

FROM mhart/alpine-node:11

RUN apk --no-cache update \
&& apk add --no-cache bash curl wget \
&& curl -L -o terminal-to-html.gz https://github.com/buildkite/terminal-to-html/releases/download/v3.1.0/terminal-to-html-3.1.0-linux-amd64.gz \
&& gzip -d terminal-to-html.gz \
&& mv terminal-to-html /usr/bin/terminal-to-html \
&& chmod +x /usr/bin/terminal-to-html \
&& mkdir -p /app

RUN rm /var/cache/apk/*

WORKDIR /app

COPY package.json yarn.lock .npmrc /app/

RUN yarn
dev-agent: &dev-agent
  agents:
    queue: shane-dev:cicd

plugins: &plugins #alias for shared plugins
  seek-oss/aws-sm#v0.0.3:
    env:
      NPM_TOKEN: "arn:xxx"
  seek-oss/private-npm#v1.1.1:
    env: "NPM_TOKEN"
  docker:
    volumes:
      - /app/node_modules
  seek-oss/docker-ecr-cache#v1.1.3:
    dockerfile: Dockerfile-builder
    cache-on:
      - yarn.lock   

steps:
  - label: "yarn :yarn: :eslint: Lint  and :mocha: unit test"
    <<: *dev-agent
    plugins:
      <<: *plugins
    command:
      - echo "--- Running yarn install :yarn:"
      - yarn
      - echo "--- Running yarn test:unit :mocha:"
      - yarn test:unit
    artifact_paths: 
      - reports/junit.xml
      - reports/coverage/**/*
  - wait: ~ #annotate test failures
    continue_on_failure: true
  - plugins:
      - junit-annotate#v1.6.0:
          artifacts: reports/junit.xml
    
    agents:
          queue: adv-dev:cicd

Hey!

Is it a checksum of your lock file, or something else?

Yep, it's a checksum of the contents of build-args, cache-on, and dockerfile. For your pipeline, the calculation should include Dockerfile-builder and yarn.lock.

without any lock file changes I see in the buildkite log # BUILDKITE_PLUGIN_DOCKER_IMAGE changed

If the cache is invalidated, you'll see a --- Building image log.

The log you've observed is an environment variable that this plugin sets for seamless integration with the Docker plugin:

plugins:
  - seek-oss/docker-ecr-cache#v1.1.3:
      ...
  - docker#3.0.1:
      # the image property here is set by docker-ecr-cache!
      volumes:
        - /app/node_modules

thanks @72636c that makes sense. as my cache-on is only my lockfile. But when i made a change to the dockerfile, i seen it rebuilt