TritonDataCenter / sdc-imgapi

SDC internal API for managing OS images
Mozilla Public License 2.0
5 stars 18 forks source link

prepare-image doesn't support alpine linux #17

Open Smithx10 opened 5 years ago

Smithx10 commented 5 years ago

https://github.com/joyent/sdc-imgapi/blob/master/tools/prepare-image/linux-prepare-image

Doesn't work with alpine.

Workflow errors out:

cnapi.poll_task {"message":"prepare-image script error while preparing VM ebd8367a-11de-c549-cce8-e5bb811264f2:\n ...\n [2019-08-15T04:12:06Z] :34: export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games\n [2019-08-15T04:12:06Z] :34: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games\n [2019-08-15T04:12:06Z] :39: trap 'errexit $?' EXIT\n [2019-08-15T04:12:06Z] :244: /usr/sbin/mdata-put prepare-image:state running\n [2019-08-15T04:12:06Z] :248: [[ -f /etc/os-release ]]\n [2019-08-15T04:12:06Z] :249: . /etc/os-release\n [[2019-08-15T04:12:06Z] :1: NAME='Alpine Linux'\n [[2019-08-15T04:12:06Z] :2: ID=alpine\n [[2019-08-15T04:12:06Z] :3: VERSION_ID=3.10.1\n [[2019-08-15T04:12:06Z] :4: PRETTY_NAME='Alpine Linux v3.10'\n [[2019-08-15T04:12:06Z] :5: HOME_URL=https://alpinelinux.org/\n [[2019-08-15T04:12:06Z] :6: BUG_REPORT_URL=https://bugs.alpinelinux.org/\n [2019-08-15T04:12:06Z] :250: [[ alpine == \c\e\n\t\o\s ]]\n [2019-08-15T04:12:06Z] :252: [[ alpine == \d\e\b\i\a\n ]]\n [2019-08-15T04:12:06Z] :254: [[ alpine == \f\e\d\o\r\a ]]\n [2019-08-15T04:12:06Z] :256: [[ alpine == \u\b\u\n\t\u ]]\n [2019-08-15T04:12:06Z] :267: reset_provision_status\n [2019-08-15T04:12:06Z] :235: reset_provision_status(): [[ -f /var/svc/provision_success ]]\n [2019-08-15T04:12:06Z] :236: reset_provision_status(): rm -f /var/svc/provision_success\n [2019-08-15T04:12:06Z] :268: prepare_lib_smartdc\n [2019-08-15T04:12:06Z] :223: prepare_lib_smartdc(): [[ -d /lib/smartdc ]]\n [2019-08-15T04:12:06Z] :226: prepare_lib_smartdc(): rm -f /lib/smartdc/.firstboot-complete-do-not-delete\n [2019-08-15T04:12:06Z] :229: prepare_lib_smartdc(): chown -R root:root /lib/smartdc\n [2019-08-15T04:12:06Z] :269: cleanup_logs\n [2019-08-15T04:12:06Z] :75: cleanup_logs(): find /var/log -type f -exec sh -c '>{}' ';'\n [2019-08-15T04:12:06Z] :270: cleanup_disks\n [2019-08-15T04:12:06Z] :114: cleanup_disks(): echo 'removing /dev/vdb and cloud-init entries from fstab'\n [2019-08-15T04:12:06Z] :115: cleanup_disks(): sed -i -e '/^\/dev\/vdb/d' -e '/[\t|,]comment=cloudconfig[,|\t]/d' /etc/fstab\n [2019-08-15T04:12:06Z] :271: cleanup_ssh\n [2019-08-15T04:12:06Z] :110: cleanup_ssh(): find /etc/ssh -type f -name 'sshhost'\n [2019-08-15T04:12:06Z] :110: cleanup_ssh(): xargs rm -f\n [2019-08-15T04:12:06Z] :272: cleanup_root\n [2019-08-15T04:12:06Z] :98: cleanup_root(): history -c\n [2019-08-15T04:12:06Z] :99: cleanup_root(): history -w\n [2019-08-15T04:12:06Z] :99: cleanup_root(): true\n [[2019-08-15T04:12:06Z] :103: cleanup_root(): mdata_get_pi root-password-hash\n [[2019-08-15T04:12:06Z] :66: mdata_get_pi(): typeset key=root-password-hash\n [[2019-08-15T04:12:06Z] :68: mdata_get_pi(): mdata-get prepare-image:root-password-hash\n [[2019-08-15T04:12:06Z] :68: mdata_get_pi(): true\n [2019-08-15T04:12:06Z] :103: cleanup_root(): usermod -p '' root\n [2019-08-15T04:12:06Z] :1: cleanup_root(): errexit 127\n [2019-08-15T04:12:06Z] :49: errexit(): set +o xtrace\n ","name":"WError","stack":"PrepareImageError: prepare-image script error while preparing VM ebd8367a-11de-c549-cce8-e5bb811264f2:\n ...\n [2019-08-15T04:12:06Z] :34: export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games\n [2019-08-15T04:12:06Z] :34: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games\n [2019-08-15T04:12:06Z] :39: trap 'errexit $?' EXIT\n [2019-08-15T04:12:06Z] :244: /usr/sbin/mdata-put prepare-image:state running\n [2019-08-15T04:12:06Z] :248: [[ -f /etc/os-release ]]\n [2019-08-15T04:12:06Z] :249: . /etc/os-release\n [[2019-08-15T04:12:06Z] :1: NAME='Alpine Linux'\n [[2019-08-15T04:12:06Z] :2: ID=alpine\n [[2019-08-15T04:12:06Z] :3: VERSION_ID=3.10.1\n [[2019-08-15T04:12:06Z] :4: PRETTY_NAME='Alpine Linux v3.10'\n [[2019-08-15T04:12:06Z] :5: HOME_URL=https://alpinelinux.org/\n [[2019-08-15T04:12:06Z] :6: BUG_REPORT_URL=https://bugs.alpinelinux.org/\n [2019-08-15T04:12:06Z] :250: [[ alpine == \c\e\n\t\o\s ]]\n [2019-08-15T04:12:06Z] :252: [[ alpine == \d\e\b\i\a\n ]]\n [2019-08-15T04:12:06Z] :254: [[ alpine == \f\e\d\o\r\a ]]\n [2019-08-15T04:12:06Z] :256: [[ alpine == \u\b\u\n\t\u ]]\n [2019-08-15T04:12:06Z] :267: reset_provision_status\n [2019-08-15T04:12:06Z] :235: reset_provision_status(): [[ -f /var/svc/provision_success ]]\n [2019-08-15T04:12:06Z] :236: reset_provision_status(): rm -f /var/svc/provision_success\n [2019-08-15T04:12:06Z] :268: prepare_lib_smartdc\n [2019-08-15T04:12:06Z] :223: prepare_lib_smartdc(): [[ -d /lib/smartdc ]]\n [2019-08-15T04:12:06Z] :226: prepare_lib_smartdc(): rm -f /lib/smartdc/.firstboot-complete-do-not-delete\n [2019-08-15T04:12:06Z] :229: prepare_lib_smartdc(): chown -R root:root /lib/smartdc\n [2019-08-15T04:12:06Z] :269: cleanup_logs\n [2019-08-15T04:12:06Z] :75: cleanup_logs(): find /var/log -type f -exec sh -c '>{}' ';'\n [2019-08-15T04:12:06Z] :270: cleanup_disks\n [2019-08-15T04:12:06Z] :114: cleanup_disks(): echo 'removing /dev/vdb and cloud-init entries from fstab'\n [2019-08-15T04:12:06Z] :115: cleanup_disks(): sed -i -e '/^\/dev\/vdb/d' -e '/[\t|,]comment=cloudconfig[,|\t]/d' /etc/fstab\n [2019-08-15T04:12:06Z] :271: cleanup_ssh\n [2019-08-15T04:12:06Z] :110: cleanup_ssh(): find /etc/ssh -type f -name 'sshhost'\n [2019-08-15T04:12:06Z] :110: cleanup_ssh(): xargs rm -f\n [2019-08-15T04:12:06Z] :272: cleanup_root\n [2019-08-15T04:12:06Z] :98: cleanup_root(): history -c\n [2019-08-15T04:12:06Z] :99: cleanup_root(): history -w\n [2019-08-15T04:12:06Z] :99: cleanup_root(): true\n [[2019-08-15T04:12:06Z] :103: cleanup_root(): mdata_get_pi root-password-hash\n [[2019-08-15T04:12:06Z] :66: mdata_get_pi(): typeset key=root-password-hash\n [[2019-08-15T04:12:06Z] :68: mdata_get_pi(): mdata-get prepare-image:root-password-hash\n [[2019-08-15T04:12:06Z] :68: mdata_get_pi(): true\n [2019-08-15T04:12:06Z] :103: cleanup_root(): usermod -p '' root\n [2019-08-15T04:12:06Z] :1: cleanup_root(): errexit 127\n [2019-08-15T04:12:06Z] :49: errexit(): set +o xtrace\n \n at /usr/img/lib/imgadm.js:3767:26\n at done (/usr/img/lib/common.js:601:17)\n at /usr/img/node_modules/async/lib/async.js:729:17\n at /usr/img/lib/common.js:587:21\n at /usr/img/lib/common.js:532:13\n at ChildProcess.exithandler (child_process.js:635:7)\n at ChildProcess.EventEmitter.emit (events.js:98:17)\n at maybeClose (child_process.js:743:16)\n at Process.ChildProcess._handle.onexit (child_process.js:810:5)","code":"PrepareImageError"}

