github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/containers/compilers/firecracker/build-image (about)

     1  #!/bin/bash
     2  
     3  # run this container like so
     4  # docker run --rm --privileged -v /path/to/code:/go/src/gopath/to/code firecracker-builder
     5  
     6  set -ex
     7  
     8  
     9  dd if=/dev/zero of=/tmp/rootfs bs=1M count=50
    10  mkfs.ext4 /tmp/rootfs
    11  
    12  mkdir /tmp/tmp
    13  # mknod /dev/loop0 b 7 0 
    14  mount /tmp/rootfs /tmp/tmp -o loop
    15  
    16  tar xzf /tmp/alpine-minirootfs-3.8.1-x86_64.tar.gz -C /tmp/tmp
    17  
    18  CODEDIR=${CODEDIR:-/opt/code}
    19  
    20  cp -r  /tmp/overlay/* /tmp/tmp/
    21  
    22  cd $CODEDIR
    23  go get -d -v ./...
    24  CGO_ENABLED=0 go build -o /tmp/tmp/usr/local/bin/program
    25  
    26  # not using gopath.. so no need for: cp /go/bin/* /tmp/tmp/usr/local/bin/program
    27  
    28  cat > /tmp/tmp/prepare.sh <<EOF
    29  passwd root -d root
    30  apk add -u openrc ca-certificates
    31  exit 
    32  EOF
    33  
    34  chroot /tmp/tmp/ /bin/sh /prepare.sh
    35  
    36  rm /tmp/tmp/prepare.sh 
    37  
    38  umount /tmp/tmp
    39  
    40  OUTDIR=${OUTDIR:-$CODEDIR}
    41  
    42  mkdir -p $OUTDIR || :
    43  
    44  cp /tmp/rootfs $OUTDIR