Skip to content
This repository has been archived by the owner. It is now read-only.

cache #1

Closed
fredwangwang opened this issue Nov 29, 2018 · 5 comments

Comments

@fredwangwang
Copy link

commented Nov 29, 2018

I saw the build script uses rsync to cp the state back and forth between local drive and cache drive. Curious what is the particular reason for doing that?

@vito

This comment has been minimized.

Copy link
Member

commented Nov 30, 2018

If I remember right, the cache directory can't be directly used as the img state dir because when the cache is restored on subsequent runs it'll be created as an overlay mount point, which can't be used as an underlying filesystem for img's own overlay mount points. This is because of how Concourse caches work - tasks are given a copy-on-write of the cache so concurrent runs don't trip each other up.

I tried, though. It would've been really slick.

@fredwangwang

This comment has been minimized.

Copy link
Author

commented Nov 30, 2018

that's interesting. I dont't have much knowledge about how concourse cache and overlay fs works, but I was able to get the following pipeline running and img shows cache hit on the subsequent run.

jobs:
  - name: build-using-img
    plan:
      - task: generate-dockerfile
        config:
          platform: linux
          image_resource:
            type: docker-image
            source:
              repository: alpine
          outputs:
            - name: dockerfile
          run:
            path: sh
            args:
              - -c
              - |
                cat <<'EOF' > dockerfile/Dockerfile
                FROM alpine
                RUN apk update
                RUN apk add bash zip unzip curl gettext jq py2-pip git wget tar xz
                RUN pip install awscli
                EOF
      - task: run-img
        privileged: true
        config:
          platform: linux
          image_resource:
            type: docker-image
            source:
              repository: r.j3ss.co/img
          inputs:
            - name: dockerfile
          outputs:
            - name: generated-image
          caches:
            - path: cache
          run:
            user: root
            path: sh
            args:
              - -c
              - |
                function sanitize_cgroups() {
                  mkdir -p /sys/fs/cgroup
                  mountpoint -q /sys/fs/cgroup || \
                    mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup

                  mount -o remount,rw none /sys/fs/cgroup

                  sed -e 1d /proc/cgroups | while read sys hierarchy num enabled; do
                    if [ "$enabled" != "1" ]; then
                      # subsystem disabled; skip
                      continue
                    fi

                    grouping="$(cat /proc/self/cgroup | cut -d: -f2 | grep "\\<$sys\\>")" || true
                    if [ -z "$grouping" ]; then
                      # subsystem not mounted anywhere; mount it on its own
                      grouping="$sys"
                    fi

                    mountpoint="/sys/fs/cgroup/$grouping"

                    mkdir -p "$mountpoint"

                    # clear out existing mount to make sure new one is read-write
                    if mountpoint -q "$mountpoint"; then
                      umount "$mountpoint"
                    fi

                    mount -n -t cgroup -o "$grouping" cgroup "$mountpoint"

                    if [ "$grouping" != "$sys" ]; then
                      if [ -L "/sys/fs/cgroup/$sys" ]; then
                        rm "/sys/fs/cgroup/$sys"
                      fi

                      ln -s "$mountpoint" "/sys/fs/cgroup/$sys"
                    fi
                  done

                  if ! test -e /sys/fs/cgroup/systemd ; then
                    mkdir /sys/fs/cgroup/systemd
                    mount -t cgroup -o none,name=systemd none /sys/fs/cgroup/systemd
                  fi
                }

                sanitize_cgroups

                stty columns 80

                img build --no-console -s cache -f dockerfile/Dockerfile -t test:latest .
                img unpack -s cache test
                mv rootfs generated-image/rootfs
      - task: mod-image
        input_mapping:
          image: generated-image
        config:
          platform: linux
          image_resource:
            type: docker-image
            source:
              repository: ubuntu
          inputs:
            - name: image
          outputs:
            - name: modified-image
          run:
            path: bash
            args:
              - -c
              - |
                mv image/rootfs modified-image/rootfs
                echo '{"user":"root","env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","HOME=/root"]}' > modified-image/metadata.json
      - task: test-image
        image: modified-image
        config:
          platform: linux
          run:
            path: bash
            args:
              - -c
              - |
                which pip
                which unzip
                which curl
                which jq
                which git
#6 [3/3] RUN pip install awscli
#6       digest: sha256:9944856aaf16366cd0a13ad17629742f910eea787655a3342f88602327ddd40c
#6         name: "[3/3] RUN pip install awscli"
#6      started: 2018-11-30 05:45:47.695358655 +0000 UTC m=+1.364066645
#6    completed: 2018-11-30 05:45:47.695391975 +0000 UTC m=+1.364099891
#6     duration: 33.246µs
#6       cached: true

maybe img changes the way it presist the state?

@vito

This comment has been minimized.

Copy link
Member

commented Nov 30, 2018

@fredwangwang

This comment has been minimized.

Copy link
Author

commented Nov 30, 2018

@fredwangwang

This comment has been minimized.

Copy link
Author

commented Dec 12, 2018

Since there is no further discussion re this topic, I am going to close it.

One thing worth noticing though. Seems like there is a bug in img. It forbids build using folder path other than the default directory (/home/user/.local/share/img). The workaround I took was to symlink the cache director to the defualt cache directory.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants
You can’t perform that action at this time.