mgerdts commented 5 years ago

The error can be much more readable with a bit of massaging.

$ cat error.json | sed -e 's/.c.e.n.t.o.s/centos/g' -e 's/.u.b.u.n.t.u/ubuntu/g' \
    -e 's/.d.e.b.i.a.n/debian/g' -e s/.f.e.d.o.r.a/fedora/g | json stack
PrepareImageError: prepare-image script error while preparing VM ebd8367a-11de-c549-cce8-e5bb811264f2:
 ...
 [2019-08-15T04:12:06Z] :34: export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
 [2019-08-15T04:12:06Z] :34: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
 [2019-08-15T04:12:06Z] :39: trap 'errexit $?' EXIT
 [2019-08-15T04:12:06Z] :244: /usr/sbin/mdata-put prepare-image:state running
 [2019-08-15T04:12:06Z] :248: [[ -f /etc/os-release ]]
 [2019-08-15T04:12:06Z] :249: . /etc/os-release
 [[2019-08-15T04:12:06Z] :1: NAME='Alpine Linux'
 [[2019-08-15T04:12:06Z] :2: ID=alpine
 [[2019-08-15T04:12:06Z] :3: VERSION_ID=3.10.1
 [[2019-08-15T04:12:06Z] :4: PRETTY_NAME='Alpine Linux v3.10'
 [[2019-08-15T04:12:06Z] :5: HOME_URL=https://alpinelinux.org/
 [[2019-08-15T04:12:06Z] :6: BUG_REPORT_URL=https://bugs.alpinelinux.org/
 [2019-08-15T04:12:06Z] :250: [[ alpine == centos ]]
 [2019-08-15T04:12:06Z] :252: [[ alpine == debian ]]
 [2019-08-15T04:12:06Z] :254: [[ alpine == fedora ]]
 [2019-08-15T04:12:06Z] :256: [[ alpine == ubuntu ]]
 [2019-08-15T04:12:06Z] :267: reset_provision_status
 [2019-08-15T04:12:06Z] :235: reset_provision_status(): [[ -f /var/svc/provision_success ]]
 [2019-08-15T04:12:06Z] :236: reset_provision_status(): rm -f /var/svc/provision_success
 [2019-08-15T04:12:06Z] :268: prepare_lib_smartdc
 [2019-08-15T04:12:06Z] :223: prepare_lib_smartdc(): [[ -d /lib/smartdc ]]
 [2019-08-15T04:12:06Z] :226: prepare_lib_smartdc(): rm -f /lib/smartdc/.firstboot-complete-do-not-delete
 [2019-08-15T04:12:06Z] :229: prepare_lib_smartdc(): chown -R root:root /lib/smartdc
 [2019-08-15T04:12:06Z] :269: cleanup_logs
 [2019-08-15T04:12:06Z] :75: cleanup_logs(): find /var/log -type f -exec sh -c '>{}' ';'
 [2019-08-15T04:12:06Z] :270: cleanup_disks
 [2019-08-15T04:12:06Z] :114: cleanup_disks(): echo 'removing /dev/vdb and cloud-init entries from fstab'
 [2019-08-15T04:12:06Z] :115: cleanup_disks(): sed -i -e '/^/dev/vdb/d' -e '/[  |,]comment=cloudconfig[,|   ]/d' /etc/fstab
 [2019-08-15T04:12:06Z] :271: cleanup_ssh
 [2019-08-15T04:12:06Z] :110: cleanup_ssh(): find /etc/ssh -type f -name 'ssh_host_'
 [2019-08-15T04:12:06Z] :110: cleanup_ssh(): xargs rm -f
 [2019-08-15T04:12:06Z] :272: cleanup_root
 [2019-08-15T04:12:06Z] :98: cleanup_root(): history -c
 [2019-08-15T04:12:06Z] :99: cleanup_root(): history -w
 [2019-08-15T04:12:06Z] :99: cleanup_root(): true
 [[2019-08-15T04:12:06Z] :103: cleanup_root(): mdata_get_pi root-password-hash
 [[2019-08-15T04:12:06Z] :66: mdata_get_pi(): typeset key=root-password-hash
 [[2019-08-15T04:12:06Z] :68: mdata_get_pi(): mdata-get prepare-image:root-password-hash
 [[2019-08-15T04:12:06Z] :68: mdata_get_pi(): true
 [2019-08-15T04:12:06Z] :103: cleanup_root(): usermod -p '' root
 [2019-08-15T04:12:06Z] :1: cleanup_root(): errexit 127
 [2019-08-15T04:12:06Z] :49: errexit(): set +o xtrace

 at /usr/img/lib/imgadm.js:3767:26
 at done (/usr/img/lib/common.js:601:17)
 at /usr/img/node_modules/async/lib/async.js:729:17
 at /usr/img/lib/common.js:587:21
 at /usr/img/lib/common.js:532:13
 at ChildProcess.exithandler (child_process.js:635:7)
 at ChildProcess.EventEmitter.emit (events.js:98:17)
 at maybeClose (child_process.js:743:16)
 at Process.ChildProcess._handle.onexit (child_process.js:810:5)

I've logged this in Jira as TRITON-1873. That ticket has a link to a code review with the proposed fix.