starter-workflows icon indicating copy to clipboard operation
starter-workflows copied to clipboard

Cannot enable experimental features on ubuntu based worfklow

Open barthelemyleveque opened this issue 6 years ago • 6 comments

I need to squash my docker images upon building but it isn't possible to set the experimental features, as there is permission issues.

I used the following code to build and push the images:

    - name: Build, tag, and push CFIND image to Amazon ECR
      id: build-image
      env:
        ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
        ECR_REPOSITORY: azmed/rayvolve/cfind
        IMAGE_TAG: jetson_dev_deploy_test
        DOCKER_CLI_EXPERIMENTAL: enabled
      run: |
        #build and push images
        sudo rm -rf /etc/docker/daemon.json
        sudo echo '{"experimental": true}' >> /etc/docker/daemon.json
        sudo systemctl restart docker
        docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f core/cfind/Dockerfile .
        docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
        echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"

However, I got an error saying

/home/runner/work/_temp/59d363d1-0231-4d54-bffe-1e3205bf6bf3.sh: line 3: /etc/docker/daemon.json: Permission denied

It seems that we do not have root access even if we use sudo. Am I doing something wrong, or is there a workaround? I have also tried setting

env:
        DOCKER_CLI_EXPERIMENTAL: enabled

and also tried manually exporting this env but nothing worked.

barthelemyleveque avatar Feb 07 '20 16:02 barthelemyleveque

Same herw

annaeve32 avatar Feb 08 '20 15:02 annaeve32

I need to squash my docker images upon building but it isn't possible to set the experimental features, as there is permission issues.

I used the following code to build and push the images:

    - name: Build, tag, and push CFIND image to Amazon ECR
      id: build-image
      env:
        ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
        ECR_REPOSITORY: azmed/rayvolve/cfind
        IMAGE_TAG: jetson_dev_deploy_test
        DOCKER_CLI_EXPERIMENTAL: enabled
      run: |
        #build and push images
        sudo rm -rf /etc/docker/daemon.json
        sudo echo '{"experimental": true}' >> /etc/docker/daemon.json
        sudo systemctl restart docker
        docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f core/cfind/Dockerfile .
        docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
        echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"

However, I got an error saying

/home/runner/work/_temp/59d363d1-0231-4d54-bffe-1e3205bf6bf3.sh: line 3: /etc/docker/daemon.json: Permission denied

It seems that we do not have root access even if we use sudo. Am I doing something wrong, or is there a workaround? I have also tried setting

env:
        DOCKER_CLI_EXPERIMENTAL: enabled

and also tried manually exporting this env but nothing worked.

ryaiori501 avatar Feb 27 '20 06:02 ryaiori501

It seems that we do not have root access even if we use sudo. Am I doing something wrong, or is there a workaround?

The sudo command will run the given command as root. But you're doing a shell redirect, which is handled by the shell itself, not by sudo. In other words, you're redirecting the output of sudo.

If you want to write to a file as root then you'll need to actually run a command that writes the file, and then run that using sudo. For example:

echo '{"experimental": true}' | sudo tee -a /etc/docker/daemon.json

ethomson avatar Feb 28 '20 14:02 ethomson

I replied on StackOverflow, because that's a great place for this type of question. This isn't an issue with our starter-workflows - this is a general question about GitHub Actions.

Another great place for this sort of question is the GitHub Community Forum.

But since this isn't related to starter-workflows, I'm going to close this issue here.

ethomson avatar Feb 28 '20 14:02 ethomson

TL:DR; daemon.json contents have changed. Use sed command instead.

This helped me to find the right way to enable --squash on GitHub workflows.

I first tried using the following command which indeed does what it says.

echo '{"experimental": true}' | sudo tee -a /etc/docker/daemon.json

However it wouldn't work. After inspecting daemon.json the mystery goes away:

{
    "exec-opts": ["native.cgroupdriver=cgroupfs"],
    "cgroup-parent": "/actions_job"
}
{"experimental": true}

There should ever be a single object. It is possible that this file used to be empty back in 2020. Today sed comes to the help:

sudo sed -i 's/}/,"experimental": true}/' /etc/docker/daemon.json

it produces the following ugly but working file:

{
    "exec-opts": ["native.cgroupdriver=cgroupfs"],
    "cgroup-parent": "/actions_job"
,"experimental": true}

flexchar avatar Aug 13 '22 08:08 flexchar