Doker安装
- 创建一个data目录用于数据持久化
mkdir data chmod -R 777 ./data
- docker部署
docker run -it -d \ --name artifactory \ --restart always \ -v $PWD/data/:/var/opt/jfrog/artifactory \ -p 18081:8081 \ -p 18082:8082 \ releases-docker.jfrog.io/jfrog/artifactory-oss:latest
- 快速部署
docker pull docker.bintray.io/jfrog/artifactory-oss docker run -d -p 8081:8081 docker.bintray.io/jfrog/artifactory-oss
- 快速部署
- 访问 http://localhost:18082/ui/
默认账号:admin/password
测试
CURL测试
上传
# 如果v1.0不存在会自动创建
curl -X PUT -u 用户名:密码 -T app.jar jfrog地址:端口/artifactory/v1.0/
curl -u test:密码 -T el7upgradeSSHv8.5p1.tar.gz https://test.com:8081/artifactory/test/el7upgradeSSHv8.5p1.tar.gz
curl -X PUT -u ${JFROG_USER}:${JFROG_PWD} -T 1.txt "${ARTIFACTORY_URL}/temp/1.txt"
# deploy files with property
curl -X PUT -u ${JFROG_USER}:${JFROG_PWD} -T 1.sh "${ARTIFACTORY_URL}/temp/1.sh;retention.days=20;build_os=ubuntu-18.04;"
下载
wget --user test --password '密码' https://test.com:8082/artifactory/public-tools/anymatch-2.0.0.tgz
curl -u ${JFROG_USER}:${JFROG_PWD} -O ${ARTIFACTORY_URL}/temp/1.txt
copy 文件
curl -X POST -u ${JFROG_USER}:${JFROG_PWD} ${ARTIFACTORY_URL}/api/copy/temp/1.txt?to=temp/2.txt
删除
curl -X DELETE -u 用户名:密码 jfrog地址:端口/artifactory/v1.0/app.jar #删除文件
curl -X DELETE -u 用户名:密码 jfrog地址:端口/artifactory/v1.0/ #删除目录
curl -X DELETE -u ${JFROG_USER}:${JFROG_PWD} ${ARTIFACTORY_URL}/temp/1.txt
支持删除整个目录
获取files list
curl -u ${JFROG_USER}:${JFROG_PWD} -X POST ${ARTIFACTORY_URL}/api/search/aql -H 'Content-Type: text/plain' -d \
"items.find({ \
\"type\" : \"file\", \
\"repo\" : {\"\$eq\" : \"${atf_repo}\"}, \
\"path\":{\"\$match\":\"${atf_path}*\"} \
}).include(\"name\",\"repo\",\"path\",\"actual_md5\",\"type\")" | tee "${tmp_file}"
获取多少天创建的files list
curl -u ${JFROG_USER}:${JFROG_PWD} -X POST ${ARTIFACTORY_URL}/api/search/aql -H 'Content-Type: text/plain' -d \
"items.find({ \
\"type\" : \"file\", \
\"repo\" : {\"\$eq\" : \"${repo}\"}, \
\"\$or\": [\
{\
\"\$and\": [\
{\
\"created\": { \"\$before\":\"${retention_days}d\" }\
}\
]\
}\
]\
}).include(\"name\",\"repo\",\"path\",\"actual_md5\",\"type\")" \
| jq '.results' \
| jq '.[] | "\(.repo)/\(.path)/\(.name)"' \
| sed 's/"//g' \
| sed "s#^#${ARTIFACTORY_URL}/#g"
java测试
<dependency>
<groupId>org.jfrog.artifactory.client</groupId>
<artifactId>artifactory-java-client-services</artifactId>
<version>RELEASE</version>
</dependency>
import org.jfrog.artifactory.client.Artifactory;
import org.jfrog.artifactory.client.ArtifactoryClientBuilder;
import org.jfrog.artifactory.client.model.File;
import org.jfrog.artifactory.client.model.RepoPath;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
public class JFrogConnectionTest {
@Test
public void test0() throws IOException {
Artifactory artifactory = ArtifactoryClientBuilder.create()
.setUrl("ArtifactoryUrl")
.setUsername("username")
.setPassword("password")
.build();
// 上传
java.io.File file = new java.io.File("fileToUpload.txt");
File result = artifactory.repository("RepoName").upload("path/to/newName.txt", file).doUpload();
// 下载
InputStream iStream = artifactory.repository("RepoName")
.download("path/to/fileToDownload.txt")
.doDownload();
FileOutputStream fos = new FileOutputStream("b.txt");
byte[] b = new byte[1024];
int length;
while((length= iStream.read(b)) > 0){
fos.write(b,0,length);
}
iStream.close();
fos.close();
// 搜索
List<RepoPath> searchItems = artifactory.searches()
.repositories("RepoName", "RepoName2")
.artifactsByName("prefixedWith*.txt")
.doSearch();
for (RepoPath searchItem : searchItems) {
String repoKey = searchItem.getRepoKey();
String itemPath = searchItem.getItemPath();
}
// 关闭Artifactory实例
artifactory.close();
}
}
上传应用
-
生成配置
生成Artifactory仓库上传配置文件,选择仓库,点击‘Set Me Up’查看部署配置
- Type password to insert your credentials to the code snippets 如果输入密码的话,生成的settins.xml文件有密码;否则不会生成密码
- Releases jar发布版本的仓库
- Snapshots jar快照版本的仓库
- Plugin Releases 插件发版版本的仓库
- Plugin Snapshots 插件快照版本的仓库
下载下来的 settings.xml 文件,servers节点的配置不对的,以下是下载下来的settings.xml文件的内容
下载下的settings.xml
<servers> <server> <username>${security.getCurrentUsername()}</username> <password>${security.getEscapedEncryptedPassword()!"AP618vz432Djy5gwWfBu5jWR5hL"}</password> <id>central</id> </server> <server> <username>${security.getCurrentUsername()}</username> <password>${security.getEscapedEncryptedPassword()!"AP618vz432Djy5gwWfBu5jWR5hL"}</password> <id>snapshots</id> </server> </servers>
修改为:
需要把username和pasword修改正确
<servers> <server> <username>admin</username> <password>AP618vz432Djy5gwWfBu5jWR5hL</password> <id>central</id> </server> <server> <username>admin</username> <password>AP618vz432Djy5gwWfBu5jWR5hL</password> <id>snapshots</id> </server> </servers>
-
拷贝配置
拷贝配置到项目中的POM文件,添加配置DistributionManagement注意id和url要配置正确, 与setting文件的一致. 如果不是使用虚拟库来部署, 这里的url就指定私库, 但是id要与setting中的server一致, 因为会通过id去找用户密码
<distributionManagement> <repository> <id>central</id> <name>ssc-center</name> <url>http://192.168.159.134:8082/artifactory/ssc-center</url> </repository> <snapshotRepository> <id>snapshots</id> <name>ssc-center</name> <url>http://192.168.159.134:8082/artifactory/ssc-center</url> </snapshotRepository> </distributionManagement>
-
上传
项目中deploy即可, 成功后可以在仓库中看到部署上的jar包信息mvn deploy
-
查看
下载制品
-
获取密文密码
-
下载
curl -u admin:AKCp8k8ie8z87ysDfDFwQbSkAEnEM7m2p1XEGHQgqevRjbxjMEEoH3bV4LYY1qZdUq1R3nzxH http://192.168.159.134:8082/artifactory/ssc-release-local/org/wangqing/notebook-k8s/notebook-service/1.1/notebook-service-1.1.jar --output notebook-service-1.1.jar