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

[GitHub Actions] Failed to initialize container on ubuntu-latest with SwiftFormat 0.55.2 #1930

Closed
ski-u opened this issue Nov 25, 2024 · 22 comments · Fixed by #1934
Closed
Labels

Comments

@ski-u
Copy link
Contributor

ski-u commented Nov 25, 2024

Hi, thank you for working on this project! 👋

I'm using SwiftFormat on GitHub Actions and found the container initialization fails on ubuntu-latest with the latest SwiftFormat (0.55.2)

I didn't have this issue before 0.55.0.

Reproduce

Error

Checking docker version
  /usr/bin/docker version --format '{{.Server.APIVersion}}'
  '1.45'
  Docker daemon API version: '1.45'
  /usr/bin/docker version --format '{{.Client.APIVersion}}'
  '1.45'
  Docker client API version: '1.45'
Clean up resources from previous jobs
  /usr/bin/docker ps --all --quiet --no-trunc --filter "label=ccba6d"
  /usr/bin/docker network prune --force --filter "label=ccba6d"
Create local container network
  /usr/bin/docker network create --label ccba6d github_network_e4c91c3988fa417e99[2](https://github.com/ski-u/SwiftFormatWithGitHubActions/actions/runs/12003321065/job/33456611463?pr=2#step:2:2)67aa1f0cf9313
  29af86267cfcbc322ec978f72116d96cfc48467b6855[3](https://github.com/ski-u/SwiftFormatWithGitHubActions/actions/runs/12003321065/job/33456611463?pr=2#step:2:3)af07e2c0885d0e672be
Starting job container
  /usr/bin/docker --config /home/runner/work/_temp/.docker_bed75291-d[4](https://github.com/ski-u/SwiftFormatWithGitHubActions/actions/runs/12003321065/job/33456611463?pr=2#step:2:4)99-443b-b6a1-825953f70e09 login ghcr.io -u ski-u --password-stdin
  /usr/bin/docker --config /home/runner/work/_temp/.docker_bed7[5](https://github.com/ski-u/SwiftFormatWithGitHubActions/actions/runs/12003321065/job/33456611463?pr=2#step:2:5)291-d499-443b-b6a1-825953f70e09 pull ghcr.io/nicklockwood/swiftformat:0.55.0
  0.55.0: Pulling from nicklockwood/swiftformat
  27[6](https://github.com/ski-u/SwiftFormatWithGitHubActions/actions/runs/12003321065/job/33456611463?pr=2#step:2:6)54217a0d4: Pulling fs layer
  2[7](https://github.com/ski-u/SwiftFormatWithGitHubActions/actions/runs/12003321065/job/33456611463?pr=2#step:2:7)654217a0d4: Verifying Checksum
  27654217a0d4: Download complete
  27654217a0d4: Pull complete
  Digest: sha256:b65053942ed5fb1[8](https://github.com/ski-u/SwiftFormatWithGitHubActions/actions/runs/12003321065/job/33456611463?pr=2#step:2:9)1b6a66968e1164b6fec9f2959a17251984f96a1c82bd707f
  Status: Downloaded newer image for ghcr.io/nicklockwood/swiftformat:0.55.0
  ghcr.io/nicklockwood/swiftformat:0.55.0
  /usr/bin/docker create --name 874f1670a32143b1bcc52bfa[9](https://github.com/ski-u/SwiftFormatWithGitHubActions/actions/runs/12003321065/job/33456611463?pr=2#step:2:10)95c8676_ghcrionicklockwoodswiftformat0550_aba14a --label ccba6d --workdir /__w/SwiftFormatWithGitHubActions/SwiftFormatWithGitHubActions --network github_network_e4c91c3988fa417e99267aa1f0cf9313  -e "HOME=/github/home" -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work":"/__w" -v "/home/runner/runners/2.320.0/externals":"/__e":ro -v "/home/runner/work/_temp":"/__w/_temp" -v "/home/runner/work/_actions":"/__w/_actions" -v "/opt/hostedtoolcache":"/__t" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" --entrypoint "tail" ghcr.io/nicklockwood/swiftformat:0.55.0 "-f" "/dev/null"
  427e0f75c05053aa9f291a704827f332a65b9f51ca0ba95ef70e0e5d3240dd9b
  /usr/bin/docker start 427e0f75c05053aa9f291a704827f332a65b9f51ca0ba95ef70e0e5d3240dd9b
  Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "tail": executable file not found in $PATH: unknown
  Error: failed to start containers: 427e0f75c05053aa9f291a704827f332a65b9f51ca0ba95ef70e0e5d3[24](https://github.com/ski-u/SwiftFormatWithGitHubActions/actions/runs/12003321065/job/33456611463?pr=2#step:2:27)0dd9b
  Error: Docker start fail with exit code 1

Workflow

name: swiftformat
on:
  pull_request:
    paths:
      - '.github/workflows/swiftformat.yml'
      - '**/*.swift'
  workflow_dispatch:
permissions:
  contents: read
jobs:
  swiftformat:
    runs-on: ubuntu-latest
    container:
      image: ghcr.io/nicklockwood/swiftformat:0.54.5
    steps:
    - uses: actions/checkout@v4
    - name: swiftformat
      run: swiftformat . --lint --lenient
@david-walter-naptics
Copy link

Thank you a lot for this great project which makes working in a team so much easier and effective!

Sadly at the moment I experience the same Issue as the original poster.
I set back the version to 0.54.5 at the moment as a workaround but would love to continue using latest.

Error

Checking docker version
Clean up resources from previous jobs
Create local container network
Starting job container
  /usr/bin/docker --config /home/runner/work/_temp/.docker_d7c9b40f-9dda-4978-b15b-4da8425b8f50 login ghcr.io -u david-walter-naptics --password-stdin
  /usr/bin/docker --config /home/runner/work/_temp/.docker_d7c9b40f-9dda-4978-b15b-4da8425b8f50 pull ghcr.io/nicklockwood/swiftformat:latest
  latest: Pulling from nicklockwood/swiftformat
  5ec304e2e8a2: Pulling fs layer
  5ec304e2e8a2: Verifying Checksum
  5ec304e2e8a2: Download complete
  5ec304e2e8a2: Pull complete
  Digest: sha256:1308256e5b6bf0efef0d8d07abe460c7e595b01c2b9fbea8d616d3083f9ee59c
  Status: Downloaded newer image for ghcr.io/nicklockwood/swiftformat:latest
  ghcr.io/nicklockwood/swiftformat:latest
  /usr/bin/docker create --name 557f75af22b042c6a70cf37730185027_ghcrionicklockwoodswiftformatlatest_b41db7 --label 6536e6 --workdir /__w/heim-app-ios/heim-app-ios --network github_network_67ca9aa9873346df89f2d0f080fe92ed --entrypoint '' -e "HOME=/github/home" -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work":"/__w" -v "/home/runner/runners/2.320.0/externals":"/__e":ro -v "/home/runner/work/_temp":"/__w/_temp" -v "/home/runner/work/_actions":"/__w/_actions" -v "/opt/hostedtoolcache":"/__t" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" --entrypoint "tail" ghcr.io/nicklockwood/swiftformat:latest "-f" "/dev/null"
  5faba1a735a294728a4ca24e77083547fc3a5eac467b6ef6b9564535aa28ab36
  /usr/bin/docker start 5faba1a735a294728a4ca24e77083547fc3a5eac467b6ef6b9564535aa28ab36
  Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "tail": executable file not found in $PATH: unknown
  Error: failed to start containers: 5faba1a735a294728a4ca24e77083547fc3a5eac467b6ef6b9564535aa28ab36
  Error: Docker start fail with exit code 1

Workflow

name: Swiftformat
run-name: Swiftformat
on:
  workflow_call:
jobs:
  swiftformat:
    runs-on: ubuntu-latest
    container:
      image: ghcr.io/nicklockwood/swiftformat:latest
      options: "--entrypoint ''" # Prevent run of swiftformat before repo is checked out
    steps:
      - name: Check out repository code
        uses: actions/checkout@v4
      - name: Printing swiftformat version
        run: swiftformat --version
      - name: Running swiftformat
        run: swiftformat --lint .

@nicklockwood
Copy link
Owner

@csjones @Cyberbeni could this be related to your Linux build changes? Would you mind taking a look?

@Cyberbeni
Copy link
Contributor

From the log, it seems like GHA changes the entrypoint to tail and since we only have swiftformat in the container, it fails. We could try using busybox:stable instead of scratch here:

FROM scratch AS runner

PS: Using the docker container locally with docker works on an Intel J4105 PC, using the container with podman on a Ryzen 1700x PC sometimes returns error code 139 (SIGSEGV) but not when --verbose mode is enabled, both on 0.55.0, 0.55.2 and local build; 0.54.5 seems to work on both. I will try installing docker on the Ryzen PC and podman on the Intel PC later.

@Cyberbeni
Copy link
Contributor

The Intel PC with podman seems to work fine. (It is running Ubuntu server 20.04)

So the problem is specific to the Ryzen 1700x PC, which is using Nobara 40. (Haven't had time to try docker on this machine yet)

@Cyberbeni
Copy link
Contributor

Ah, don't need to install docker, I can just get the binary from the artifactbundle.
It is also crashing on the Ryzen PC:

> ~/Downloads/swiftformat_linux .
Running SwiftFormat...
Reading config file at /home/cyberbeni/Developer/Wiring/.swiftformat
[1]    6165 segmentation fault (core dumped)  ~/Downloads/swiftformat_linux .

But still not crashing when using verbose mode:

> ~/Downloads/swiftformat_linux --verbose .
Running SwiftFormat...
Reading config file at /home/cyberbeni/Developer/Wiring/.swiftformat
...
SwiftFormat completed in 0.16s.
0/31 files formatted.

So this seems like an issue with the Swift static Linux SDK. Will write up a bug report for them later today.

@Cyberbeni
Copy link
Contributor

swiftformat_linux.zip still contains the version that links against dependency versions that are found on Ubuntu 20.04, I think that can be removed (or replaced with the same output as the artifactbundle build)

@nicklockwood
Copy link
Owner

nicklockwood commented Nov 26, 2024

@Cyberbeni the zipped version is built using the linux_build action rather than the artifactbundle action. Perhaps these can be unified?

@Cyberbeni
Copy link
Contributor

Yes, the swiftformat_linux.zip currently only runs properly on Ubuntu 20.04 (or systems that use the same versions for the runtime dependencies)

@Cyberbeni
Copy link
Contributor

Also I just noticed that build-linux-release.sh passes -Xlinker -S (which corresponds to the settings in xcodeproj to strip debugging symbols) but then we strip once more. I think using -Xlinker -s (with lowercase s, which strips all symbols) would have the same result as running the strip CLI tool.

The 0.55.0 container has no stripping, so this shouldn't be the cause of the problem.

Relevant Apple docs: https://developer.apple.com/documentation/xcode/build-settings-reference#Strip-Style

@Cyberbeni
Copy link
Contributor

@ski-u Could you try this image? ghcr.io/cyberbeni/swiftformat:github_actions_fix

Here are the changes compared to main: https://github.com/Cyberbeni/SwiftFormat/commit/0e0ee6cf589d5b0d6078f6c22d6dbb30b3bada06

@ski-u
Copy link
Contributor Author

ski-u commented Nov 27, 2024

@Cyberbeni Thank you for the investigation!

I tried the new image here
Initialize containers step now succeeded but actions/checkout@v4 failed with the following log

Run actions/checkout@v4
  with:
    repository: ski-u/SwiftFormatWithGitHubActions
    token: ***
    ssh-strict: true
    ssh-user: git
    persist-credentials: true
    clean: true
    sparse-checkout-cone-mode: true
    fetch-depth: 1
    fetch-tags: false
    show-progress: true
    lfs: false
    submodules: false
    set-safe-directory: true
/usr/bin/docker exec  3afffe4b3b05991cc8f3b9e0d31[2](https://github.com/ski-u/SwiftFormatWithGitHubActions/actions/runs/12041026502/job/33572291480#step:3:2)6f46541f641b[3](https://github.com/ski-u/SwiftFormatWithGitHubActions/actions/runs/12041026502/job/33572291480#step:3:3)e921a822916fe6643922589 sh -c "cat /etc/*release | grep ^ID"
/__e/node20/bin/node: error while loading shared libraries: libdl.so.2: cannot open shared object file: No such file or directory

@nicklockwood nicklockwood reopened this Nov 27, 2024
@Cyberbeni
Copy link
Contributor

So they copy over a dynamically linked node to run actions which then doesn't find its dependencies. Is there no documentation on the minimal base image for GHA? I couldn't find anything on this.

Also I'm not sure if this should be a supported use case. I'm pretty sure you can just run docker run --rm --volume=.:/workspace ghcr.io/nicklockwood/swiftformat:0.55.2 --lint /workspace as a step instead of running the whole workflow inside the container. (Not sure if exit code is passed through or you need to add a flag for that, like docker compose up --exit-code-from)

@nicklockwood
Copy link
Owner

I'm horribly out of my depth here so I'm going to let you guys figure it out. Let me know if I need to revert anything or replace any of the binaries attached to the release

@ski-u
Copy link
Contributor Author

ski-u commented Nov 29, 2024

I tried docker run --rm --volume=.:/workspace ghcr.io/nicklockwood/swiftformat:0.55.2 /workspace --lint --lenient --reporter github-actions-log here and found the workflow succeeded 🎉

BTW, --reporter github-actions-log does't work well with this command but I guess that's out of scope for this issue.

@Cyberbeni
Copy link
Contributor

Based on the code I think you have to pass this to docker: --env GITHUB_WORKSPACE=/workspace

So docker run --rm --volume=.:/workspace --env GITHUB_WORKSPACE=/workspace ghcr.io/nicklockwood/swiftformat:0.55.2 /workspace --lint --lenient --reporter github-actions-log

https://github.com/nicklockwood/SwiftFormat/blob/main/Sources/GithubActionsLogReporter.swift

Then this could probably be added to the readme: https://github.com/nicklockwood/SwiftFormat?tab=readme-ov-file#github-actions

@ski-u
Copy link
Contributor Author

ski-u commented Nov 29, 2024

That's what I need, thank you for the feedback.
It's now working well for 0.55.2!

But I found that command failed with swiftformat:0.55.3 and the following error is displayed

Run docker run --rm --volume=.:/workspace --env GITHUB_WORKSPACE=/workspace ghcr.io/nicklockwood/swiftformat:0.55.3 /workspace --lint --lenient --reporter github-actions-log
Unable to find image 'ghcr.io/nicklockwood/swiftformat:0.55.3' locally
0.55.3: Pulling from nicklockwood/swiftformat
d3a[4](https://github.com/ski-u/SwiftFormatWithGitHubActions/actions/runs/12114190729/job/33770333939?pr=5#step:3:5)026919f9: Pulling fs layer
3a7100a6b2df: Pulling fs layer
d3a4026919f9: Verifying Checksum
d3a4026919f9: Download complete
3a7100a6b2df: Verifying Checksum
3a7100a6b2df: Download complete
d3a4026919f9: Pull complete
3a7100a6b2df: Pull complete
Digest: sha2[5](https://github.com/ski-u/SwiftFormatWithGitHubActions/actions/runs/12114190729/job/33770333939?pr=5#step:3:6)6:68f92025cfb0cdb6d60dc235489215f79936de3783a2b1c2b1f22e40[6](https://github.com/ski-u/SwiftFormatWithGitHubActions/actions/runs/12114190729/job/33770333939?pr=5#step:3:7)17f13c8
Status: Downloaded newer image for ghcr.io/nicklockwood/swiftformat:0.55.3
Running SwiftFormat...
(lint mode - no files will be changed.)
Error: Process completed with exit code 13[9](https://github.com/ski-u/SwiftFormatWithGitHubActions/actions/runs/12114190729/job/33770333939?pr=5#step:3:10).

@nicklockwood
Copy link
Owner

nicklockwood commented Dec 22, 2024

@ski-u hopefully fixed 0.55.4? Let me know if not

@cpisciotta
Copy link

Hey @nicklockwood! I'm still seeing this issue with 0.55.4. You can see the most recent failures below. Interestingly, they're different errors, and I see them across the two latest Ubuntu runners (22.04 and 24.04).

For context, I was running SwiftFormat via Docker image, and I wasn't having any issues until 0.55.x. As a workaround, I'm simply using the pre-installed version on GitHub's macOS runners.

Docker and Linux is out of my wheelhouse, so I don't know how to resolve this, but I would be interested to know the fix. It'd likely be helpful for my own work on xcbeautify.

If it's any help, I noticed that previous versions (before 0.55.x) shipped images for 3 Linux architectures (see here), while the later ones only ship 2 (see here). I'm not sure if that's related, but it is the one difference that stuck out to me.

Thanks, and I hope this helps find a fix!

@ealeksandrov
Copy link

ealeksandrov commented Dec 22, 2024

I am using a self-hosted runner with Ubuntu 22.04 and still seeing the same error for 0.55.4:

Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "tail": executable file not found in $PATH: unknown

Workflow:

jobs:
  format:
    runs-on: my-ubuntu-runner
    container: ghcr.io/nicklockwood/swiftformat:0.55.4
    steps:
      - uses: actions/checkout@v4
      - name: SwiftFormat
        run: swiftformat --lint . --reporter github-actions-log

It worked well before 0.55.x.

@ski-u
Copy link
Contributor Author

ski-u commented Dec 23, 2024

Now it works well for me with docker run command as README shows like:

jobs:
  swiftformat:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: swiftformat
        run: docker run --rm --volume=.:/workspace --env GITHUB_WORKSPACE=/workspace ghcr.io/nicklockwood/swiftformat:0.55.4 /workspace --lint --lenient --reporter github-actions-log

@ealeksandrov
Copy link

@ski-u Thanks, it worked! Although I tried this yesterday and the build got stuck, it now works for several tests.
I'm not familiar with Docker, can you explain the difference and why we need this complicated path setup only for 0.55.x? It looks much cleaner with the container syntax.

@ski-u
Copy link
Contributor Author

ski-u commented Dec 25, 2024

@ealeksandrov
This workaround is suggested here and I'm also not sure why we need this setup change after 0.55.0 (after #1915?)

@Cyberbeni
Could you answer the question?

can you explain the difference and why we need this complicated path setup only for 0.55.x?

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

Successfully merging a pull request may close this issue.

6 participants