cirruslabs / cirrus-cli

CLI for executing Cirrus tasks locally and in any CI
GNU Affero General Public License v3.0
204 stars 18 forks source link

Error: image was found but does not match the specified platform #748

Closed bartekpacia closed 4 months ago

bartekpacia commented 4 months ago

My environment

In my project, I'm in the process of migrating to ghcr.io/cirruslabs/macos-runner:sonoma. However, when I run the workflow, I always get:

$ cirrus run \
  --lazy-pull \
  --output simple \
  --env CIRRUS_BRANCH=master \
  'Deploy Android app'
Started 'Deploy Android app' Task
Started 'Preparing execution environment...'
Preparing volume to work with...
Failed to create a volume from working directory: working volume creation failed: when creating helper container: Error response from daemon: image with reference ghcr.io/cirruslabs/cirrus-cli:v0.119.0 was found but does not match the specified platform: wanted linux/amd64, actual: linux/arm64
'Preparing execution environment...' failed in 0.0s!
working volume creation failed: when creating helper container: Error response from daemon: image with reference ghcr.io/cirruslabs/cirrus-cli:v0.119.0 was found but does not match the specified platform: wanted linux/amd64, actual: linux/arm64

This was not occuring before. FWIW, a similar problem also occurs with Linux containers

fkorotkov commented 4 months ago

Could you please run file $(which cirrus) to verify cirrus binary is arm64 and not running under Rosetta.

bartekpacia commented 4 months ago
$ file $(which cirrus)
/opt/homebrew/bin/cirrus: Mach-O 64-bit executable arm64
edigaryev commented 4 months ago

How does your .cirrus.yml look like (or maybe you can get some reproducible/minimized example)?

edigaryev commented 4 months ago

P.S. you probably want to use arm_container instead of just container if your container engine does not support amd64 architecture, see Linux Containers.

bartekpacia commented 4 months ago

This is my .cirrus.star:

.cirrus.star ```starlark load( "./cirrus/common.star", "secrets", "setup_1password_cli", "setup_credentials", "setup_fastlane", ) load("cirrus", "fs", "yaml") load( "github.com/cirrus-modules/helpers", "cache", "container", "macos_instance", "script", "task", ) def main(): pubspec = fs.read("pubspec.yaml") flutter_version = yaml.loads(pubspec)["environment"]["flutter"] return [ task( name = "Deploy Android app", env = {"CIRRUS_CLONE_TAGS": "true"} | secrets(), instance = container( image = "ghcr.io/cirruslabs/flutter:%s" % flutter_version, ), only_if = "$CIRRUS_TAG =~ 'v.*' || $CIRRUS_BRANCH == 'master'", instructions = [ cache("pub", "~/.pub-cache"), setup_1password_cli(), setup_credentials(), setup_fastlane(), script( "fastlane_android_distribute", "cd android", """\ if [ "$CIRRUS_TAG" == "v*" ]; then op run -- bundle exec fastlane android internal else op run -- bundle exec fastlane android distribute fi """, ), ], ), task( name = "Deploy iOS app", env = {"CIRRUS_CLONE_TAGS": "true"} | secrets(), instance = macos_instance( image = "ghcr.io/cirruslabs/macos-runner:sonoma", ), only_if = "$CIRRUS_TAG =~ 'v.*' || $CIRRUS_BRANCH == 'master'", instructions = [ cache("cocoapods", "~/.cocoapods"), setup_1password_cli(), setup_credentials(), setup_fastlane(), script( "fastlane_ios_distribute", "cd ios", """\ if [ "$CIRRUS_TAG" == "v*" ]; then op run -- bundle exec fastlane ios prod else op run -- bundle exec fastlane ios distribute fi """, ), ], ), ] ```

It references .common.star, I believe it's not important in this context but just for the sake of it, here it is:

./cirrus/common.star ```starlark load("github.com/cirrus-modules/helpers", "script") def secrets(): return { "OP_SERVICE_ACCOUNT_TOKEN": "ENCRYPTED[6cb47a274401075b0883b77c85a850631b342ec26afc074cc1bf679b6fd18d2ae81e53bde62b2fde49a89374271e82fa]", } def setup_credentials(): return script( "setup_credentials", """\ if [ $(uname) = \"Linux\" ]; then apt-get update && apt-get install -y jq fi """, "chmod +x ./setup_credentials && ./setup_credentials", 'while read -r line; do echo "$line" >> $CIRRUS_ENV; done < .env', ) def setup_1password_cli(): return script( "setup_1password_cli", """\ if [ $(uname) = \"Linux\" ]; then apt-get update && apt-get install -y jq %s elif [ $(uname) = \"Darwin\" ]; then %s fi """ % (_setup_1password_cli_debian, _setup_1password_cli_macos), "echo \"OP_SERVICE_ACCOUNT_KEY: $OP_SERVICE_ACCOUNT_KEY\"", ) _setup_1password_cli_debian = """\ # Add key for 1Password APT repository curl -sS https://downloads.1password.com/linux/keys/1password.asc | sudo gpg --dearmor --output /usr/share/keyrings/1password-archive-keyring.gpg # Add the 1Password apt repository echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/1password-archive-keyring.gpg] https://downloads.1password.com/linux/debian/$(dpkg --print-architecture) stable main" | sudo tee /etc/apt/sources.list.d/1password.list #Add the debsig-verify policy sudo mkdir -p /etc/debsig/policies/AC2D62742012EA22/ curl -sS https://downloads.1password.com/linux/debian/debsig/1password.pol | sudo tee /etc/debsig/policies/AC2D62742012EA22/1password.pol sudo mkdir -p /usr/share/debsig/keyrings/AC2D62742012EA22 curl -sS https://downloads.1password.com/linux/keys/1password.asc | sudo gpg --dearmor --output /usr/share/debsig/keyrings/AC2D62742012EA22/debsig.gpg # Install 1Password CLI apt-get update && apt-get install -y 1password-cli""" _setup_1password_cli_macos = """\ brew install 1password-cli""" def setup_fastlane(): return script( "setup_fastlane", "gem install bundler", "cd android && bundle install", "cd ..", "cd ios && bundle install", ) ```
bartekpacia commented 4 months ago

@edigaryev Using arm_container works for Linux container, but for macOS VM, I encounter #746

edigaryev commented 4 months ago

Do I understand correctly that the only issue remaining is that this .cirrus.yml:

macos_instance:
  image: ghcr.io/cirruslabs/macos-runner:sonoma

task:
  script: uname -a

Causes your cirrus run to pull the ghcr.io/cirruslabs/macos-runner:sonoma image?

What does your tart list --source oci | grep macos-runner look like on the machine you're trying to run this?

bartekpacia commented 4 months ago

Do I understand correctly that the only issue remaining is [...]

No, the issue is that when I try to run the image, it throws the error from OP.

Logs ``` $ cat .cirrus.yaml exit 1 macos_instance: image: ghcr.io/cirruslabs/macos-runner:sonoma task: script: uname -a ``` ``` $ cirrus run --output simple Started 'main' task Started 'pull virtual machine' Pulling virtual machine ghcr.io/cirruslabs/macos-runner:sonoma... pulling ghcr.io/cirruslabs/macos-runner:sonoma... pulling manifest... ghcr.io/cirruslabs/macos-runner@sha256:e1847298815e8363d590ac31bf08951f9b00f329954cf7a273bd29317085753b image is already cached and linked! 'pull virtual machine' succeeded in 0.8s! Started 'clone virtual machine' Cloning virtual machine ghcr.io/cirruslabs/macos-runner:sonoma... 'clone virtual machine' succeeded in 0.1s! Started 'configure virtual machine' Configuring virtual machine cirrus-cli-0-f61c8e94-2a8e-4240-ac67-b73f124b848d... 'configure virtual machine' succeeded in 0.0s! Started 'boot virtual machine' VM was assigned with 192.168.64.22 IP 'boot virtual machine' succeeded in 14s! Started 'syncing working directory' 'syncing working directory' succeeded in 19s! Started 'main' script uname -a Darwin admins-Virtual-Machine.local 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:12:39 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_VMAPPLE arm64 'main' script succeeded in 1.0s! agent warning: Encountered an error while gathering resource utilization metrics: failed to query total CPU count/memory amount: not implemented yet agent warning: Encountered an error while gathering resource utilization metrics: failed to query CPU usage using gopsutil on darwin/arm64: not implemented yet 'main' task succeeded in 40s! ```

What does your tart list --source oci | grep macos-runner look like on the machine you're trying to run this?

$ tart list --source oci | grep macos-runner
OCI    ghcr.io/cirruslabs/macos-runner:sonoma                                                                        250  142  stopped
OCI    ghcr.io/cirruslabs/macos-runner@sha256:e1847298815e8363d590ac31bf08951f9b00f329954cf7a273bd29317085753b       250  142  stopped
bartekpacia commented 4 months ago

Weirdly, everything seems to work just fine now. I think the most productive thing to do is to close this issue. If I encounter the problem again, I'll create a fully reproducible example.

Thanks for all the help.