Skip to content

Instantly share code, notes, and snippets.

@day253
Created December 26, 2024 03:36
Show Gist options
  • Select an option

  • Save day253/e9bdfeb034aa4447140e457600b16807 to your computer and use it in GitHub Desktop.

Select an option

Save day253/e9bdfeb034aa4447140e457600b16807 to your computer and use it in GitHub Desktop.
how-to-install-a-rpm-package-and-its-dependencies-offline
stages:
- build
- pack
- upload
- release
variables:
ARTIFACTS_NAME: ${CI_PROJECT_NAME}.tar.gz
build:
stage: build
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/centos:7.9.2009
script:
- |
set -xv
yum install -y wget yum-utils tree createrepo
# https://stackoverflow.com/questions/60258864/download-all-dependencies-recursively-from-a-rpm-file
wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
# 定义变量
RPM_PATH="$(pwd)/google-chrome-stable_current_x86_64.rpm"
LOCAL_REPO_PATH="/tmp/localrepo"
DOWNLOAD_DIR="$(pwd)/rpms"
# 创建本地仓库目录
mkdir -p "${LOCAL_REPO_PATH}"
mkdir -p "${DOWNLOAD_DIR}"
# 复制 RPM 包到本地仓库
cp "${RPM_PATH}" "${LOCAL_REPO_PATH}"
cp "${RPM_PATH}" "${DOWNLOAD_DIR}"
# 创建仓库元数据
createrepo "${LOCAL_REPO_PATH}"
# 配置本地 YUM 仓库
echo "[localrepo]
name=Local Repository
baseurl=file://${LOCAL_REPO_PATH}
enabled=1
gpgcheck=0" > /etc/yum.repos.d/localrepo.repo
# 清理并更新 YUM 缓存
yum clean all
yum makecache
# 使用 yumdownloader 下载依赖
# https://stackoverflow.com/questions/50648152/how-to-install-a-rpm-package-and-its-dependencies-offline/50683836#50683836
yumdownloader --resolve --destdir="${DOWNLOAD_DIR}" $(rpm -qpR "${RPM_PATH}")
# 清理和移除本地 YUM 仓库
rm -rf "${LOCAL_REPO_PATH}"
rm /etc/yum.repos.d/localrepo.repo
yum clean all
echo "依赖下载完成,保存在 ${DOWNLOAD_DIR}"
ls -la "${DOWNLOAD_DIR}"
tar czf ${ARTIFACTS_NAME} "${DOWNLOAD_DIR}"
# yum install -y --cacheonly --disablerepo=* "${DOWNLOAD_DIR}"/*.rpm
artifacts:
paths:
- ${ARTIFACTS_NAME}
expire_in: 1 day
tags:
- hk
upload:
stage: upload
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/curlimages/curl:7.85.0
rules:
- if: $CI_COMMIT_TAG
script:
- |
PACKAGE_VERSION=$(echo ${CI_COMMIT_TAG} | awk -F "-" '{print $NF}')
PACKAGE_REGISTRY_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${PACKAGE_VERSION}"
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file ${ARTIFACTS_NAME} ${PACKAGE_REGISTRY_URL}/${ARTIFACTS_NAME}
release:
stage: release
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/gitlab-release-cli:latest
rules:
- if: $CI_COMMIT_TAG
script:
- |
PACKAGE_VERSION=$(echo ${CI_COMMIT_TAG} | awk -F "-" '{print $NF}')
PACKAGE_REGISTRY_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${PACKAGE_VERSION}"
- >
release-cli create
--name "Release $CI_COMMIT_TAG"
--description "Release of $CI_COMMIT_TAG from $CI_PROJECT_NAME"
--tag-name "$CI_COMMIT_TAG"
--assets-link "{\"name\":\"${ARTIFACTS_NAME}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${ARTIFACTS_NAME}\"}"
- |
echo 'Created released of ${CI_PROJECT_NAME}!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment