maier / vagrant-alpine

Vagrant plugin for Alpine Linux Guest
MIT License
137 stars 10 forks source link

`echo 'something' >> /etc/apk/repositories` results in permissions issue #21

Closed samlevin closed 7 years ago

samlevin commented 7 years ago

I'm trying to programmatically modify /etc/apk/repositories through the Vagrantfile generated by this repo. When I attempt via:

echo 'http://nl.alpinelinux.org/alpine/v3.3/main' >> /etc/apk/repositories'

I get the following: bash: /etc/apk/repositories: Permission denied

Prefixing the command with sudo doesn't appear to make a difference. Am I missing something obvious?

Use-case: Trying to install docker on an alpine vagrantbox (at provision time) using instructions here: https://wiki.alpinelinux.org/wiki/Docker

Thanks!

maier commented 7 years ago

This Vagrantfile worked for me.

Vagrant.configure(2) do |config|
  config.vm.define "alpine" do |alpine|
    alpine.vm.box = "maier/alpine-3.5-x86_64"
    alpine.vm.synced_folder ".", "/vagrant", disabled: true
    alpine.vm.provider "virtualbox" do |vb|
      vb.name = 'Alpine'
      vb.cpus = 2
      vb.memory = 2048
      vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on", "--nic1", "nat", "--cableconnected1", "on"]
    end

    alpine.vm.provision 'shell', inline: <<-SHELL
        echo "Add community repository"
        echo 'http://dl-cdn.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories

        echo "Update repositories"
        apk update

        echo "Install docker package"
        apk add docker

        echo "Enable docker service"
        rc-update add docker boot

        echo "Start docker service"
        service docker start
    SHELL
  end
end
$  vagrant up
Bringing machine 'alpine' up with 'virtualbox' provider...
==> alpine: Importing base box 'maier/alpine-3.5-x86_64'...
[snip]
==> alpine: Running provisioner: shell...
    alpine: Running: inline script
==> alpine: Add community repository
==> alpine: Update repositories
==> alpine: fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
==> alpine: fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
==> alpine: v3.5.2-70-gec9876f375 [http://dl-cdn.alpinelinux.org/alpine/v3.5/main]
==> alpine: v3.5.0-4623-g211cf411be [http://dl-cdn.alpinelinux.org/alpine/edge/community]
==> alpine: OK: 8490 distinct packages available
==> alpine: Install docker package
==> alpine: (1/5) Installing libmnl (1.0.4-r0)
==> alpine: (2/5) Installing libnftnl-libs (1.0.7-r0)
==> alpine: (3/5) Installing iptables (1.6.0-r0)
==> alpine: (4/5) Installing libseccomp (2.3.1-r0)
==> alpine: (5/5) Installing docker (17.04.0-r0)
==> alpine: Executing docker-17.04.0-r0.pre-install
==> alpine: Executing busybox-1.25.1-r0.trigger
==> alpine: OK: 148 MiB in 52 packages
==> alpine: Enable docker service
==> alpine:  * service docker added to runlevel boot
==> alpine: Start docker service
==> alpine:  * Caching service dependencies ... [ ok ]
==> alpine:  * /var/log/docker.log: creating file
==> alpine:  * /var/log/docker.log: correcting mode
==> alpine:  * /var/log/docker.log: correcting owner
==> alpine:  * Starting docker ...
==> alpine:  [ ok ]
maier commented 7 years ago

Here's one with alpine 3.3, if you need to stick with that version of alpine.

Vagrant.configure(2) do |config|
  config.vm.define "alpine" do |alpine|
    alpine.vm.box = "maier/alpine-3.3.1-x86_64"
    alpine.vm.synced_folder ".", "/vagrant", disabled: true
    alpine.vm.network "private_network", ip: "172.28.128.250"
    alpine.vm.synced_folder ".", "/vagrant", type: "nfs"
    alpine.vm.provider "virtualbox" do |vb|
      vb.name = 'Alpine'
      vb.cpus = 2
      vb.memory = 2048
      vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on", "--nic1", "nat", "--cableconnected1", "on"]
    end

    alpine.vm.provision 'shell', inline: <<-SHELL
        echo "Add community repository"
        echo 'http://dl-cdn.alpinelinux.org/alpine/v3.3/community' >> /etc/apk/repositories

        echo "Update repositories"
        apk update

        echo "Upgrade box"
        apk upgrade

        echo "Install docker package"
        apk add docker

        echo "Enable docker service"
        rc-update add docker boot

        echo "Start docker service"
        service docker start
    SHELL
  end
end
$  vagrant up
Bringing machine 'alpine' up with 'virtualbox' provider...
==> alpine: Importing base box 'maier/alpine-3.3.1-x86_64'...
[snip]
==> alpine: Installing NFS client...
==> alpine: Exporting NFS shared folders...
==> alpine: Preparing to edit /etc/exports. Administrator privileges will be required...
Password:
==> alpine: Mounting NFS shared folders...
==> alpine: Running provisioner: shell...
    alpine: Running: inline script
==> alpine: Add community repository
==> alpine: Update repositories
==> alpine: fetch http://dl-cdn.alpinelinux.org/alpine/v3.3/main/x86_64/APKINDEX.tar.gz
==> alpine: fetch http://dl-cdn.alpinelinux.org/alpine/v3.3/community/x86_64/APKINDEX.tar.gz
==> alpine: v3.3.3-258-g18e7791 [http://dl-cdn.alpinelinux.org/alpine/v3.3/main]
==> alpine: v3.3.3-196-g593fa5b [http://dl-cdn.alpinelinux.org/alpine/v3.3/community]
==> alpine: OK: 5876 distinct packages available
==> alpine: Upgrade box
==> alpine: (1/19) Upgrading musl (1.1.12-r2 -> 1.1.12-r7)
==> alpine: (2/19) Upgrading openrc (0.19-r2 -> 0.19-r4)
==> alpine: Executing openrc-0.19-r4.post-upgrade
==> alpine: (3/19) Upgrading busybox-suid (1.24.1-r7 -> 1.24.2-r1)
==> alpine: (4/19) Upgrading busybox-initscripts (2.3-r1 -> 2.3-r2)
==> alpine: (5/19) Upgrading musl-utils (1.1.12-r2 -> 1.1.12-r7)
==> alpine: (6/19) Upgrading alpine-base (3.3.1-r0 -> 3.3.3-r0)
==> alpine: (7/19) Upgrading bash (4.3.42-r3 -> 4.3.42-r6)
==> alpine: Executing bash-4.3.42-r6.post-upgrade
==> alpine: (8/19) Upgrading openssl (1.0.2f-r0 -> 1.0.2k-r0)
==> alpine: (9/19) Upgrading ca-certificates (20160104-r2 -> 20161130-r0)
==> alpine: (10/19) Upgrading libssh2 (1.6.0-r0 -> 1.6.0-r1)
==> alpine: (11/19) Upgrading curl (7.47.0-r0 -> 7.52.1-r1)
==> alpine: (12/19) Upgrading e2fsprogs-libs (1.42.13-r2 -> 1.42.13-r3)
==> alpine: (13/19) Upgrading e2fsprogs (1.42.13-r2 -> 1.42.13-r3)
==> alpine: (14/19) Upgrading cryptsetup-libs (1.7.0-r0 -> 1.7.1-r0)
==> alpine: (15/19) Upgrading mkinitfs (3.0.2-r0 -> 3.0.4-r1)
==> alpine: Executing mkinitfs-3.0.4-r1.pre-upgrade
==> alpine: Executing mkinitfs-3.0.4-r1.post-upgrade
==> alpine: (16/19) Upgrading linux-grsec (4.1.15-r2 -> 4.1.20-r0)
==> alpine: (17/19) Upgrading openssh-client (7.1_p2-r0 -> 7.2_p2-r3)
==> alpine: (18/19) Upgrading openssh-sftp-server (7.1_p2-r0 -> 7.2_p2-r3)
==> alpine: (19/19) Upgrading openssh (7.1_p2-r0 -> 7.2_p2-r3)
==> alpine: Executing busybox-1.24.2-r1.trigger
==> alpine: Executing ca-certificates-20161130-r0.trigger
==> alpine: Executing kmod-22-r0.trigger
==> alpine: Executing mkinitfs-3.0.4-r1.trigger
==> alpine: ==> initramfs: creating /boot/initramfs-grsec
==> alpine: Executing syslinux-6.03-r2.trigger
==> alpine: /boot is device /dev/sda1
==> alpine: OK: 282 MiB in 60 packages
==> alpine: Install docker package
==> alpine: (1/6) Installing iptables (1.4.21-r4)
==> alpine: (2/6) Installing expat (2.1.1-r1)
==> alpine: (3/6) Installing pcre (8.38-r1)
==> alpine: (4/6) Installing git (2.6.6-r0)
==> alpine: (5/6) Installing xz (5.2.2-r1)
==> alpine: (6/6) Installing docker (1.9.1-r2)
==> alpine: Executing docker-1.9.1-r2.pre-install
==> alpine: Executing busybox-1.24.2-r1.trigger
==> alpine: OK: 336 MiB in 66 packages
==> alpine: Enable docker service
==> alpine:  * service docker added to runlevel boot
==> alpine: Start docker service
==> alpine:  * Caching service dependencies ... [ ok ]
==> alpine:  * /var/log/docker.log: creating file
==> alpine:  * /var/log/docker.log: correcting mode
==> alpine:  * /var/log/docker.log: correcting owner
==> alpine:  * Starting docker ...
==> alpine:  [ ok ]
samlevin commented 7 years ago

Worked like a charm. Thank you very much!