google / go-cloud

The Go Cloud Development Kit (Go CDK): A library and tools for open cloud development in Go.
https://gocloud.dev/
Apache License 2.0
9.57k stars 812 forks source link

samples/guestbook/localdb/main.go: add docker platform flag #3450

Closed samlaf closed 4 months ago

samlaf commented 4 months ago

Code didn't run on my m1 macbook pro, getting

$ go run localdb/main.go
go: downloading gopkg.in/pipe.v2 v2.0.0-20140414041502-3c2ca4d52544
localdb: Starting container running MySQL
Unable to find image 'mysql:5.6' locally
docker: Error response from daemon: no match for platform in manifest: not found.
See 'docker run --help'.
localdb: running [docker run --rm --env MYSQL_DATABASE=guestbook --env MYSQL_ROOT_PASSWORD=password --detach --publish 3306:3306 mysql:5.6]: exit status 125:
exit status 1

That's because mysql:5.6 only had a linux/amd64 image (https://hub.docker.com/layers/library/mysql/5.6/images/sha256-897086d07d1efa876224b147397ea8d3147e61dd84dce963aace1d5e9dc2802d?context=explore). Adding the platform flag tells docker to download it anyways, even on a mac.

I always use this trick but honestly not sure why amd64 images run on m1 chips. Maybe there's no meaningful difference? Maybe its because of Rosetta? Or maybe I'll eventually hit a bug because some features are not available when running on different arch?

Please use a title starting with the name of the affected package, or \"all\", followed by a colon, followed by a short summary of the issue. Example: blob/gcsblob: fix typo in documentation.

Please reference any Issue related to this Pull Request. Example: Fixes #1.

See here for tips on good Pull Request description.

codecov[bot] commented 4 months ago

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 73.37%. Comparing base (0a37d2f) to head (4cfae61).

Files Patch % Lines
samples/guestbook/localdb/main.go 0.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #3450 +/- ## ========================================== - Coverage 73.38% 73.37% -0.01% ========================================== Files 113 113 Lines 14956 14957 +1 ========================================== Hits 10975 10975 - Misses 3207 3208 +1 Partials 774 774 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.