Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit f78b564

Browse files
committed
Add an Alpine Vagrant configuration
This closes #221
1 parent 10ebc0d commit f78b564

4 files changed

Lines changed: 181 additions & 1 deletion

File tree

Rakefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ task :binary => :compile do
5151
end
5252

5353
namespace :build do
54-
['x86_64-linux', 'x86-linux', 'armhf-linux', 'x86_64-freebsd-10', 'x86_64-freebsd-11'].each do |arch|
54+
[
55+
'x86_64-linux',
56+
'x86-linux',
57+
'armhf-linux',
58+
'x86_64-freebsd-10',
59+
'x86_64-freebsd-11',
60+
'x86_64-linux-musl'
61+
].each do |arch|
5562
desc "build binary gem for #{arch}"
5663
task arch do
5764
arch_dir = Pathname(__FILE__).dirname.join("release/#{arch}")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM alpine:3.5
2+
3+
MAINTAINER Andrew Cutler <andrew@panubo.com>
4+
5+
RUN apk update && \
6+
apk add sudo bash git openssh rsync && \
7+
mkdir -p ~root/.ssh /etc/authorized_keys && chmod 700 ~root/.ssh/ && \
8+
sed -i -e 's@^AuthorizedKeysFile.*@@g' /etc/ssh/sshd_config && \
9+
echo -e "Port 22\n" >> /etc/ssh/sshd_config && \
10+
echo -e "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
11+
cp -a /etc/ssh /etc/ssh.cache && \
12+
rm -rf /var/cache/apk/*
13+
14+
EXPOSE 22
15+
16+
COPY entry.sh /entry.sh
17+
18+
ENTRYPOINT ["/entry.sh"]
19+
20+
CMD ["/usr/sbin/sshd", "-D", "-f", "/etc/ssh/sshd_config"]
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# All Vagrant configuration is done below. The "2" in Vagrant.configure
5+
# configures the configuration version (we support older styles for
6+
# backwards compatibility). Please don't change it unless you know what
7+
# you're doing.
8+
Vagrant.configure("2") do |config|
9+
# ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'
10+
11+
# The most common configuration options are documented and commented below.
12+
# For a complete reference, please see the online documentation at
13+
# https://docs.vagrantup.com.
14+
15+
# Every Vagrant development environment requires a box. You can search for
16+
# boxes at https://atlas.hashicorp.com/search.
17+
# config.vm.box = "base"
18+
19+
# Disable automatic box update checking. If you disable this, then
20+
# boxes will only be checked for updates when the user runs
21+
# `vagrant box outdated`. This is not recommended.
22+
# config.vm.box_check_update = false
23+
24+
# Create a forwarded port mapping which allows access to a specific port
25+
# within the machine from a port on the host machine. In the example below,
26+
# accessing "localhost:8080" will access port 80 on the guest machine.
27+
# config.vm.network "forwarded_port", guest: 80, host: 8080
28+
29+
# Create a private network, which allows host-only access to the machine
30+
# using a specific IP.
31+
# config.vm.network "private_network", ip: "192.168.33.10"
32+
33+
# Create a public network, which generally matched to bridged network.
34+
# Bridged networks make the machine appear as another physical device on
35+
# your network.
36+
# config.vm.network "public_network"
37+
38+
# Share an additional folder to the guest VM. The first argument is
39+
# the path on the host to the actual folder. The second argument is
40+
# the path on the guest to mount the folder. And the optional third
41+
# argument is a set of non-required options.
42+
# config.vm.synced_folder "../data", "/vagrant_data"
43+
config.vm.synced_folder "../..", "/libv8"
44+
45+
# Provider-specific configuration so you can fine-tune various
46+
# backing providers for Vagrant. These expose provider-specific options.
47+
# Example for VirtualBox:
48+
#
49+
# config.vm.provider "virtualbox" do |vb|
50+
# # Display the VirtualBox GUI when booting the machine
51+
# vb.gui = true
52+
#
53+
# # Customize the amount of memory on the VM:
54+
# vb.memory = "1024"
55+
# end
56+
#
57+
# View the documentation for the provider you are using for more
58+
# information on available options.
59+
60+
config.vm.provider "docker" do |d|
61+
d.build_dir = "."
62+
d.has_ssh = true
63+
end
64+
65+
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
66+
# such as FTP and Heroku are also available. See the documentation at
67+
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
68+
# config.push.define "atlas" do |push|
69+
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
70+
# end
71+
72+
# Enable provisioning with a shell script. Additional provisioners such as
73+
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
74+
# documentation for more information about their specific syntax and use.
75+
# config.vm.provision "shell", inline: <<-SHELL
76+
# apt-get update
77+
# apt-get install -y apache2
78+
# SHELL
79+
80+
config.vm.provision "shell", inline: <<-SHELL
81+
apk add --update alpine-sdk binutils-gold linux-headers ruby ruby-dev ruby-bundler python
82+
SHELL
83+
end

release/x86_64-linux-musl/entry.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
[ "$DEBUG" == 'true' ] && set -x
6+
7+
DAEMON=sshd
8+
9+
# Copy default config from cache
10+
if [ ! "$(ls -A /etc/ssh)" ]; then
11+
cp -a /etc/ssh.cache/* /etc/ssh/
12+
fi
13+
14+
# Generate Host keys, if required
15+
if ! ls /etc/ssh/ssh_host_* 1> /dev/null 2>&1; then
16+
ssh-keygen -A
17+
fi
18+
19+
# Fix permissions, if writable
20+
if [ -w ~/.ssh ]; then
21+
chown root:root ~/.ssh && chmod 700 ~/.ssh/
22+
fi
23+
if [ -w ~/.ssh/authorized_keys ]; then
24+
chown root:root ~/.ssh/authorized_keys
25+
chmod 600 ~/.ssh/authorized_keys
26+
fi
27+
if [ -w /etc/authorized_keys ]; then
28+
chown root:root /etc/authorized_keys
29+
chmod 755 /etc/authorized_keys
30+
find /etc/authorized_keys/ -type f -exec chmod 644 {} \;
31+
fi
32+
33+
# Create vagrant user if missing
34+
if ! ls /home/vagrant 1> /dev/null 2>&1; then
35+
addgroup vagrant
36+
adduser -D -G vagrant -s '/bin/bash' vagrant
37+
(echo vagrant; echo vagrant) | passwd vagrant
38+
mkdir /home/vagrant/.ssh
39+
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key' > /home/vagrant/.ssh/authorized_keys
40+
chmod -R 0700 /home/vagrant/.ssh
41+
chown -R vagrant:vagrant /home/vagrant/.ssh
42+
fi
43+
44+
# Update MOTD
45+
if [ -v MOTD ]; then
46+
echo -e "$MOTD" > /etc/motd
47+
fi
48+
49+
stop() {
50+
echo "Received SIGINT or SIGTERM. Shutting down $DAEMON"
51+
# Get PID
52+
pid=$(cat /var/run/$DAEMON/$DAEMON.pid)
53+
# Set TERM
54+
kill -SIGTERM "${pid}"
55+
# Wait for exit
56+
wait "${pid}"
57+
# All done.
58+
echo "Done."
59+
}
60+
61+
echo "Running $@"
62+
if [ "$(basename $1)" == "$DAEMON" ]; then
63+
trap stop SIGINT SIGTERM
64+
$@ &
65+
pid="$!"
66+
mkdir -p /var/run/$DAEMON && echo "${pid}" > /var/run/$DAEMON/$DAEMON.pid
67+
wait "${pid}" && exit $?
68+
else
69+
exec "$@"
70+
fi

0 commit comments

Comments
 (0)