### Install and Start Consul Agent (Bash) Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/install/binary/README.md Demonstrates commands for installing and starting Consul agents. It shows examples for both local execution and a server machine, emphasizing the use of data directories, datacenter names, domain configurations, and bind addresses. The UI port is also specified. ```bash consul agent -data-dir=/usr/local/var/consul -datacenter=bk-repo -domain=bk-repo -bind=<本地IP> -retry-join= -http-port=8081 -ui (本地执行) consul agent -server -data-dir=/data/consul -ui -client=0.0.0.0 -bind= -http-port=8500 -datacenter=bk-repo -domain=bk-repo -bootstrap (工作机执行) ``` -------------------------------- ### RPM Package .spec File Example Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/repository/rpm.md This is an example of an RPM .spec file, defining package metadata such as name, version, release, summary, and license. It also includes sections for preparation (%prep), building (%build), installation (%install), and file listing (%files). ```txt Name: bkrepo-test Version: 1.1 Release: 1 Summary: Test same artifactUri but different content! License: FIXME %description This is my first RPM package, which does nothing. %prep # we have no source, so nothing here %build cat > bkrepo-test.sh < bkrepo-test.sh <' with the actual repository URL. ```shell helm repo add bkee helm install bkrepo bkee/bkrepo ``` -------------------------------- ### Startup and Packaging Source: https://github.com/tencentblueking/bk-repo/blob/master/src/backend/README.md Instructions on how to start and package the BK-Repo application using both IDEs and Gradle. ```APIDOC ## Startup and Packaging ### 启动说明 (Startup Instructions) #### Idea To run the application in an IDE, directly execute the `main` function in the `XXXApplication.kt` file located within the `xxx-boot` module. #### Gradle Leveraging the Spring Boot Gradle plugin, the `bootRun` task can be used to start the application. ```bash # Run a specific microservice ./gradlew xxx:boot-xxx:bootRun ``` ### 打包说明 (Packaging Instructions) Using the Spring Boot Gradle plugin, the `bootJar` task is used for packaging. ```bash # Package a single microservice ./gradlew xxx:boot-xxx:bootJar # Package all microservices ./gradlew bootJar ``` **Note on Gradle Configuration:** The Spring Boot plugin by default disables the standard `jar` task for modules starting with `boot-`. The `build.gradle` file contains the following configuration: ```gradle def isBootProject = project.name.startsWith("boot-") jar.enabled = !isBootProject bootJar.enabled = isBootProject bootRun.enabled = isBootProject ``` This ensures that modules prefixed with `boot-` are packaged as executable JARs (`bootJar`, `bootRun`), while other modules are packaged as dependency JARs (`jar`). ``` -------------------------------- ### Deploy and Start bkrepo Gateway Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/install/binary/gateway.md This section covers the deployment and startup of the bkrepo gateway. It involves configuring environment parameters, rendering gateway template files using a script, and creating a symbolic link for the Nginx configuration. Finally, it provides commands to start, reload, and manage the Nginx service. ```shell # Configure parameters in $WORK_DIR/bkrepo/scripts/repo.env # Execute render command to generate gateway template files cd $WORK_DIR/bkrepo/scripts chmod +x render_tpl ./render_tpl -u -p /data/bkee -m bkrepo -e repo.env $WORK_DIR/bkrepo/support-files/templates/gateway* # Symlink the gateway nginx configuration directory to nginx conf directory rm -rf /usr/local/openresty/nginx/conf ln -s $WORK_DIR/bkrepo/gateway /usr/local/openresty/nginx/conf # Start commands mkdir -p /usr/local/openresty/nginx/run/ # Create PID directory cd /usr/local/openresty/nginx # Enter nginx installation directory ./sbin/nginx -t # Verify nginx configuration ./sbin/nginx # Start nginx ./sbin/nginx -s reload # Restart nginx ``` -------------------------------- ### Troubleshoot Slow Initial Startup and Not Ready Pods Source: https://github.com/tencentblueking/bk-repo/blob/master/support-files/kubernetes/charts/bkrepo/README.md Explains that slow initial startup and pods remaining in a 'Not Ready' state are often due to the MongoDB deployment taking time to complete, including database table and index creation. ```text 2. 首次启动时间过长,且READY状态为`0/1`? 答: 如果选择了部署`mongodb Chart`,需要等待`mongodb`部署完成后,`bkrepo`相关容器才会启动;启动过程涉及到数据表以及索引创建,这个期间容器状态为`Not Ready`。 ``` -------------------------------- ### Update Helm Repository and Install Chart from BK-Repo Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/repository/helm.md Before installing a chart, it's often necessary to update the local Helm repository cache to fetch the latest information about available charts. This command then installs a specified chart from the configured repository. ```powershell # 下载会提示先执行repo update操作 $ helm repo update # 下载指定包 $ helm install localhost/mychart ``` -------------------------------- ### Install Composer Dependencies Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/repository/composer.md Installs Composer dependencies for a PHP project. This command is executed within the project directory. The `composer.json` file should be configured with the repository URL and any required packages. ```bash composer.phar install ``` -------------------------------- ### Package All Microservices with Gradle Source: https://github.com/tencentblueking/bk-repo/blob/master/src/backend/README.md This command uses the Gradle wrapper to execute the 'bootJar' task for all modules. It packages all microservices into executable JAR files. ```bash ./gradlew bootJar ``` -------------------------------- ### Start Consul Client Agent Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/install/binary/consul.md Command to start a Consul client agent. It requires the data directory, datacenter, and domain. Crucially, it needs the IP address of a server to join the cluster and the local IP for binding. ```shell consul agent -data-dir={consul_directory} -datacenter=bk-repo -domain=bk-repo -join={server_IP} -bind={local_IP} # Example: consul client IP=10.10.10.2 consul agent -data-dir=/data/consul -datacenter=bk-repo -domain=bk-repo -join=10.10.10.1 -bind=10.10.10.2 ``` -------------------------------- ### Run Microservice with Gradle Source: https://github.com/tencentblueking/bk-repo/blob/master/src/backend/README.md This command uses the Gradle wrapper to execute the 'bootRun' task for a specific microservice (e.g., 'xxx'). This is used for running individual microservices during development. ```bash ./gradlew xxx:boot-xxx:bootRun ``` -------------------------------- ### Install Package from BK-Repo PyPI with pip Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/repository/pypi.md These snippets illustrate how to install Python packages from the BK-Repo PyPI repository using pip. The first method involves configuring pip globally to use the BK-Repo as the default index, while the second method specifies the repository URL directly in the install command. ```bash pip3 install {packageName}=={version} ``` ```bash pip3 install -i http://{bk_repo_addr}/{projectId}/{repoName} {package}=={version} ``` -------------------------------- ### Start Consul Server Agent Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/install/binary/consul.md Command to start a Consul server agent. It specifies the data directory, enables the UI, sets the HTTP port, and defines datacenter and domain configurations. The '-bootstrap' flag indicates it's the first server in a new cluster. ```shell consul agent -server -data-dir={consul_directory} -ui -http-port={consul_http_port} -datacenter=bk-repo -domain=bk-repo -bootstrap -client=0.0.0.0 # Example: consul server IP=10.10.10.1 consul agent -server -data-dir=/data/consul -ui -http-port=8080 -datacenter=bk-repo -domain=bk-repo -bootstrap -client=0.0.0.0 ``` -------------------------------- ### Set Deployment Environment Variables (Bash) Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/install/binary/README.md Configures essential environment variables for BK-Repo deployment by editing the system's profile file. These variables include paths, database credentials, and Consul server details. Ensure these are set correctly before proceeding with the installation. ```bash sudo vim /etc/profile export WORK_DIR=/data/bkee export BK_REPO_MONGODB_USER= export BK_REPO_MONGODB_PASSWORD= export BK_REPO_MONGODB_ADDR= export BK_REPO_MONGODB_DB_NAME= export BK_REPO_SERVICE_PREFIX=bkrepo- export BK_REPO_CONSUL_SERVER_HOST= export BK_REPO_CONSUL_SERVER_PORT= ``` -------------------------------- ### Run Proxy on Windows Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/install/proxy.md This bash command demonstrates how to run the proxy JAR file on a Windows system. It specifies the file storage path using a system property and requires JDK 17. Upon successful startup, log and runtime directories will be created. ```bash javaw -D'storage.filesystem.path=Z:\data\store' -jar proxy.jar ``` -------------------------------- ### Modify Consul Program Permissions and Install Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/install/binary/consul.md This snippet shows how to change the file permissions of the Consul executable to make it executable and then move it to the global binary directory. This ensures Consul can be run from anywhere on the system. ```shell # Modify consul program mod chmod 755 ./consul # Move consul program to /usr/local/sbin/ cp ./consul /usr/local/sbin/ ``` -------------------------------- ### Package Single Microservice with Gradle Source: https://github.com/tencentblueking/bk-repo/blob/master/src/backend/README.md This command utilizes the Gradle wrapper to execute the 'bootJar' task for a specific microservice (e.g., 'xxx'). This creates an executable JAR file for that microservice. ```bash ./gradlew xxx:boot-xxx:bootJar ``` -------------------------------- ### Deploy JAR to Maven Repository Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/repository/maven.md This section details how to deploy a JAR file to a configured Maven repository using the `mvn deploy:deploy-file` command. It includes necessary parameters and an example of the Maven settings configuration. ```APIDOC ## Deploy JAR to Maven Repository ### Description Deploys a JAR file to a specified Maven repository using the `mvn deploy:deploy-file` command. Requires specifying file path, artifact details, and repository URL. Authentication can be handled via `settings.xml`. ### Method N/A (Maven command) ### Endpoint N/A (Uses repository URL provided in command) ### Parameters #### Command Line Parameters for `mvn deploy:deploy-file` - **-Dfile** (string) - Required - The path to the JAR file to deploy. - **-DgroupId** (string) - Required - The group ID of the artifact. - **-DartifactId** (string) - Required - The artifact ID of the artifact. - **-Dversion** (string) - Required - The version of the artifact. - **-Dpackaging** (string) - Required - The packaging type (e.g., 'jar'). - **-DrepositoryId** (string) - Optional - The ID of the repository, used for authentication if defined in `settings.xml`. - **-Durl** (string) - Required - The URL of the repository to deploy to. ### Request Example (Command Line) ```bash mvn deploy:deploy-file \ -Dfile=/abc/bcd/example-1.0.0.jar \ -DgroupId=com.xxx.yyy.zzz \ -DartifactId=example \ -Dversion=1.0.0 \ -Dpackaging=jar \ -DrepositoryId=file-http \ -Durl=http://{bk_repo_addr}/{projectId}/{repoName} ``` ### Maven Settings Configuration (`settings.xml`) Configure server credentials for repository authentication. ```xml file-http admin password ``` ``` -------------------------------- ### Get One-Time Task Status Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/apidoc/replication/remote-replication.md Retrieves the execution status of a one-time task. Requires the project ID, repository name, and the task name. Returns task details including status, start and end times, and any error reasons. ```http GET /replication/api/remote/distribution/get/runOnceTaskStatus/{projectId}/{repoName}?name={name} ``` -------------------------------- ### POST /auth/api/user/create/project Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/apidoc/auth/user.md Creates a new user and assigns them as a project administrator. ```APIDOC ## POST /auth/api/user/create/project ### Description Creates a new user and assigns them as a project administrator. ### Method POST ### Endpoint /auth/api/user/create/project ### Parameters #### Request Body - **name** (string) - Required - The username. - **pwd** (string) - Required - The password for the user. - **userId** (string) - Required - The unique identifier for the user. - **asstUsers** (string array) - Optional - A list of associated user IDs. Defaults to []. - **group** (boolean) - Optional - Indicates if this is a group account. Defaults to false. - **projectId** (string) - Required - The ID of the project to associate the user with. ### Request Example ```json { "name":"string", "pwd":"string", "userId":"string", "asstUsers":["owen"], "group":true, "projectId":"test" } ``` ### Response #### Success Response (200) - **code** (integer) - Indicates success (0) or failure (>0). - **message** (string) - Contains an error message if the operation failed. - **data** (boolean) - The result of the operation. - **traceId** (string) - A unique identifier for tracing the request. #### Response Example ```json { "code": 0, "message": null, "data": true, "traceId": "" } ``` ``` -------------------------------- ### Upload Package to BK-Repo PyPI with twine Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/repository/pypi.md This example demonstrates how to upload Python packages to a BK-Repo PyPI repository using the 'twine' tool. It requires configuring the repository details and authentication in the `.pypirc` file and then executing the upload command. ```txt [distutils] index-servers = bkrepo [bkrepo] repository = http://{bk_repo_addr}/{projectId}/{repoName}/simple username = {user} password = {password} ``` ```bash python3 -m twine upload -r {bkrepo} dist/* ``` -------------------------------- ### POST /generic/separate/{project}/{repo}/{path} - Initialize Block Upload Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/apidoc/generic/SeparateBlock.md Initializes a block upload process for a generic artifact. This endpoint is used to obtain an upload ID before starting to upload individual file chunks. ```APIDOC ## POST /generic/separate/{project}/{repo}/{path} ### Description Initializes a block upload process for a generic artifact. This endpoint is used to obtain an upload ID before starting to upload individual file chunks. ### Method POST ### Endpoint `/generic/separate/{project}/{repo}/{path}` ### Parameters #### Path Parameters - **project** (string) - Required - Project name - **repo** (string) - Required - Repo name - **path** (string) - Required - Full path #### Request Headers - **X-BKREPO-OVERWRITE** (boolean) - Optional - Default: false - Overwrite existing file ### Response #### Success Response (200) - **code** (int) - Error code, 0 indicates success. - **message** (string) - The failure message. - **data** (object) - Response data. - **uploadId** (string) - Block upload ID. - **expireSeconds** (long) - Upload ID expiration in seconds. - **traceId** (string) - Trace ID. #### Response Example ```json { "code": 0, "message": null, "data": { "uploadId": "8be31384f82a45b0aafb6c6add29e94f/xxxxxxxx", "expireSeconds": 43200 }, "traceId": null } ``` ``` -------------------------------- ### Manage RPM Packages with Yum and Curl Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/repository/rpm.md This set of commands covers common operations for managing RPM packages using yum and curl. It includes uploading packages, installing, checking for updates, downloading from specific repositories, removing packages, and cleaning cache or metadata. ```shell #发布 curl -u{admin}:{password} -XPUT http://{bk_repo_addr}/{projectId}/{repoName} -T {文件路径} #下载 yum install -y {package} # 添加源后快速使源生效 yum check-update #从指定源下载 yum install nginx --enablerepo={源名称} #删除包 yum erase -y {package} #清除缓存的包 yum clean packages --enablerepo={源名称} #清除对应仓库的元数据 yum clean metadata --enablerepo={源名称} #上传组文件,必须上传至仓库repodata 目录 curl -u{admin}:{password} -XPUT http://{bk_repo_addr}/{projectId}/{repoName}/{repodata}/ -T {文件路径} #group 列表 yum grouplist #下载组包含的包 yum groupinstall {group} #在系统中移除组,不会移除安装的包 yum groups mark remove {group} #移除通过组安装的包,在系统中组依然是被安装 yum groupremove {group} #升级group下所有包 yum groupupdate {groupName} ``` -------------------------------- ### Gradle Build Configuration for Boot Projects Source: https://github.com/tencentblueking/bk-repo/blob/master/src/backend/README.md This Gradle configuration snippet defines how JAR and bootJar tasks are enabled based on the project name. Projects starting with 'boot-' are configured to use 'bootJar' for executable JARs, while others use the standard 'jar' task for dependency JARs. ```gradle def isBootProject = project.name.startsWith("boot-") jar.enabled = !isBootProject bootJar.enabled = isBootProject bootRun.enabled = isBootProject ``` -------------------------------- ### Download Package Version (API Example) Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/apidoc/package/package.md API endpoint to download a specific version of a package. It requires project ID, repository name, package key, and version as path or query parameters. The response is a file stream. ```http GET /repository/api/version/download/{projectId}/{repoName}?packageKey=npm://test&version=0.0.1 ``` -------------------------------- ### GET /generic/separate/{project}/{repo}/{path} - List Uploaded Blocks Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/apidoc/generic/SeparateBlock.md This endpoint retrieves a list of already uploaded blocks for a given chunked upload. It requires project, repository, and path details, along with a Block Upload ID in the header. ```APIDOC ## GET /generic/separate/{project}/{repo}/{path} ### Description Lists the uploaded blocks for a chunked upload. ### Method GET ### Endpoint `/generic/separate/{project}/{repo}/{path}` ### Parameters #### Path Parameters - **project** (string) - Required - Project name - **repo** (string) - Required - Repository name - **path** (string) - Required - Full path #### Request Headers - **X-BKREPO-UPLOAD-ID** (string) - Required - Block upload ID #### Request Body This endpoint does not have a request body. ### Response #### Success Response (200) - **code** (int) - Error code, 0 indicates success. - **message** (string) - The failure message. - **data** (array) - List of block information. - **traceId** (string) - Trace ID. #### Block Information Fields - **size** (long) - Block size (in bytes). - **sha256** (string) - SHA256 checksum of the block. - **startPos** (long) - Block start position. - **uploadId** (string) - Block upload ID. #### Response Example ```json { "code": 0, "message": null, "data": [ { "size": 10240, "sha256": "abc123def456...", "startPos": 0, "uploadId": "1.0" }, { "size": 10240, "sha256": "def456ghi789...", "startPos": 10240, "uploadId": "1.0" } ], "traceId": null } ``` ``` -------------------------------- ### Create, Package, and Push Helm Chart to BK-Repo Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/repository/helm.md This sequence of commands first creates a new Helm chart, then packages it into a versioned archive, and finally pushes it to the specified Helm repository. Ensure you are in the chart's directory before packaging and pushing. ```powershell # 创建helm包 $ helm create mychart # 打包 $ helm package ./ # 上传 $ helm push mychart-0.1.0.tgz localhost ``` -------------------------------- ### Configure Gateway with OpenResty (Shell) Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/install/binary/README.md Deploys the gateway component using OpenResty. This involves rendering gateway configuration templates, moving the generated gateway module to the correct directory, and creating a symbolic link to the Nginx configuration. It also includes instructions for updating the local hosts file. ```shell cd $WORK_DIR/bkrepo/scripts chmod +x render_tpl ./render_tpl -u -p /data/bkee -m bkrepo -e repo.env $WORK_DIR/bkrepo/support-files/templates/gateway* rm -rf /usr/local/openresty/nginx/conf ln -s $WORK_DIR/bkrepo/gateway /usr/local/openresty/nginx/conf sudo vim /etc/hosts # Example: <工作机IP> bkrepo.example.com ``` -------------------------------- ### Configure Host File for NodePort Service Source: https://github.com/tencentblueking/bk-repo/blob/master/support-files/kubernetes/charts/bkrepo/templates/NOTES.txt This snippet shows how to configure the /etc/hosts file when using a NodePort service type. It retrieves the NodePort and NodeIP, then maps them to the gateway host, dockerHost, and helmHost. ```bash export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "common.names.fullname" . }}-gateway) export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") echo "$NODE_IP {{ .Values.gateway.host }}" >> /etc/hosts {{- if .Values.docker.enabled }} echo "$NODE_IP {{ .Values.gateway.dockerHost }}" >> /etc/hosts {{- end }} {{- if .Values.helm.enabled }} echo "$NODE_IP {{ .Values.gateway.helmHost }}" >> /etc/hosts {{- end }} ``` -------------------------------- ### List Uploaded Blocks API Request Source: https://github.com/tencentblueking/bk-repo/blob/master/docs/apidoc/generic/SeparateBlock.md This snippet shows how to make a GET request to the BK Repo API to list uploaded blocks for a specific file. It requires project, repo, and path as URL parameters, and an 'X-BKREPO-UPLOAD-ID' in the request header. The request body is empty. ```http GET /generic/separate/{project}/{repo}/{path} HTTP/1.1 Host: your-bk-repo-host.com X-BKREPO-UPLOAD-ID: your-upload-id ```