Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
sed -i "s/reg.mydomain.com/$IPorFQDN/g" 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"
@mkuendig

This comment has been minimized.

Copy link

@mkuendig mkuendig commented Mar 24, 2020

I can't get this to work. It fails during install.sh with error:

Docker Compose Installation done
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/common.sh
harbor/harbor.yml
[Step 0]: checking if docker is installed ...
Note: docker version: 19.03.8
[Step 1]: checking docker-compose is installed ...
Note: docker-compose version: 1.25.4
[Step 2]: preparing environment ...
[Step 3]: preparing harbor configs ...
prepare base dir is set to /home/mkuendig/harbor
ERROR:root:Error: The protocol is https but attribute ssl_cert is not set

This is on a brand new ubuntu 18.04 on GCP.

commenting out the https section in the harbor.yaml file works and continues the script.

@kacole2

This comment has been minimized.

Copy link
Owner Author

@kacole2 kacole2 commented Mar 24, 2020

@mkuendig . Yes, you need to comment out the https section. Sorry about not having that information.

@tthebst

This comment has been minimized.

Copy link

@tthebst tthebst commented Apr 2, 2020

Hi,

I encountered the same problem as @mkuendig. I added a quick fix to the script. At line 63 you can add these commands, which will comment out the https section of the harbor.yml file.

sed -e '/port: 443/ s/^#*/#/' -i harbor.yml  
sed -e '/https:/ s/^#*/#/' -i harbor.yml  
sed -e '/certificate:*/ s/^#*/#/' -i harbor.yml  
sed -e '/private_key:*/ s/^#*/#/' -i harbor.yml  

With these lines added the script runs without problems on Ubuntu 1804 on GCP.

Tim

@tthebst

This comment has been minimized.

Copy link

@tthebst tthebst commented Apr 2, 2020

Another fix would be to change the password of the script to "VMware12345" instead of "Harbor12345" to be consistent with the docs. This may save somebody some time...

@kacole2

This comment has been minimized.

Copy link
Owner Author

@kacole2 kacole2 commented Apr 2, 2020

@tthebst thanks for the fix. I'll get that added. To be honest, the docs should be Harbor12345. Let's submit a PR to "de-VMware" this thing. :)

@tthebst

This comment has been minimized.

Copy link

@tthebst tthebst commented Apr 2, 2020

Thanks. I will submit a PR

@mschuchard

This comment has been minimized.

Copy link

@mschuchard mschuchard commented Jun 26, 2020

Could the quick start please be updated with the fixes? It still currently does not work as is, and the manual fixes have to be applied. Thanks!

@spartan195

This comment has been minimized.

Copy link

@spartan195 spartan195 commented Aug 10, 2020

Greetings, I know i'm a bit late but I encountered the same issues as you, let me upload the fixed script here.
Keep in mind this code is made to be executed from $HOME folder!

#!/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
sed -e '/port: 443/ s/^#*/#/' -i ~/harbor/harbor.yml
sed -e '/https:/ s/^#*/#/' -i ~/harbor/harbor.yml
sed -e '/certificate:*/ s/^#*/#/' -i ~/harbor/harbor.yml
sed -e '/private_key:*/ s/^#*/#/' -i ~/harbor/harbor.yml
cd harbor
sed -i "s/reg.mydomain.com/$IPorFQDN/g" ~/harbor/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 Harbor123456 $IPorFQDN"
@kcalmond

This comment has been minimized.

Copy link

@kcalmond kcalmond commented Aug 30, 2020

Above script mod for no https doesn't work with current Harbor version (2.0.2). The tarball includes a ~/harbor/harbor.yml.tmpl instead of harbor.yml. You have to copy the template file into harbor.yml first. Also, I modified the regex's for the sed-e commands to elimate matching extraneous lines in harbor.yml. The sequence that worked for me is below, between the CHANGE bars:

...
tar xvf harbor-online-installer-v$HARBORVERSION.tgz
# CHANGE-----
cd harbor
cp harbor.yml.tmpl harbor.yml
sed -i "s/reg.mydomain.com/$IPorFQDN/g" ~/harbor/harbor.yml
sed -e '/port: 443$/ s/^#*/#/' -i ~/harbor/harbor.yml
sed -e '/https:$/ s/^#*/#/' -i ~/harbor/harbor.yml
sed -e '/\/your\/certificate\/path$/ s/^#*/#/' -i ~/harbor/harbor.yml
sed -e '/\/your\/private\/key\/path$/ s/^#*/#/' -i ~/harbor/harbor.yml
# -----CHANGE
# ./install.sh --with-clair --with-chartmuseum
...
@tingkai-zhang

This comment has been minimized.

Copy link

@tingkai-zhang tingkai-zhang commented Sep 14, 2020

After running the script, I have problem with docker login:

Error response from daemon: Get http://xxx.xxx.xxx.xx/v2/: dial tcp xxx.xxx.xxx.xx:80: connect: connection refused

Anyone knows why?

@durai23

This comment has been minimized.

Copy link

@durai23 durai23 commented Sep 29, 2020

Hi harbor,
please note this script currently outputs (after successful completion) default password as Harbor123456. This is incorrect. By trial and error (and from 2.1 docs as well) I tried Harbor12345 and only that worked. Please modify the script to reflect this.

@danielporto

This comment has been minimized.

Copy link

@danielporto danielporto commented Oct 7, 2020

damn.. is not working. :-/

@danielporto

This comment has been minimized.

@danielporto

This comment has been minimized.

Copy link

@danielporto danielporto commented Oct 7, 2020

here is the whole script fixed. working with version 2.1.0
https://gist.github.com/danielporto/86463aeb2efc816f044695847167ae2a

@kacole2

This comment has been minimized.

Copy link
Owner Author

@kacole2 kacole2 commented Oct 7, 2020

Hi all. This script has been abandoned because this is NOT the preferred way to install or operate Harbor. There is currently a Helm chart that takes care of the entire installation. There is also an Operator that will be released soon that will be the new successor of the Helm chart.

@alanmbarr

This comment has been minimized.

Copy link

@alanmbarr alanmbarr commented Dec 1, 2020

Might be a good idea to take it off the harbor site if it's not meant to be used? https://goharbor.io/docs/2.1.0/install-config/quick-install-script/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.