-
Notifications
You must be signed in to change notification settings - Fork 25
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 --platform
docker CLI argument to target the platform specific image architecture
#103
Support --platform
docker CLI argument to target the platform specific image architecture
#103
Conversation
@lifeofguenter hopefully it will be merged soon! In a meantime: Is there a workaround until this change is applied? For instance by exporting variables such as:
? |
@pySilver have you been able to get this approach to work? |
@sroomberg yes, it works just fine. Up until it's not :D Well if your image fails with qemu segfault while building x86 image on ARM this merge won't help. Some of my images can be build and others cannot. But that qemu problem, unfortunately. |
@pySilver fyi it works just fine but if you are running on an ARM-based machine (i.e., an M1 mac) and you inspect the image it will show it as an ARM-based image even though its a multi-platform build. In order to verify the image is compatible with amd64/x86 I pushed the image to AWS ECR and verified it on an x86-based EC2 image. |
Its still a gamble for some reason. Some things cannot be compiled inside dockerized linux when host is arm based (m1). Same recipe works fine on x86. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @lifeofguenter, thanks for creating the PR!
While reviewing the PR, I tried to build an image using the binary with your changes. But we are still getting "docker pull" requires exactly 1 argument
error.
=> Packer template
source "docker" "oraclelinux2" {
image = "--platform=linux/amd64 oraclelinux:8"
commit = true
}
build {
name = "packer-docker-pr-103"
sources = [
"source.docker.oraclelinux2",
]
}
=> Output Logs
➜ packer_tutorial PACKER_LOG=1 packer build temp.pkr.hcl
2022/07/12 19:47:47 [INFO] Packer version: 1.8.2 [go1.18.3 darwin arm64]
2022/07/12 19:47:47 Old default config directory found: /Users/devashish/.packer.d
2022/07/12 19:47:47 [TRACE] discovering plugins in /Users/devashish/.gvm/pkgsets/go1.18.3/global/bin
2022/07/12 19:47:47 Old default config directory found: /Users/devashish/.packer.d
2022/07/12 19:47:47 [TRACE] discovering plugins in /Users/devashish/.packer.d/plugins
2022/07/12 19:47:47 [DEBUG] Discovered plugin: docker = /Users/devashish/.packer.d/plugins/packer-plugin-docker
2022/07/12 19:47:47 [INFO] found external [-packer-default-plugin-name-] builders from docker plugin
2022/07/12 19:47:47 [INFO] found external [import push save tag] post-processors from docker plugin
2022/07/12 19:47:47 [TRACE] discovering plugins in .
2022/07/12 19:47:47 [DEBUG] Discovered plugin: docker = /Users/devashish/repos/personal/packer_tutorial/packer-plugin-docker
2022/07/12 19:47:47 [INFO] found external [-packer-default-plugin-name-] builders from docker plugin
2022/07/12 19:47:47 [INFO] found external [import push save tag] post-processors from docker plugin
2022/07/12 19:47:47 [INFO] PACKER_CONFIG env var not set; checking the default config file path
2022/07/12 19:47:47 [INFO] PACKER_CONFIG env var set; attempting to open config file: /Users/devashish/.packerconfig
2022/07/12 19:47:47 [WARN] Config file doesn't exist: /Users/devashish/.packerconfig
2022/07/12 19:47:47 Old default config directory found: /Users/devashish/.packer.d
2022/07/12 19:47:47 [INFO] Setting cache directory: /Users/devashish/.cache/packer
2022/07/12 19:47:47 Old default config directory found: /Users/devashish/.packer.d
2022/07/12 19:47:47 [TRACE] Starting external plugin /Users/devashish/repos/personal/packer_tutorial/packer-plugin-docker start builder -packer-default-plugin-name-
2022/07/12 19:47:47 Starting plugin: /Users/devashish/repos/personal/packer_tutorial/packer-plugin-docker []string{"/Users/devashish/repos/personal/packer_tutorial/packer-plugin-docker", "start", "builder", "-packer-default-plugin-name-"}
2022/07/12 19:47:47 Waiting for RPC address for: /Users/devashish/repos/personal/packer_tutorial/packer-plugin-docker
2022/07/12 19:47:47 packer-plugin-docker plugin: 2022/07/12 19:47:47 Plugin address: unix /var/folders/cz/q3cr3tld2457gtlgw7qs1kqc0000gq/T/packer-plugin2355989151
2022/07/12 19:47:47 packer-plugin-docker plugin: 2022/07/12 19:47:47 Waiting for connection...
2022/07/12 19:47:47 Received unix RPC address for /Users/devashish/repos/personal/packer_tutorial/packer-plugin-docker: addr is /var/folders/cz/q3cr3tld2457gtlgw7qs1kqc0000gq/T/packer-plugin2355989151
2022/07/12 19:47:47 packer-plugin-docker plugin: 2022/07/12 19:47:47 Serving a plugin connection...
2022/07/12 19:47:47 packer-plugin-docker plugin: 2022/07/12 19:47:47 [TRACE] starting builder -packer-default-plugin-name-
2022/07/12 19:47:47 Build debug mode: false
2022/07/12 19:47:47 Force build: false
2022/07/12 19:47:47 On error:
2022/07/12 19:47:47 Waiting on builds to complete...
2022/07/12 19:47:47 Starting build run: packer-docker-pr-103.docker.oraclelinux2
2022/07/12 19:47:47 Running builder:
2022/07/12 19:47:47 [INFO] (telemetry) Starting builder docker.oraclelinux2
packer-docker-pr-103.docker.oraclelinux2: output will be in this color.
2022/07/12 19:47:47 packer-plugin-docker plugin: 2022/07/12 19:47:47 [DEBUG] Docker version: 20.0.0
2022/07/12 19:47:47 packer-plugin-docker plugin: 2022/07/12 19:47:47 [DEBUG] Container will be committed
==> packer-docker-pr-103.docker.oraclelinux2: Creating a temporary directory for sharing data...
2022/07/12 19:47:47 packer-plugin-docker plugin: 2022/07/12 19:47:47 Old default config directory found: /Users/devashish/.packer.d
2022/07/12 19:47:47 packer-plugin-docker plugin: 2022/07/12 19:47:47 Set Packer temp dir to /Users/devashish/.packer.d/tmp2498624076
==> packer-docker-pr-103.docker.oraclelinux2: Pulling Docker image: --platform=linux/amd64 oraclelinux:8
2022/07/12 19:47:47 packer-plugin-docker plugin: 2022/07/12 19:47:47 Executing: /usr/local/bin/docker [pull --platform=linux/amd64 oraclelinux:8]
packer-docker-pr-103.docker.oraclelinux2: "docker pull" requires exactly 1 argument.
packer-docker-pr-103.docker.oraclelinux2: See 'docker pull --help'.
packer-docker-pr-103.docker.oraclelinux2: Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST]
packer-docker-pr-103.docker.oraclelinux2: Pull an image or a repository from a registry
==> packer-docker-pr-103.docker.oraclelinux2: Error pulling Docker image: Bad exit status: 1
2022/07/12 19:47:47 [INFO] (telemetry) ending docker.oraclelinux2
==> Wait completed after 141 milliseconds 568 microseconds
2022/07/12 19:47:47 machine readable: error-count []string{"1"}
==> Some builds didn't complete successfully and had errors:
2022/07/12 19:47:47 machine readable: packer-docker-pr-103.docker.oraclelinux2,error []string{"Error pulling Docker image: Bad exit status: 1"}
==> Builds finished but no artifacts were created.
Build 'packer-docker-pr-103.docker.oraclelinux2' errored after 141 milliseconds 526 microseconds: Error pulling Docker image: Bad exit status: 1
2022/07/12 19:47:47 [INFO] (telemetry) Finalizing.
==> Wait completed after 141 milliseconds 568 microseconds
==> Some builds didn't complete successfully and had errors:
--> packer-docker-pr-103.docker.oraclelinux2: Error pulling Docker image: Bad exit status: 1
==> Builds finished but no artifacts were created.
2022/07/12 19:47:47 waiting for all plugin processes to complete...
2022/07/12 19:47:47 /Users/devashish/repos/personal/packer_tutorial/packer-plugin-docker: plugin process exited
=> How to build an image with your binary?
- Go to the root of this directory and checkout to this branch
- Run
make build
, this will create a binary with the namepacker-plugin-docker
- Move the binary to the same dir level where your packer template is
- Go to your packer template directory and start the build
Could you please look into this? If something is missing on my side, please let me know.
try like so: source "docker" "oraclelinux2" { |
@devashish-patel the |
Yes, it was a miss on my side. Here are the correct template and logs: => Teamplate: source "docker" "oraclelinux2" {
image = "oraclelinux:8"
commit = true
platform = "linux/amd64"
}
build {
name = "packer-docker-pr-103"
sources = [
"source.docker.oraclelinux2",
]
post-processor "docker-tag" {
repository = "packer-tutorial"
tags = ["packer-rocks-with-platform"]
only = ["docker.oraclelinux2"]
}
} => Logs:
*expected logs noted with |
--platform
docker CLI argument to target the platform specific image architecture
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@lifeofguenter, thanks again for the contribution! We will release a new version with this change soon!
Adding support for
--platform
arg on pull, push, import and run.Closes #97