solo-io / packer-plugin-arm-image

Packer plugin for ARM images
Apache License 2.0
426 stars 104 forks source link

Unable to build image using docker, pre-built docker, or vagrant #143

Closed vincentracine closed 2 years ago

vincentracine commented 2 years ago

I've previously been successful at building images using this plugin back in Feb 2022. I'm not sure what has changed either with this repository, Packer, or my setup. I've tried to dig into the issue but really hitting a dead-end. I'm using a Macbook Pro macOS Big Sur (Intel chip). The setup that previously worked for me was the local self-built docker. I tried Vagrant and the pre-built docker setup today to see if I could get that running but I couldn't.

Packer template:

{
  "variables": {
    "release_version": "2022.3.1-dev",
    "postgres_docker_image_version": "10.13.arm",
    "sentry_docker_image_version": "2022.9.56"
  },
  "builders": [
    {
      "type": "arm-image",
      "iso_url": "https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2020-02-14/2020-02-13-raspbian-buster-lite.zip",
      "iso_checksum": "sha256:12ae6e17bf95b6ba83beca61e7394e7411b45eba7e6a520f434b0748ea7370e8",
      "output_filename": "/build/release/automifyOS-{{user `release_version`}}.img",
      "target_image_size": 4294967296
    }
  ],
  "provisioners": [
    {
      "type": "file",
      "source": "/files/config.txt",
      "destination": "/boot/config.txt"
    }
  ]
}

Failure using locally built Docker image (Dockerfile below):

(base) vincentracine@VR-Macbook automifyOS % sh build.sh 
Building packer builder container: docker.pkg.github.com/solo-io/packer-builder-arm-image/packer-builder-arm
[+] Building 1.5s (19/19) FINISHED                                                                                                                                           
 => [internal] load build definition from Dockerfile                                                                                                                    0.0s
 => => transferring dockerfile: 37B                                                                                                                                     0.0s
 => [internal] load .dockerignore                                                                                                                                       0.0s
 => => transferring context: 2B                                                                                                                                         0.0s
 => [internal] load metadata for docker.io/library/ubuntu:focal                                                                                                         1.4s
 => [internal] load metadata for docker.io/library/golang:buster                                                                                                        1.4s
 => [auth] library/ubuntu:pull token for registry-1.docker.io                                                                                                           0.0s
 => [auth] library/golang:pull token for registry-1.docker.io                                                                                                           0.0s
 => [builder 1/5] FROM docker.io/library/golang:buster@sha256:3ad5048c0c63cbc32d1c576bda513ebfd6e1914b6cd57837e0cd0a31fe81de69                                          0.0s
 => [internal] load build context                                                                                                                                       0.0s
 => => transferring context: 35B                                                                                                                                        0.0s
 => [stage-1 1/6] FROM docker.io/library/ubuntu:focal@sha256:fd92c36d3cb9b1d027c4d2a72c6bf0125da82425fc2ca37c414d4f010180dc19                                           0.0s
 => CACHED [stage-1 2/6] RUN apt-get update -qq  && DEBIAN_FRONTEND=noninteractive apt-get install -qqy   qemu-user-static   kpartx   unzip   wget   curl   sudo  && r  0.0s
 => CACHED [stage-1 3/6] RUN wget https://releases.hashicorp.com/packer/1.7.3/packer_1.7.3_linux_amd64.zip -O /tmp/packer.zip &&   unzip /tmp/packer.zip -d /bin &&     0.0s
 => CACHED [stage-1 4/6] WORKDIR /build                                                                                                                                 0.0s
 => CACHED [stage-1 5/6] COPY entrypoint.sh /entrypoint.sh                                                                                                              0.0s
 => CACHED [builder 2/5] RUN apt-get update -qq  && apt-get install -qqy git &&  mkdir /build                                                                           0.0s
 => CACHED [builder 3/5] WORKDIR /build                                                                                                                                 0.0s
 => CACHED [builder 4/5] RUN git clone --depth 1 https://github.com/solo-io/packer-builder-arm-image /build                                                             0.0s
 => CACHED [builder 5/5] RUN go build -o packer-builder-arm-image                                                                                                       0.0s
 => CACHED [stage-1 6/6] COPY --from=builder /build/packer-builder-arm-image /bin/packer-builder-arm-image                                                              0.0s
 => exporting to image                                                                                                                                                  0.0s
 => => exporting layers                                                                                                                                                 0.0s
 => => writing image sha256:0cd13df421174b3b8e64169c99e0e84d2c90852183192f25c9c0a750519743a2                                                                            0.0s
 => => naming to docker.pkg.github.com/solo-io/packer-builder-arm-image/packer-builder-arm                                                                              0.0s
Attempting to build the iso image
Debug:
pwd: /build
Running /bin/packer build -force templates/simple-template.json
Error: Failed to initialize build "arm-image"

error initializing builder 'arm-image': plugin exited before we could connect

==> Wait completed after 3 microseconds

==> Builds finished but no artifacts were created.
panic: needs at least one argument
2022/06/25 15:02:46 packer-builder-arm-image plugin: 
2022/06/25 15:02:46 packer-builder-arm-image plugin: goroutine 1 [running]:
2022/06/25 15:02:46 packer-builder-arm-image plugin: main.main()
2022/06/25 15:02:46 packer-builder-arm-image plugin:    /build/main.go:17 +0xf1
2022/06/25 15:02:46 /usr/bin/packer-builder-arm-image: plugin process exited
2022/06/25 15:02:46 ui error: Error: Failed to initialize build "arm-image"

error initializing builder 'arm-image': plugin exited before we could connect

2022/06/25 15:02:46 Build debug mode: false
2022/06/25 15:02:46 Force build: true
2022/06/25 15:02:46 On error: 
2022/06/25 15:02:46 Waiting on builds to complete...
2022/06/25 15:02:46 ui: 
==> Wait completed after 3 microseconds
2022/06/25 15:02:46 ui: 
==> Builds finished but no artifacts were created.
2022/06/25 15:02:46 [INFO] (telemetry) Finalizing.
2022/06/25 15:02:46 waiting for all plugin processes to complete...

!!!!!!!!!!!!!!!!!!!!!!!!!!! PACKER CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Packer crashed! This is always indicative of a bug within Packer.
A crash log has been placed at "crash.log" relative to your current
working directory. It would be immensely helpful if you could please
report the crash with Packer[1] so that we can fix this.

[1]: https://github.com/hashicorp/packer/issues

!!!!!!!!!!!!!!!!!!!!!!!!!!! PACKER CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!
Build failed. Exiting.

Here are the packer logs for the build above (packerlog.txt):

2022/06/25 14:58:48 [INFO] Packer version: 1.7.3 [go1.16.5 linux amd64]
2022/06/25 14:58:48 [TRACE] discovering plugins in /usr/bin
2022/06/25 14:58:48 [DEBUG] Discovered plugin: arm-image = /usr/bin/packer-builder-arm-image
2022/06/25 14:58:48 [INFO] using external builders: [arm-image]
2022/06/25 14:58:48 [TRACE] discovering plugins in /root/.packer.d/plugins
2022/06/25 14:58:48 [TRACE] discovering plugins in .
2022/06/25 14:58:48 [INFO] PACKER_CONFIG env var not set; checking the default config file path
2022/06/25 14:58:48 [INFO] PACKER_CONFIG env var set; attempting to open config file: /root/.packerconfig
2022/06/25 14:58:48 [WARN] Config file doesn't exist: /root/.packerconfig
2022/06/25 14:58:48 [INFO] Setting cache directory: /build/packer_cache
e: Running in background, not using a TTY
2022/06/25 14:58:48 [TRACE] Starting external plugin /usr/bin/packer-builder-arm-image 
2022/06/25 14:58:48 Starting plugin: /usr/bin/packer-builder-arm-image []string{"/usr/bin/packer-builder-arm-image"}
2022/06/25 14:58:48 Waiting for RPC address for: /usr/bin/packer-builder-arm-image
2022/06/25 14:58:48 packer-builder-arm-image plugin: panic: needs at least one argument
2022/06/25 14:58:48 packer-builder-arm-image plugin: 
2022/06/25 14:58:48 packer-builder-arm-image plugin: goroutine 1 [running]:
2022/06/25 14:58:48 packer-builder-arm-image plugin: main.main()
2022/06/25 14:58:48 packer-builder-arm-image plugin:    /build/main.go:17 +0xf1
2022/06/25 14:58:48 /usr/bin/packer-builder-arm-image: plugin process exited
2022/06/25 14:58:48 ui error: Error: Failed to initialize build "arm-image"

error initializing builder 'arm-image': plugin exited before we could connect

2022/06/25 14:58:48 Build debug mode: false
2022/06/25 14:58:48 Force build: true
2022/06/25 14:58:48 On error: 
2022/06/25 14:58:48 Waiting on builds to complete...
2022/06/25 14:58:48 ui: 
==> Wait completed after 2 microseconds
2022/06/25 14:58:48 ui: 
==> Builds finished but no artifacts were created.
2022/06/25 14:58:48 [INFO] (telemetry) Finalizing.
2022/06/25 14:58:49 waiting for all plugin processes to complete...

Failure using Vagrant setup, please note that build-env and packer-plugin-arm-image work successfully:

(base) vincentracine@VR-Macbook packer-plugin-arm-image % vagrant provision --provision-with build-image
==> default: Running provisioner: build-image (shell)...
    default: Running: /var/folders/mg/nm64crnd5tg8gftn8km4dk7h0000gn/T/vagrant-shell20220625-6974-6lnen.sh
    default: + set -e
    default: + export PACKERFILE=samples/raspbian_golang.json
    default: + PACKERFILE=samples/raspbian_golang.json
    default: + PLUGIN_DIR=/root/.packer.d/plugins
    default: + sudo mkdir -p /root/.packer.d/plugins
    default: + sudo cp /vagrant/packer-plugin-arm-image /root/.packer.d/plugins/
    default: + sudo test '!' -f /root/.packer.d/plugins/packer-plugin-arm-image
    default: + echo 'Attempting to build image'
    default: Attempting to build image
    default: ++ mktemp
    default: + PACKER_LOG=/tmp/tmp.xD8xOOkYbq
    default: + export PACKER_CONFIG_DIR=/root/
    default: + PACKER_CONFIG_DIR=/root/
    default: + [[ -f /vagrant/samples/raspbian_golang.json ]]
    default: + tee /tmp/tmp.xD8xOOkYbq
    default: + sudo -E packer build /vagrant/samples/raspbian_golang.json
    default:  Error loading configuration:
    default: 
    default: exit status 2
    default: ++ grep -Po '(?<=Build '\'').*(?='\'' finished.)' /tmp/tmp.xD8xOOkYbq
    default: + BUILD_NAME=
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

Failure using pre-built Docker image.

(base) vincentracine@VR-Macbook packer-plugin-arm-image % docker run \
  --rm \
  --privileged \
  -v /dev:/dev \
  -v ${PWD}:/build:ro \
  -v ${PWD}/packer_cache:/build/packer_cache \
  -v ${PWD}/output-arm-image:/build/output-arm-image \
  ghcr.io/solo-io/packer-plugin-arm-image build samples/raspbian_golang.json
Unable to find image 'ghcr.io/solo-io/packer-plugin-arm-image:latest' locally
latest: Pulling from solo-io/packer-plugin-arm-image
d5fd17ec1767: Pull complete 
edb4a383f815: Pull complete 
b3d0203c6e24: Pull complete 
689475015b8b: Pull complete 
c8ea965144e0: Pull complete 
e192a914ff66: Pull complete 
Digest: sha256:cd1ef12597e002509ec4cb89543723a8dbf41e4a86e15f291f96950d814fc872
Status: Downloaded newer image for ghcr.io/solo-io/packer-plugin-arm-image:latest
running /bin/packer
 Error loading configuration: 

exit status 2

Local Dockerfile:

FROM golang:buster AS builder
RUN apt-get update -qq \
 && apt-get install -qqy git && \
 mkdir /build

WORKDIR /build

# if you wish to build from upstream, un comment this line, and comment lines below
RUN git clone --depth 1 https://github.com/solo-io/packer-builder-arm-image /build

RUN go build -o packer-builder-arm-image

FROM ubuntu:focal

RUN apt-get update -qq \
 && DEBIAN_FRONTEND=noninteractive apt-get install -qqy \
  qemu-user-static \
  kpartx \
  unzip \
  wget \
  curl \
  sudo \
 && rm -rf /var/lib/apt/lists/*

ENV PACKER_VERSION 1.7.3

RUN wget https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip -O /tmp/packer.zip && \
  unzip /tmp/packer.zip -d /bin && \
  rm /tmp/packer.zip
WORKDIR /build
COPY entrypoint.sh /entrypoint.sh

COPY --from=builder /build/packer-builder-arm-image /bin/packer-builder-arm-image
ENTRYPOINT ["/entrypoint.sh"]

My entrypoint.sh:

#!/bin/bash

/usr/sbin/update-binfmts --enable qemu-arm >/dev/null 2>&1

PACKER=/bin/packer

echo "Debug:"
echo "pwd: $(pwd)"

mkdir -p /root/packer_tmp
export TMPDIR=/root/packer_tmp
export PACKER_TMP_DIR=/root/packer_tmp
export PACKER_LOG=1
export PACKER_LOG_PATH="/build/packerlog.txt"

echo "Running $PACKER ${@}"

$PACKER "${@}"

if [ ! $? -eq 0 ]; then
    echo "Build failed. Exiting."
    echo "packer_tmp: $(ls -la /root/packer_tmp)"
    exit 1
else
    echo "Image built successfully."
    exit 0
fi
vincentracine commented 2 years ago

Closing as I restarted from scratch and looks like my Dockerfile and entrypoint.sh were severely out-of-date. I can now build again.