Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support docker build workflows #41

Open
jianlins opened this issue Feb 14, 2024 · 6 comments
Open

support docker build workflows #41

jianlins opened this issue Feb 14, 2024 · 6 comments

Comments

@jianlins
Copy link

jianlins commented Feb 14, 2024

The first three steps will work for docker build, can you integrate it into the action?

jobs:
  build_docker:
    runs-on: ubuntu-latest
    steps:
      - name: Backup docker files
        run: |
          echo "backup moby/buildkit image"
          sudo docker image save -o ${GITHUB_WORKSPACE}/images.tar moby/buildkit
          echo "Back up /var/lib/docker folder structure and other files"
          sudo rsync -aPq /var/lib/docker/ ${GITHUB_WORKSPACE}/docker 


      - name: Maximize build space
        uses: easimon/maximize-build-space@master
        with:
          overprovision-lvm: 'true'          
          remove-dotnet: 'true'
          # instead of using default value to mount to build path, /var/lib/docker/ is really the place we need more spaces.
          build-mount-path: '/var/lib/docker/'

      - name: Restore docker files
        run: |
          sudo rsync -aPq ${GITHUB_WORKSPACE}/docker/ /var/lib/docker
          sudo rm -rf ${GITHUB_WORKSPACE}/docker
          sudo ls ${GITHUB_WORKSPACE} -l
          sudo docker image load -i ${GITHUB_WORKSPACE}/images.tar
          sudo rm ${GITHUB_WORKSPACE}/images.tar

      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3      
              
      - name: list images
        run: docker images

      - name: check storage
        run: |
          sudo df -h
@gionn
Copy link

gionn commented Feb 14, 2024

I guess it's faster to stop the docker service (if possibile), rename the current /var/lib/docker to something else, run the action, rsync back to the new /var/lib/docker and start docker again

@jianlins
Copy link
Author

jianlins commented Feb 14, 2024

Tried. it doesn't work. I've tried a tone of ways to change docker data root directory, although it works on local machine, it doesn't work in runs. And start docker and stop docker commands behave weirdly. You should give it a try. Maybe there are other ways.

@j3soon
Copy link

j3soon commented Feb 22, 2024

Simply restarting the docker service seems to work for me:

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      - name: Maximize build space
        uses: easimon/maximize-build-space@master
        with:
          build-mount-path: /var/lib/docker/
          remove-dotnet: 'true'
          remove-android: 'true'
          remove-haskell: 'true'
          remove-codeql: 'true'
          remove-docker-images: 'true'
      - name: Restart docker
        run: sudo service docker restart
      - name: Checkout
        uses: actions/checkout@v4

@jianlins
Copy link
Author

Have you worked further to check the storage? It seems restarted , but still not saving to the mounted folder.

@sheepymeh
Copy link

If you want to preserve the contents of /var/lib/docker, I've found that the following snippet seems to work:

- name: Move /var/lib/docker/
  run: sudo mv /var/lib/docker/ "${GITHUB_WORKSPACE}/docker"

- name: Maximize build space
  uses: easimon/maximize-build-space@master
  with:
    root-reserve-mb: 512
    temp-reserve-mb: 32
    swap-size-mb: 32
    remove-dotnet: 'true'
    remove-android: 'true'
    remove-haskell: 'true'
    remove-codeql: 'true'
    build-mount-path: '/var/lib/docker/'

- name: Restore /var/lib/docker/
  run: sudo sh -c "mv ${GITHUB_WORKSPACE}/docker/* /var/lib/docker"

You shouldn't use remove-docker-images in this case because it would run docker image prune, which doesn't work after /var/lib/docker is moved. You can replicate its behavior by adding a docker image prune --all --force step beforehand.

@anoronh4
Copy link

this workaround works for me but for whatever reason the restore step sudo sh -c "mv ${GITHUB_WORKSPACE}/docker/* /var/lib/docker" takes several minutes for me even though the first mv step was basically instantaneous. does anyone have any other way to speed it up? rsync took the same amount of time. i'm guessing it's because after the cleanup they are on different mounts, so mv is not really a mv anymore, but actually a cp and rm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants