Skip to content

Instantly share code, notes, and snippets.

@danielporto
Forked from kacole2/harbor.sh
Last active November 15, 2021 05:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save danielporto/86463aeb2efc816f044695847167ae2a to your computer and use it in GitHub Desktop.
Save danielporto/86463aeb2efc816f044695847167ae2a to your computer and use it in GitHub Desktop.
Quick Start Harbor Installation Script on Ubuntu 18.04
#!/bin/bash
#Harbor on Ubuntu 18.04
#Prompt for the user to ask if the install should use the IP Address or Fully Qualified Domain Name of the Harbor Server
PS3='Would you like to install Harbor based on IP or FQDN? '
select option in IP FQDN
do
case $option in
IP)
IPorFQDN=$(hostname -I|cut -d" " -f 1)
break;;
FQDN)
IPorFQDN=$(hostname -f)
break;;
esac
done
# Housekeeping
apt update -y
swapoff --all
sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab
ufw disable #Do Not Do This In Production
echo "Housekeeping done"
#Install Latest Stable Docker Release
apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update -y
apt-get install -y docker-ce docker-ce-cli containerd.io
tee /etc/docker/daemon.json >/dev/null <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"insecure-registries" : ["$IPorFQDN:443","$IPorFQDN:80","0.0.0.0/0"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
mkdir -p /etc/systemd/system/docker.service.d
groupadd docker
MAINUSER=$(logname)
usermod -aG docker $MAINUSER
systemctl daemon-reload
systemctl restart docker
echo "Docker Installation done"
#Install Latest Stable Docker Compose Release
COMPOSEVERSION=$(curl -s https://github.com/docker/compose/releases/latest/download 2>&1 | grep -Po [0-9]+\.[0-9]+\.[0-9]+)
curl -L "https://github.com/docker/compose/releases/download/$COMPOSEVERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
echo "Docker Compose Installation done"
#Install Latest Stable Harbor Release
HARBORVERSION=$(curl -s https://github.com/goharbor/harbor/releases/latest/download 2>&1 | grep -Po [0-9]+\.[0-9]+\.[0-9]+)
curl -s https://api.github.com/repos/goharbor/harbor/releases/latest | grep browser_download_url | grep online | cut -d '"' -f 4 | wget -qi -
tar xvf harbor-online-installer-v$HARBORVERSION.tgz
cd harbor
cp harbor.yml.tmpl harbor.yml
sed -i "s/reg.mydomain.com/$IPorFQDN/g" harbor.yml
sed -e '/port: 443$/ s/^#*/#/' -i harbor.yml
sed -e '/https:$/ s/^#*/#/' -i harbor.yml
sed -e '/\/your\/certificate\/path$/ s/^#*/#/' -i harbor.yml
sed -e '/\/your\/private\/key\/path$/ s/^#*/#/' -i harbor.yml
./install.sh --with-clair --with-chartmuseum
echo -e "Harbor Installation Complete \n\nPlease log out and log in or run the command 'newgrp docker' to use Docker without sudo\n\nLogin to your harbor instance:\n docker login -u admin -p Harbor12345 $IPorFQDN"
@bmerry
Copy link

bmerry commented Sep 29, 2021

Just tried this on a completely fresh Ubuntu 18.04 Vagrant box (bento/ubuntu-18.04) and while it ran without complaints, there are no docker containers running afterwards (nor any stopped containers). Here's the output in case it helps:

vagrant@vagrant:~$ wget https://gist.githubusercontent.com/danielporto/86463aeb2efc816f044695847167ae2a/raw/d9d44cfb7c4d0442ad04c25294800ef4cd726ce9/harbor.sh
--2021-09-29 06:42:24--  https://gist.githubusercontent.com/danielporto/86463aeb2efc816f044695847167ae2a/raw/d9d44cfb7c4d0442ad04c25294800ef4cd726ce9/harbor.sh
Resolving gist.githubusercontent.com (gist.githubusercontent.com)... 185.199.109.133, 185.199.111.133, 185.199.110.133, ...
Connecting to gist.githubusercontent.com (gist.githubusercontent.com)|185.199.109.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2830 (2.8K) [text/plain]
Saving to: ‘harbor.sh’

harbor.sh                  100%[=======================================>]   2.76K  --.-KB/s    in 0.1s    

2021-09-29 06:42:26 (25.7 KB/s) - ‘harbor.sh’ saved [2830/2830]

vagrant@vagrant:~$ chmod +x harbor.sh 
vagrant@vagrant:~$ sudo ./harbor.sh 
1) IP
2) FQDN
Would you like to install Harbor based on IP or FQDN? 1
Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease                                  
Get:2 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]              
Get:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]          
Get:4 http://security.ubuntu.com/ubuntu bionic-security/main i386 Packages [1,055 kB]
Get:5 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]         
Get:6 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [2,262 kB]
Get:7 http://archive.ubuntu.com/ubuntu bionic-updates/main i386 Packages [1,360 kB]                       
Get:8 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [1,904 kB]                    
Get:9 http://archive.ubuntu.com/ubuntu bionic-updates/main Translation-en [438 kB]                        
Get:10 http://security.ubuntu.com/ubuntu bionic-security/main Translation-en [345 kB]                     
Get:11 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [468 kB]               
Get:12 http://security.ubuntu.com/ubuntu bionic-security/restricted i386 Packages [22.0 kB]               
Get:13 http://security.ubuntu.com/ubuntu bionic-security/restricted Translation-en [63.0 kB]     
Get:14 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [1,140 kB]         
Get:15 http://archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [492 kB]                 
Get:16 http://security.ubuntu.com/ubuntu bionic-security/universe i386 Packages [988 kB]                  
Get:17 http://security.ubuntu.com/ubuntu bionic-security/universe Translation-en [260 kB]                 
Get:18 http://archive.ubuntu.com/ubuntu bionic-updates/restricted i386 Packages [28.6 kB]                 
Get:19 http://archive.ubuntu.com/ubuntu bionic-updates/restricted Translation-en [66.7 kB]                
Get:20 http://archive.ubuntu.com/ubuntu bionic-updates/universe i386 Packages [1,579 kB]                  
Get:21 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1,754 kB]                 
Get:22 http://archive.ubuntu.com/ubuntu bionic-updates/universe Translation-en [376 kB]                   
Get:23 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [27.3 kB]                
Get:24 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse Translation-en [6,808 B]                
Fetched 14.9 MB in 14s (1,049 kB/s)                                                                       
Reading package lists... Done
Building dependency tree       
Reading state information... Done
42 packages can be upgraded. Run 'apt list --upgradable' to see them.
Firewall stopped and disabled on system startup
Housekeeping done
Reading package lists... Done
Building dependency tree       
Reading state information... Done
software-properties-common is already the newest version (0.96.24.32.14).
The following NEW packages will be installed:
  apt-transport-https gnupg-agent
The following packages will be upgraded:
  ca-certificates curl libcurl4
3 upgraded, 2 newly installed, 0 to remove and 39 not upgraded.
Need to get 533 kB of archives.
After this operation, 197 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 ca-certificates all 20210119~18.04.2 [145 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 apt-transport-https all 1.6.14 [4,348 B]
Get:3 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 curl amd64 7.58.0-2ubuntu3.16 [159 kB]   
Get:4 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libcurl4 amd64 7.58.0-2ubuntu3.16 [220 kB]
Get:5 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 gnupg-agent all 2.2.4-1ubuntu1.4 [4,864 B]
Fetched 533 kB in 8s (64.8 kB/s)                                                                          
Preconfiguring packages ...
(Reading database ... 39787 files and directories currently installed.)
Preparing to unpack .../ca-certificates_20210119~18.04.2_all.deb ...
Unpacking ca-certificates (20210119~18.04.2) over (20210119~18.04.1) ...
Selecting previously unselected package apt-transport-https.
Preparing to unpack .../apt-transport-https_1.6.14_all.deb ...
Unpacking apt-transport-https (1.6.14) ...
Preparing to unpack .../curl_7.58.0-2ubuntu3.16_amd64.deb ...
Unpacking curl (7.58.0-2ubuntu3.16) over (7.58.0-2ubuntu3.14) ...
Preparing to unpack .../libcurl4_7.58.0-2ubuntu3.16_amd64.deb ...
Unpacking libcurl4:amd64 (7.58.0-2ubuntu3.16) over (7.58.0-2ubuntu3.14) ...
Selecting previously unselected package gnupg-agent.
Preparing to unpack .../gnupg-agent_2.2.4-1ubuntu1.4_all.deb ...
Unpacking gnupg-agent (2.2.4-1ubuntu1.4) ...
Setting up apt-transport-https (1.6.14) ...
Setting up libcurl4:amd64 (7.58.0-2ubuntu3.16) ...
Setting up gnupg-agent (2.2.4-1ubuntu1.4) ...
Setting up ca-certificates (20210119~18.04.2) ...
Updating certificates in /etc/ssl/certs...
0 added, 1 removed; done.
Setting up curl (7.58.0-2ubuntu3.16) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...
Processing triggers for ca-certificates (20210119~18.04.2) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
OK
Get:1 https://download.docker.com/linux/ubuntu bionic InRelease [64.4 kB]
Get:2 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages [19.8 kB]  
Hit:3 http://archive.ubuntu.com/ubuntu bionic InRelease                                
Hit:4 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:5 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
Hit:6 http://security.ubuntu.com/ubuntu bionic-security InRelease                                         
Fetched 84.3 kB in 6s (13.1 kB/s)                                                                         
Reading package lists... Done
Hit:1 https://download.docker.com/linux/ubuntu bionic InRelease
Hit:2 http://security.ubuntu.com/ubuntu bionic-security InRelease               
Hit:3 http://archive.ubuntu.com/ubuntu bionic InRelease
Hit:4 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:5 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
Reading package lists... Done
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  docker-ce-rootless-extras docker-scan-plugin libltdl7 pigz
Suggested packages:
  aufs-tools cgroupfs-mount | cgroup-lite
Recommended packages:
  slirp4netns
The following NEW packages will be installed:
  containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras docker-scan-plugin libltdl7 pigz
0 upgraded, 7 newly installed, 0 to remove and 39 not upgraded.
Need to get 96.7 MB of archives.
After this operation, 407 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic/universe amd64 pigz amd64 2.4-1 [57.4 kB]
Get:2 https://download.docker.com/linux/ubuntu bionic/stable amd64 containerd.io amd64 1.4.9-1 [24.7 MB]
Get:3 http://archive.ubuntu.com/ubuntu bionic/main amd64 libltdl7 amd64 2.4.6-2 [38.8 kB]
Get:4 https://download.docker.com/linux/ubuntu bionic/stable amd64 docker-ce-cli amd64 5:20.10.8~3-0~ubuntu-bionic [38.8 MB]
Get:5 https://download.docker.com/linux/ubuntu bionic/stable amd64 docker-ce amd64 5:20.10.8~3-0~ubuntu-bionic [21.2 MB]
Get:6 https://download.docker.com/linux/ubuntu bionic/stable amd64 docker-ce-rootless-extras amd64 5:20.10.8~3-0~ubuntu-bionic [7,911 kB]
Get:7 https://download.docker.com/linux/ubuntu bionic/stable amd64 docker-scan-plugin amd64 0.8.0~ubuntu-bionic [3,888 kB]
Fetched 96.7 MB in 19s (5,060 kB/s)                                                                       
Selecting previously unselected package pigz.
(Reading database ... 39794 files and directories currently installed.)
Preparing to unpack .../0-pigz_2.4-1_amd64.deb ...
Unpacking pigz (2.4-1) ...
Selecting previously unselected package containerd.io.
Preparing to unpack .../1-containerd.io_1.4.9-1_amd64.deb ...
Unpacking containerd.io (1.4.9-1) ...
Selecting previously unselected package docker-ce-cli.
Preparing to unpack .../2-docker-ce-cli_5%3a20.10.8~3-0~ubuntu-bionic_amd64.deb ...
Unpacking docker-ce-cli (5:20.10.8~3-0~ubuntu-bionic) ...
Selecting previously unselected package docker-ce.
Preparing to unpack .../3-docker-ce_5%3a20.10.8~3-0~ubuntu-bionic_amd64.deb ...
Unpacking docker-ce (5:20.10.8~3-0~ubuntu-bionic) ...
Selecting previously unselected package docker-ce-rootless-extras.
Preparing to unpack .../4-docker-ce-rootless-extras_5%3a20.10.8~3-0~ubuntu-bionic_amd64.deb ...
Unpacking docker-ce-rootless-extras (5:20.10.8~3-0~ubuntu-bionic) ...
Selecting previously unselected package docker-scan-plugin.
Preparing to unpack .../5-docker-scan-plugin_0.8.0~ubuntu-bionic_amd64.deb ...
Unpacking docker-scan-plugin (0.8.0~ubuntu-bionic) ...
Selecting previously unselected package libltdl7:amd64.
Preparing to unpack .../6-libltdl7_2.4.6-2_amd64.deb ...
Unpacking libltdl7:amd64 (2.4.6-2) ...
Setting up containerd.io (1.4.9-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
Setting up docker-ce-rootless-extras (5:20.10.8~3-0~ubuntu-bionic) ...
Setting up docker-scan-plugin (0.8.0~ubuntu-bionic) ...
Setting up libltdl7:amd64 (2.4.6-2) ...
Setting up docker-ce-cli (5:20.10.8~3-0~ubuntu-bionic) ...
Setting up pigz (2.4-1) ...
Setting up docker-ce (5:20.10.8~3-0~ubuntu-bionic) ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...
Processing triggers for systemd (237-3ubuntu10.50) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
groupadd: group 'docker' already exists
Docker Installation done
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100     9  100     9    0     0      8      0  0:00:01  0:00:01 --:--:--     8
Docker Compose Installation done
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/common.sh
harbor/harbor.yml.tmpl
✖ Clair is deprecated please remove it from installation arguments !!!
Harbor Installation Complete 

Please log out and log in or run the command 'newgrp docker' to use Docker without sudo

Login to your harbor instance:
 docker login -u admin -p Harbor12345 10.0.2.15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment