Harbor IDEA 快速指引

网上安装的教程比较多,理清思路之后,自己的安装过程总结一下,以备后续参考。

参考Harbor官网教程 (Centos 7.5)

1.安装前必备 :On a Linux host: docker 17.06.0-ce+ and docker-compose 1.18.0+ . (自行安装好即可)

2. Harbor 下载的 harbor-offline-installer-v2.0.1.tgz 离线安装包,从 https://github.com/goharbor/harbor/releases 下载。

3. 解压开来,配置文件  harbor.yml.tmpl  复制为 harbor.yml  根据自己的需求修改即可(我只修改了主机名,证书,存放目录 )。

 1 # The IP address or hostname to access admin UI and registry service.
 2 # DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
 3 hostname: harbor.grape.com
 4 
 5 # http related config
 6 http:
 7   # port for http, default is 80. If https enabled, this port will redirect to https port
 8   port: 80
 9 
10 # https related config
11 https:
12   # https port for harbor, default is 443
13   port: 443
14   # The path of cert and key files for nginx
15   certificate: /opt/cert/harbor.grape.com.crt
16   private_key: /opt/cert/harbor.grape.com.key
17 
18 # The default data volume
19 data_volume: /home/harbor_data

证书的制作是参考的 https://www.cnblogs.com/sanduzxcvbnm/p/11956347.html 的脚本 ,/opt/cert 目录没有的话,需要先创建。

 1 #!/bin/bash
 2 
 3 # 配置harbor证书
 4 
 5 cd /opt/cert
 6 
 7 openssl genrsa -out ca.key 4096
 8 openssl req -x509 -new -nodes -sha512 -days 3650 -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor.grape.com" -key ca.key -out ca.crt
 9 openssl genrsa -out harbor.grape.com.key 4096
10 openssl req -sha512 -new -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor.grape.com" -key harbor.grape.com.key -out harbor.grape.com.csr
11 
12 cat > v3.ext <<-EOF
13 authorityKeyIdentifier=keyid,issuer
14 basicConstraints=CA:FALSE
15 keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
16 extendedKeyUsage = serverAuth
17 subjectAltName = @alt_names
18 
19 [alt_names]
20 DNS.1=harbor.grape.com
21 IP.1 = 192.168.111.9
22 IP.2 = 10.0.0.40
23 EOF
24 
25 openssl x509 -req -sha512 -days 3650 -extfile v3.ext -CA ca.crt -CAkey ca.key -CAcreateserial -in harbor.grape.com.csr -out harbor.grape.com.crt
26     
27 openssl x509 -inform PEM -in harbor.grape.com.crt -out harbor.grape.com.cert
View Code

其中注意两点,dns 我配置两个地址(内网和外网地址)用于做NAT或者端口映射,记得看过有个帖子说没有找到解决办法(此处是我的解决办法,自签证书,dns以及多个IP)

4.证书放到指定的目录,以及docker compose 启动等等就不细说了。启动之后,其他机器 docker login 进行验证,一般来说,正常的是 x509: certificate signed by unknown authority 错误 ???

linux 需要增加自建的ca证书到docker的信任,创建 /etc/docker/certs.d/harbor.grape.com 文件夹,复制ca.crt 到此目录重启docker 服务;

window 10 相对简单一些,配置文件中增加 "insecure-registries": ["https://harbor.grape.com"] 即可

还有一点差点忘记了,所有访问 https://harbor.grape.com 需要增加到 hosts文件之中。

 

IDEA中的使用过程

其实使用插件即可, com.spotify 的 dockerfile-maven-plugin 参见 https://github.com/spotify/dockerfile-maven

随便建一个spring boot 测试程序,pom文件如下 :

  1 xml version="1.0" encoding="UTF-8"?>
  2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4     <modelVersion>4.0.0modelVersion>
  5     <groupId>com.examplegroupId>
  6     <artifactId>demoartifactId>
  7     <version>0.0.1-SNAPSHOTversion>
  8     <name>demoname>
  9     <description>Demo project for Spring Bootdescription>
 10 
 11     <properties>
 12         <java.version>1.8java.version>
 13         <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
 14         <project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>
 15         <spring-boot.version>2.3.0.RELEASEspring-boot.version>
 16         
 17         <docker.repository>harbor.grape.comdocker.repository>
 18         <docker.image.prefix>bladedocker.image.prefix>
 19     properties>
 20 
 21     <dependencies>
 22         <dependency>
 23             <groupId>org.springframework.bootgroupId>
 24             <artifactId>spring-boot-starter-webartifactId>
 25         dependency>
 26 
 27         <dependency>
 28             <groupId>org.springframework.bootgroupId>
 29             <artifactId>spring-boot-starter-testartifactId>
 30             <scope>testscope>
 31             <exclusions>
 32                 <exclusion>
 33                     <groupId>org.junit.vintagegroupId>
 34                     <artifactId>junit-vintage-engineartifactId>
 35                 exclusion>
 36             exclusions>
 37         dependency>
 38     dependencies>
 39 
 40     <dependencyManagement>
 41         <dependencies>
 42             <dependency>
 43                 <groupId>org.springframework.bootgroupId>
 44                 <artifactId>spring-boot-dependenciesartifactId>
 45                 <version>${spring-boot.version}version>
 46                 <type>pomtype>
 47                 <scope>importscope>
 48             dependency>
 49         dependencies>
 50     dependencyManagement>
 51 
 52     <build>
 53         <plugins>
 54             <plugin>
 55                 <groupId>org.apache.maven.pluginsgroupId>
 56                 <artifactId>maven-compiler-pluginartifactId>
 57                 <configuration>
 58                     <source>1.8source>
 59                     <target>1.8target>
 60                     <encoding>UTF-8encoding>
 61                 configuration>
 62             plugin>
 63             <plugin>
 64                 <groupId>org.springframework.bootgroupId>
 65                 <artifactId>spring-boot-maven-pluginartifactId>
 66                 
 67                 <executions>
 68                     <execution>
 69                         <goals>
 70                             <goal>repackagegoal>
 71                         goals>
 72                     execution>
 73                 executions>
 74                 <configuration>
 75                     <includeSystemScope>trueincludeSystemScope>
 76                 configuration>
 77             plugin>
 78             <plugin>
 79                 <groupId>org.apache.maven.pluginsgroupId>
 80                 <artifactId>maven-deploy-pluginartifactId>
 81                 <configuration>
 82                     <skip>trueskip>
 83                 configuration>
 84             plugin>
 85             <plugin>
 86                 <groupId>com.spotifygroupId>
 87                 <artifactId>dockerfile-maven-pluginartifactId>
 88                 <version>1.4.13version>
 89                 <executions>
 90                     <execution>
 91                         <id>defaultid>
 92                         <goals>
 93                             <goal>buildgoal>
 94                             <goal>pushgoal>
 95                         goals>
 96                     execution>
 97                 executions>
 98                 <configuration>
 99                     
101                     <repository>${docker.repository}/${docker.image.prefix}/${project.artifactId}repository>
102                     <tag>latesttag>
103                     <buildArgs>
104                         <JAR_FILE>target/${project.build.finalName}.jarJAR_FILE>
105                     buildArgs>
106                     <useMavenSettingsForAuth>trueuseMavenSettingsForAuth>
107                 configuration>
108             plugin>
109         plugins>
110     build>
111 
112 project>
113             
View Code
值得注意的是 blade 是harbor先建立的项目,Dockerfile文件如下:
1 FROM java:8
2 ARG JAR_FILE
3 ADD ${JAR_FILE} app.jar
4 ENTRYPOINT ["java", "-jar", "/app.jar"]
View Code

Harbor IDEA 快速指引_第1张图片

 

 package -->  dockerfile:build (默认是连接到localhost:2375 ,也就是本地docker),我的系统是 winserver 2019 ,win10 2004 开启wsl2 更酷。

Harbor IDEA 快速指引_第2张图片

 

 

 

 以上已经推动到本地的docker中了,然后执行 dockerfile:push ,推动到harbor私有仓库。

Harbor IDEA 快速指引_第3张图片

 

 基本上就可以完成,其中有许多细节和知识点需要自己补充。

k8s 中拉取镜像文件即可运行

Harbor IDEA 快速指引_第4张图片

 

 

计划将 idea -> gitlab  -> jenkins -> harbor -> k8s 串联起来。 

你可能感兴趣的:(Harbor IDEA 快速指引)