使用 Mirrors
是否经常在使用持续集成时因为海外的网络,导致构建非常慢又或者是失败而挠头?
是否因为香港或者是硅谷的节点拉去海外的资源是快了,但是拉取国内的资源时又变慢了而苦恼?
在使用过程中因为这些问题导致构建不稳定只能一直重试和等待伤透了神?
本文会介绍如何使用 腾讯云 Mirrors 加速您的构建,提升稳定性和构建效率。
Gradle Wrapper
- 常见问题:
Gradle 进行构建 JAVA 工程时它会根据项目根目录下的gradle/wrapper/gradle-wrapper.properties
中的如distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
下载 Gradle Wrapper 而下载慢。 - 加速方案:
将gradle/wrapper/gradle-wrapper.properties
中的distributionUrl
改为distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-7.6-bin.zip
参考: Gradle 下载地址。 - 其他优化项: 当您的 JAVA 工程比较大时可以配置一下 Gradle 使用的 JVM 内存大小,让构建更加高效,请参考 https://docs.gradle.org/current/userguide/build_environment.html#sec:configuring_jvm_memory
Gradle 依赖下载
- 常见问题: Gradle 对 JAVA 工程进行编译构建时,它会到 Maven 的中央仓库去下载依赖而下载慢。
单项目构建修改项目根目录下的 build.gradle
文件
repositories {
maven {
url "https://mirrors.cloud.tencent.com/nexus/repository/maven-public/"
// gradle 插件,如果依赖则添加
//url "https://mirrors.cloud.tencent.com/nexus/repository/gradle-plugins/"
}
mavenCentral()
}
多项目构建修改项目根目录下的 build.gradle
文件
allprojects {
repositories {
maven {
url "https://mirrors.cloud.tencent.com/nexus/repository/maven-public/"
// gradle 插件,如果依赖则添加
url "https://mirrors.cloud.tencent.com/nexus/repository/gradle-plugins/"
}
mavenCentral()
}
}
Maven
- 常见问题: Maven 对 JAVA 工程进行编译构建时,它会到 Maven 的中央仓库去下载依赖而下载慢。
修改项目根目录下的 pom.xml
参考 maven-demo 示例仓库。
<project>
<repositories>
<repository>
<id>TencentMirror</id>
<name>Tencent Mirror</name>
<url>https://mirrors.cloud.tencent.com/nexus/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>
PHP
全局配置
所有项目都会使用该镜像地址:
composer config -g repo.packagist composer https://mirrors.cloud.tencent.com/composer/
取消配置:
composer config -g --unset repos.packagist
项目配置(项目根目录下执行)
仅修改当前项目配置:
composer config repo.packagist composer https://mirrors.cloud.tencent.com/composer/
取消配置:
composer config --unset repos.packagist
Dockerfile 使用示例
FROM php:8.1
RUN curl -sS https://install.phpcomposer.com/installer | php
RUN composer config -g repo.packagist composer https://mirrors.cloud.tencent.com/composer/
RUN composer install
Python
- 临时使用
pip install -i https://mirrors.cloud.tencent.com/pypi/simple
pip install -r requirements.txt -i https://mirrors.cloud.tencent.com/pypi/simple
- 设为默认
pip config set global.index-url https://mirrors.cloud.tencent.com/pypi/simple
- Dockerfile 使用示例
FROM python:3.6
ADD speedup .
RUN pip install -r requirements.txt -i https://mirrors.cloud.tencent.com/pypi/simple
CMD python3.6 main.py
NPM
npm config set registry https://mirrors.cloud.tencent.com/npm/
Yarn
yarn config set registry https://mirrors.cloud.tencent.com/npm/
Ubuntu
Ubuntu 的软件源配置文件是 /etc/apt/sources.list。使用前请将系统自带的该文件做备份。
- Ubuntu 16.04
deb https://mirrors.cloud.tencent.com/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.cloud.tencent.com/ubuntu/ xenial-security main restricted universe multiverse
deb https://mirrors.cloud.tencent.com/ubuntu/ xenial-updates main restricted universe multiverse
#deb https://mirrors.cloud.tencent.com/ubuntu/ xenial-proposed main restricted universe multiverse
#deb https://mirrors.cloud.tencent.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src https://mirrors.cloud.tencent.com/ubuntu/ xenial main restricted universe multiverse
deb-src https://mirrors.cloud.tencent.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src https://mirrors.cloud.tencent.com/ubuntu/ xenial-updates main restricted universe multiverse
#deb-src https://mirrors.cloud.tencent.com/ubuntu/ xenial-proposed main restricted universe multiverse
#deb-src https://mirrors.cloud.tencent.com/ubuntu/ xenial-backports main restricted universe multiverse
- Ubuntu 18.04
deb https://mirrors.cloud.tencent.com/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.cloud.tencent.com/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.cloud.tencent.com/ubuntu/ bionic-updates main restricted universe multiverse
#deb https://mirrors.cloud.tencent.com/ubuntu/ bionic-proposed main restricted universe multiverse
#deb https://mirrors.cloud.tencent.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.cloud.tencent.com/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.cloud.tencent.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.cloud.tencent.com/ubuntu/ bionic-updates main restricted universe multiverse
#deb-src https://mirrors.cloud.tencent.com/ubuntu/ bionic-proposed main restricted universe multiverse
#deb-src https://mirrors.cloud.tencent.com/ubuntu/ bionic-backports main restricted universe multiverse
- Ubuntu 20.04
deb https://mirrors.cloud.tencent.com/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.cloud.tencent.com/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.cloud.tencent.com/ubuntu/ focal-updates main restricted universe multiverse
#deb https://mirrors.cloud.tencent.com/ubuntu/ focal-proposed main restricted universe multiverse
#deb https://mirrors.cloud.tencent.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.cloud.tencent.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.cloud.tencent.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.cloud.tencent.com/ubuntu/ focal-updates main restricted universe multiverse
#deb-src https://mirrors.cloud.tencent.com/ubuntu/ focal-proposed main restricted universe multiverse
#deb-src https://mirrors.cloud.tencent.com/ubuntu/ focal-backports main restricted universe multiverse
- Ubuntu 22.04
deb https://mirrors.cloud.tencent.com/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.cloud.tencent.com/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.cloud.tencent.com/ubuntu/ jammy-updates main restricted universe multiverse
#deb https://mirrors.cloud.tencent.com/ubuntu/ jammy-proposed main restricted universe multiverse
#deb https://mirrors.cloud.tencent.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.cloud.tencent.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.cloud.tencent.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.cloud.tencent.com/ubuntu/ jammy-updates main restricted universe multiverse
#deb-src https://mirrors.cloud.tencent.com/ubuntu/ jammy-proposed main restricted universe multiverse
#deb-src https://mirrors.cloud.tencent.com/ubuntu/ jammy-backports main restricted universe multiverse
- 通过 wget 获取配置文件
# 16.04
wget -O /etc/apt/sources.list https://mirrors.cloud.tencent.com/repo/ubuntu16_sources.list
# 18.04
wget -O /etc/apt/sources.list https://mirrors.cloud.tencent.com/repo/ubuntu18_sources.list
# 20.04
wget -O /etc/apt/sources.list https://mirrors.cloud.tencent.com/repo/ubuntu20_sources.list
- Dockerfile 使用示例
FROM ubuntu:22.04
RUN cat <<EOF > /etc/apt/sources.list
deb https://mirrors.cloud.tencent.com/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.cloud.tencent.com/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.cloud.tencent.com/ubuntu/ jammy-updates main restricted universe multiverse
#deb https://mirrors.cloud.tencent.com/ubuntu/ jammy-proposed main restricted universe multiverse
#deb https://mirrors.cloud.tencent.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.cloud.tencent.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.cloud.tencent.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.cloud.tencent.com/ubuntu/ jammy-updates main restricted universe multiverse
#deb-src https://mirrors.cloud.tencent.com/ubuntu/ jammy-proposed main restricted universe multiverse
#deb-src https://mirrors.cloud.tencent.com/ubuntu/ jammy-backports main restricted universe multiverse
EOF
Centos
- 备份旧配置文件
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
- CentOS5
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.cloud.tencent.com/repo/centos5_base.repo
- CentOS6
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.cloud.tencent.com/repo/centos6_base.repo
- CentOS7
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.cloud.tencent.com/repo/centos7_base.repo
- CentOS8
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.cloud.tencent.com/repo/centos8_base.repo
- 更新缓存
yum clean all
yum makecache
Alpine
- 备份旧配置文件
mv /etc/apk/repositories /etc/apk/repositories.backup
- 配置 Mirror
sed -i 's/dl-cdn.alpinelinux.org/mirrors.cloud.tencent.com/g' /etc/apk/repositories
- Dockerfile 使用示例
FROM alpine:3.18.3
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.cloud.tencent.com/g' /etc/apk/repositories
Docker Registry
持续集成公共节点已配置
修改
/etc/docker/daemon.json
,https://mirror.ccs.tencentyun.com
该代理属于腾讯云内网地址。
{
"registry-mirrors": [
"https://mirror.ccs.tencentyun.com"
]
}
- 重启服务生效
systemctl daemon-reload
systemctl restart docker
- 校验是否生效
docker info
问题反馈 >
2024-11-04最近更新
感谢反馈有用
感谢反馈没用
在阅读中是否遇到以下问题?*
您希望我们如何改进?*
如果您希望得到回复,请留下您的邮箱地址。