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

Commit 135d15b

Browse files
author
Riaan Nolan
committed
Merge branch 'feature/mac-m1' into 'master'
get hashiqube to work on Mac M1 chips, adding docker provider, update documentation See merge request all-staff/hashiqube!83
1 parent 8dc08d4 commit 135d15b

19 files changed

+288
-36
lines changed

Dockerfile

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# https://betterprogramming.pub/managing-virtual-machines-under-vagrant-on-a-mac-m1-aebc650bc12c
2+
# https://github.com/rofrano/vagrant-docker-provider
3+
4+
FROM ubuntu:focal
5+
6+
ENV DEBIAN_FRONTEND noninteractive
7+
8+
# Install packages needed for SSH and interactive OS
9+
RUN apt-get update && \
10+
yes | unminimize && \
11+
apt-get -y install \
12+
openssh-server \
13+
passwd \
14+
sudo \
15+
man-db \
16+
curl \
17+
wget \
18+
vim-tiny && \
19+
apt-get -qq clean && \
20+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
21+
22+
# Enable systemd (from Matthew Warman's mcwarman/vagrant-provider)
23+
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
24+
rm -f /lib/systemd/system/multi-user.target.wants/*; \
25+
rm -f /etc/systemd/system/*.wants/*; \
26+
rm -f /lib/systemd/system/local-fs.target.wants/*; \
27+
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
28+
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
29+
rm -f /lib/systemd/system/basic.target.wants/*; \
30+
rm -f /lib/systemd/system/anaconda.target.wants/*;
31+
32+
# Enable ssh for vagrant
33+
RUN systemctl enable ssh.service;
34+
EXPOSE 22
35+
36+
# Create the vagrant user
37+
RUN useradd -m -G sudo -s /bin/bash vagrant && \
38+
echo "vagrant:vagrant" | chpasswd && \
39+
echo 'vagrant ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/vagrant && \
40+
chmod 440 /etc/sudoers.d/vagrant
41+
42+
# Establish ssh keys for vagrant
43+
RUN mkdir -p /home/vagrant/.ssh; \
44+
chmod 700 /home/vagrant/.ssh
45+
ADD https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant.pub /home/vagrant/.ssh/authorized_keys
46+
RUN chmod 600 /home/vagrant/.ssh/authorized_keys; \
47+
chown -R vagrant:vagrant /home/vagrant/.ssh
48+
49+
# Run the init daemon
50+
VOLUME [ "/sys/fs/cgroup" ]
51+
CMD ["/usr/sbin/init"]

README.md

+130-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,85 @@ Thanks to the flexibility of the HashiCorp products there is no need wonder how
2323
* Please download __Virtualbox__ from https://www.virtualbox.org/wiki/Downloads and __Vagrant__ from https://www.vagrantup.com/downloads.html and install
2424
* Using `git` - clone this repo `git clone $repo .` [__What is Git?__](git/#git)
2525
* Inside the local repo folder, do `vagrant up --provision` - This will setup, Vault, Nomad, Consul, Terraform, Localstack and Docker as well as giving you access the docsify website at http://localhost:3333
26-
* Open in your browser http://localhost:3333 for Documentation
26+
27+
:bulb: If you see this error message
28+
29+
```
30+
The IP address configured for the host-only network is not within the
31+
allowed ranges. Please update the address used to be within the allowed
32+
ranges and run the command again.
33+
34+
Address: 10.9.99.10
35+
Ranges: 192.168.56.0/21
36+
37+
Valid ranges can be modified in the /etc/vbox/networks.conf file. For
38+
more information including valid format see:
39+
40+
https://www.virtualbox.org/manual/ch06.html#network_hostonly
41+
```
42+
43+
Please create the following file: __/etc/vbox/networks.conf__ with the following contents
44+
45+
```
46+
* 10.0.0.0/8 192.168.0.0/16
47+
* 2001::/64
48+
```
49+
50+
and re-run `vagrant up --provision`
51+
52+
## Dependencies
53+
To get started we are now going to install some core dependencies to get the Lab started, you need to install
54+
below dependencies before you can do anything
55+
56+
__Mac Users only, Windows Users can skip this step__
57+
Let's first check if we have an __M1 Mac__, if that is the case the __virtualbox__ provider will not work.
58+
59+
Click on the Apple Icon top left
60+
![About this Mac](images/mac_apple_icon.png?raw=true "About this Mac")
61+
62+
and click on __About this Mac__
63+
64+
If you see an __Intel__ chip, you can proceed with the `virtualbox` provider.
65+
![About this Mac Intel](images/mac_intel.png?raw=true "About this Mac Intel")
66+
67+
If you see an __Apple M1__ chip, please ensure you specify the environment variable and the provider to be docker.
68+
```
69+
vagrant plugin uninstall vagrant-hostsupdater # the hostsupdator plugin does not work with the docker provider
70+
```
71+
72+
![About this Mac M1](images/mac_m1.png?raw=true "About this Mac M1")
73+
74+
#### Docker Desktop
75+
Docker Desktop is an easy-to-install application for your Mac or Windows environment that enables you to build and share containerized applications and microservices. It's a graphical user interface for the docker service.
76+
77+
* Please download __Docker Desktop__ from https://www.docker.com/products/docker-desktop and install it on your laptop, to verify please bring up the Docker Desktop application.
78+
79+
I already have HashiQube running, you won't see any containers but you will be able to open the application
80+
81+
![Docker Desktop](images/docker_desktop_installed.png?raw=true "Docker Desktop")
82+
83+
Now that docker has been installed we need to ensure that your docker environment and settings are configured
84+
85+
- Ensure you have the latest version installed
86+
- Ensure that your Operating System is updated see: https://www.docker.com/blog/speed-boost-achievement-unlocked-on-docker-desktop-4-6-for-mac/
87+
88+
##### Docker Desktop Resources
89+
90+
![Docker Desktop Resources](images/docker_installed_resources.png?raw=true "Docker Desktop Resources")
91+
92+
* Please ensure that you give your docker daemon at least __10G of RAM__ and sufficient disk space
93+
94+
##### Docker Desktop Experimental Features
95+
96+
![Docker Desktop Experimental Features](images/docker_installed_experimental_features.png?raw=true "Docker Desktop Experimental Features")
97+
98+
https://www.docker.com/blog/speed-boost-achievement-unlocked-on-docker-desktop-4-6-for-mac/
99+
100+
The latest version of Docker on Mac has some signaficant performance improvements, you should consider updating.
101+
102+
Improvements have been made to the way that files are synced between the macOS host and Docker VM. During testing with our amazing macOS community of users, we have observed that these changes have reduced the time taken to complete filesystem operations by up to 98%.
103+
104+
For developers, these incredible gains in speed mean less time waiting for filesystem operations to complete (or building project-specific workarounds to improve performance) and more time focusing on innovation!
27105

28106
## Consul DNS
29107
__Local DNS via Consul__ <br />
@@ -42,6 +120,32 @@ Now you can use DNS like nomad.service.consul:9999 vault.service.consul:9999 via
42120
* Vagrant
43121
* `vagrant up --provision`
44122

123+
124+
If you see this error message
125+
126+
```
127+
The IP address configured for the host-only network is not within the
128+
allowed ranges. Please update the address used to be within the allowed
129+
ranges and run the command again.
130+
131+
Address: 10.9.99.10
132+
Ranges: 192.168.56.0/21
133+
134+
Valid ranges can be modified in the /etc/vbox/networks.conf file.
135+
For more information including valid format see
136+
137+
https://www.virtualbox.org/manual/ch06.html#network_hostonly
138+
```
139+
140+
Please create the following file: __/etc/vbox/networks.conf__ with the following contents
141+
142+
```
143+
* 10.0.0.0/8 192.168.0.0/16
144+
* 2001::/64
145+
```
146+
147+
and re-run `vagrant up --provision`
148+
45149
## Additional Information
46150
* [__Multi Cloud__](multi-cloud/#terraform-hashicorp-hashiqube) - Hashiqube on AWS, GCP and Azure (Clustered) https://registry.terraform.io/modules/star3am/hashiqube/hashicorp/latest
47151
* [__Vagrant__](hashicorp/#vagrant) - Development Environments Made Easy
@@ -112,6 +216,31 @@ For Documentation please open http://localhost:3333 in your browser
112216
==> user.local.dev: Setting hostname...
113217
```
114218

219+
### Errors you might encounter
220+
__Error__ response from daemon: cannot stop container: 6c0c8135620ff47efe12df417a0df0e57d7a81a7f7ca06d011323fbb52e573db: tried to kill container, but did not receive an exit event <br />
221+
__Command__ `vagrant destroy` <br />
222+
__Solution__ run `vagrant destroy` again <br />
223+
```
224+
hashiqube0.service.consul: Are you sure you want to destroy the 'hashiqube0.service.consul' VM? [y/N] y
225+
==> hashiqube0.service.consul: Stopping container...
226+
A Docker command executed by Vagrant didn't complete successfully!
227+
The command run along with the output from the command is shown
228+
below.
229+
230+
Command: ["docker", "stop", "-t", "1", "6c0c8135620ff47efe12df417a0df0e57d7a81a7f7ca06d011323fbb52e573db", {:notify=>[:stdout, :stderr]}]
231+
232+
Stderr: Error response from daemon: cannot stop container: 6c0c8135620ff47efe12df417a0df0e57d7a81a7f7ca06d011323fbb52e573db: tried to kill container, but did not receive an exit event
233+
```
234+
235+
__Error__ The IP address configured for the host-only network is not within the allowed ranges. Please
236+
update the address used to be within the allowed ranges and run the command again. <br />
237+
__Command__ `vagrant up --provision` <br />
238+
__Solution__ Ensure the following contents are present in `/etc/vbox/networks.conf` <br>
239+
```
240+
* 10.0.0.0/8 192.168.0.0/16
241+
* 2001::/64
242+
```
243+
115244
## To investigate
116245
### CI/CD
117246
Gatling: (load testing) https://gatling.io/open-source

Vagrantfile

+41-15
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ fqdn = ENV["fqdn"] || "service.consul"
77

88
# https://www.virtualbox.org/manual/ch08.html
99
vbox_config = [
10-
{ '--memory' => '4096' },
11-
{ '--cpus' => '2' },
10+
{ '--memory' => '10240' },
11+
{ '--cpus' => '4' },
1212
{ '--cpuexecutioncap' => '100' },
1313
{ '--biosapic' => 'x2apic' },
1414
{ '--ioapic' => 'on' },
@@ -28,7 +28,7 @@ machines = [
2828
:disksize => '10GB',
2929
:vbox_config => vbox_config,
3030
:synced_folders => [
31-
{ :vm_path => '/data', :ext_rel_path => '../../', :vm_owner => 'ubuntu' },
31+
{ :vm_path => '/osdata', :ext_rel_path => '../../', :vm_owner => 'ubuntu' },
3232
{ :vm_path => '/var/jenkins_home', :ext_rel_path => './jenkins/jenkins_home', :vm_owner => 'ubuntu' },
3333
],
3434
},
@@ -67,21 +67,24 @@ Vagrant::configure("2") do |config|
6767
COMMAND_SEPARATOR = ";"
6868
end
6969

70-
# auto install plugins, will prompt for admin password on 1st vagrant up
71-
required_plugins = %w( vagrant-disksize vagrant-hostsupdater )
72-
required_plugins.each do |plugin|
73-
exec "vagrant plugin install #{plugin}#{COMMAND_SEPARATOR}vagrant #{ARGV.join(" ")}" unless Vagrant.has_plugin? plugin || ARGV[0] == 'plugin'
74-
end
70+
# deprecated
71+
# if @chipset != "Apple"; then
72+
# # auto install plugins, will prompt for admin password on 1st vagrant up
73+
# required_plugins = %w( vagrant-disksize vagrant-hostsupdater )
74+
# required_plugins.each do |plugin|
75+
# exec "vagrant plugin install #{plugin}#{COMMAND_SEPARATOR}vagrant #{ARGV.join(" ")}" unless Vagrant.has_plugin? plugin || ARGV[0] == 'plugin'
76+
# end
77+
# end
7578

7679
machines.each_with_index do |machine, index|
7780

7881
config.vm.box = "ubuntu/focal64"
7982
config.vm.define machine[:name] do |config|
8083

81-
config.disksize.size = machine[:disksize]
84+
# config.disksize.size = machine[:disksize] # deprecated
8285
config.ssh.forward_agent = true
8386
config.ssh.insert_key = true
84-
config.vm.network "private_network", ip: machine[:ip]
87+
config.vm.network "private_network", ip: "#{machine[:ip]}"
8588
config.vm.network "forwarded_port", guest: 22, host: machine[:ssh_port], id: 'ssh', auto_correct: true
8689

8790
if machines.size == 1 # only expose these ports if 1 machine, else conflicts
@@ -110,7 +113,6 @@ Vagrant::configure("2") do |config|
110113
end
111114

112115
config.vm.hostname = "#{machine[:name]}"
113-
config.hostsupdater.aliases = ["#{machine[:name]}"]
114116

115117
unless machine[:vbox_config].nil?
116118
config.vm.provider :virtualbox do |vb|
@@ -121,6 +123,30 @@ Vagrant::configure("2") do |config|
121123
end
122124
end
123125
end
126+
127+
# if you are not on Apple M chip and want to use docker provider do:
128+
# vagrant up --provision-with basetools --provider docker
129+
# https://developers.redhat.com/blog/2016/09/13/running-systemd-in-a-non-privileged-container
130+
# https://github.com/containers/podman/issues/3295
131+
# --tmpfs /tmp : Create a temporary filesystem in /tmp
132+
# --tmpfs /run : Create another temporary filesystem in /run
133+
# --tmpfs /run/lock : Apparently having a tmpfs in /run isn’t enough – you ALSO need one in /run/lock
134+
# -v /sys/fs/cgroup:/sys/fs/cgroup:ro : Mount the CGroup kernel configuration values into the container
135+
# https://github.com/docker/for-mac/issues/6073
136+
# Docker Desktop now uses cgroupv2. If you need to run systemd in a container then:
137+
# * Ensure your version of systemd supports cgroupv2. It must be at least systemd 247. Consider upgrading any centos:7 images to centos:8.
138+
# * Containers running systemd need the following options: --privileged --cgroupns=host -v /sys/fs/cgroup:/sys/fs/cgroup:rw.
139+
# https://betterprogramming.pub/managing-virtual-machines-under-vagrant-on-a-mac-m1-aebc650bc12c
140+
config.vm.provider "docker" do |docker, override|
141+
override.vm.box = nil
142+
docker.build_dir = "."
143+
docker.remains_running = true
144+
docker.has_ssh = true
145+
docker.privileged = true
146+
docker.volumes = ['/sys/fs/cgroup:/sys/fs/cgroup:rw']
147+
docker.create_args = ['--cgroupns=host', '--tmpfs=/tmp:exec', '--tmpfs=/var/lib/docker:mode=0777,dev,size=15g,suid,exec', '--tmpfs=/run', '--tmpfs=/run/lock'] # '--memory=10g', '--memory-swap=14g', '--oom-kill-disable'
148+
docker.env = { "PROVIDER": "docker", "NAME": "hashiqube" }
149+
end
124150

125151
# mount the shared folder inside the VM
126152
unless machine[:synced_folders].nil?
@@ -161,6 +187,10 @@ Vagrant::configure("2") do |config|
161187
# vagrant up --provision-with docker to only run this on vagrant up
162188
config.vm.provision "docker", preserve_order: true, type: "shell", path: "docker/docker.sh"
163189

190+
# docsify
191+
# vagrant up --provision-with docsify to only run this on vagrant up
192+
config.vm.provision "docsify", type: "shell", preserve_order: true, privileged: false, path: "docsify/docsify.sh"
193+
164194
# install terraform
165195
# vagrant up --provision-with terraform to only run this on vagrant up
166196
config.vm.provision "terraform", preserve_order: true, type: "shell", privileged: true, path: "hashicorp/terraform.sh"
@@ -247,10 +277,6 @@ Vagrant::configure("2") do |config|
247277

248278

249279

250-
# docsify
251-
# vagrant up --provision-with docsify to only run this on vagrant up
252-
config.vm.provision "docsify", type: "shell", preserve_order: true, privileged: false, path: "docsify/docsify.sh"
253-
254280

255281

256282

database/mysql.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ yes | sudo docker system prune -a
77
yes | sudo docker system prune --volumes
88
sudo DEBIAN_FRONTEND=noninteractive apt-get --assume-yes install mysql-client
99
sudo docker run \
10+
--memory 512M \
1011
--name mysql \
1112
-e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=mysqldb \
1213
-p 3306:3306 \
1314
-d mysql:latest \
1415
--character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
15-
sleep 15;
16+
sleep 60;
1617
echo -e '\e[38;5;198m'"++++ Show databases"
1718
mysql -h 127.0.0.1 -u root -ppassword -e "show databases;"
1819
echo -e '\e[38;5;198m'"++++ Create Vault MySQL user"

docker/docker.sh

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
#/bin/bash
22
# https://docs.docker.com/install/linux/docker-ce/ubuntu/
3+
sudo DEBIAN_FRONTEND=noninteractive apt-get update
34
sudo DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes apt-transport-https ca-certificates curl gnupg-agent software-properties-common
45
sudo -i
56
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
6-
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
7+
#PROCESSOR_ARCHITECTURE=$(lscpu | grep "Architecture" | awk '{print $NF}') >> /etc/environment
8+
#echo -e '\e[38;5;198m'"CPU is $PROCESSOR_ARCHITECTURE"
9+
arch=$(lscpu | grep "Architecture" | awk '{print $NF}')
10+
if [[ $arch == x86_64* ]]; then
11+
ARCH="amd64"
12+
elif [[ $arch == aarch64 ]]; then
13+
ARCH="arm64"
14+
fi
15+
echo -e '\e[38;5;198m'"CPU is $ARCH"
16+
sudo add-apt-repository "deb [arch=$ARCH] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
717
sudo apt-get update
818
sudo DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes docker-ce docker-ce-cli containerd.io
919
sudo usermod -aG docker vagrant
1020
sudo mkdir -p /etc/docker
1121
sudo echo '{
12-
"metrics-addr" : "0.0.0.0:9323",
13-
"experimental" : true
22+
"metrics-addr": "0.0.0.0:9323",
23+
"experimental": true,
24+
"storage-driver": "overlay2"
1425
}
1526
' >/etc/docker/daemon.json
1627
sudo service docker restart
@@ -22,14 +33,16 @@ docker rm apache2
2233
yes | sudo docker system prune -a
2334
yes | sudo docker system prune --volumes
2435
echo "Creating Private Docker Registry"
25-
docker run -d -p 5000:5000 --restart=always --name registry registry:2
36+
docker run -d -p 5001:5001 --restart=always --name registry --memory 16M registry:2
2637
echo -e '\e[38;5;198m'"++++ docker build -t apache2 ."
2738
docker build -t apache2 .
2839
echo -e '\e[38;5;198m'"++++ docker images --filter reference=apache2"
2940
docker images --filter reference=apache2
3041
echo -e '\e[38;5;198m'"++++ docker run -t -d -i -p 8889:80 --name apache2 --rm apache2"
31-
docker run -t -d -i -p 8889:80 --name apache2 --rm apache2
42+
docker run -t -d -i -p 8889:80 --name apache2 --memory 16M --rm apache2
3243
docker ps
33-
echo -e '\e[38;5;198m''++++ open http://localhost:8889 in your browser'
34-
echo -e '\e[38;5;198m''++++ you can also run below to get apache2 version from the docker container'
44+
echo -e '\e[38;5;198m'"++++ Docker stats"
45+
docker stats --no-stream -a
46+
echo -e '\e[38;5;198m'"++++ open http://localhost:8889 in your browser"
47+
echo -e '\e[38;5;198m'"++++ you can also run below to get apache2 version from the docker container"
3548
echo -e '\e[38;5;198m'"++++ vagrant ssh -c \"docker ps; docker exec -it apache2 /bin/bash -c 'apache2 -t -v; ps aux'\""

docsify/docsify.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
3+
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
44
sudo DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes nodejs
55
sudo npm i docsify-cli -g --loglevel=error
66
cd /vagrant

0 commit comments

Comments
 (0)