使用 release-bot 自动化上游发布

您只需在上游仓库中提交一个 issue,release-bot 就会处理剩下的事情。
214 位读者喜欢这篇文章。
Three giant robots and a person

Opensource.com

如果您拥有或维护一个 GitHub 仓库,并且曾经从中将软件包推送到 PyPI 和/或 Fedora,您就会知道这需要使用 Fedora 基础设施进行一些额外的工作。

好消息:我们开发了一个名为 release-bot 的工具,可以自动化这个过程。您只需在上游仓库中提交一个 issue,release-bot 就会处理剩下的事情。但我们先别急着深入细节。首先,让我们看看为了实现这种自动化需要进行哪些设置。我选择了 meta-test-family 上游仓库作为示例。

release-bot 的配置文件

release-bot 有两个配置文件:conf.yamlrelease-conf.yaml

conf.yaml

conf.yaml 必须在机器人初始化期间可访问;它指定了如何访问 GitHub 仓库。为了演示这一点,我创建了一个名为 mtf-release-bot 的新 git 仓库,其中包含 conf.yaml 和其他秘密文件。

repository_name: name
repository_owner: owner
# https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
github_token: xxxxxxxxxxxxxxxxxxxxxxxxx
# time in seconds during checks for new releases
refresh_interval: 180

对于 meta-test-family 的情况,配置文件如下所示

repository_name: meta-test-family
repository_owner: fedora-modularity
github_token: xxxxxxxxxxxxxxxxxxxxx
refresh_interval: 180

release-conf.yaml

release-conf.yaml 必须 存储在仓库本身中;它指定了如何进行 GitHub/PyPI/Fedora 发布。

# list of major python versions that bot will build separate wheels for
python_versions:
  - 2
  - 3
# optional:
changelog:
  - Example changelog entry
  - Another changelog entry
# this is info for the authorship of the changelog
# if this is not set, person who merged the release PR will be used as an author
author_name: John Doe
author_email: johndoe@example.com
# whether to release on fedora. False by default
fedora: false
# list of fedora branches bot should release on. Master is always implied
fedora_branches:
  - f27

对于 meta-test-family 的情况,配置文件如下所示

python_versions:
-	2
fedora: true
fedora_branches:
-	f29
-	f28
trigger_on_issue: true

PyPI 配置文件

文件 .pypirc,存储在您的 mtf-release-bot 私有仓库中,用于将新软件包版本上传到 PyPI

[pypi]
username = phracek
password = xxxxxxxx

私有 SSH 密钥,id_rsa,您在 FAS 中配置的。

包含 conf.yaml 和其他文件的 git 仓库的最终结构如下所示

$ ls -la
total 24
drwxrwxr-x   3 phracek phracek 4096 Sep 24 12:38 .
drwxrwxr-x. 20 phracek phracek 4096 Sep 24 12:37 ..
-rw-rw-r--   1 phracek phracek  199 Sep 24 12:26 conf.yaml
drwxrwxr-x   8 phracek phracek 4096 Sep 24 12:38 .git
-rw-rw-r--   1 phracek phracek 3243 Sep 24 12:38 id_rsa
-rw-------   1 phracek phracek   78 Sep 24 12:28 .pypirc

要求

发布到 PyPI 需要 Python 2 和 Python 3 的 wheel 包,因此请使用两个版本的 pip 安装 requirements.txt。您还必须在 $HOME/.pypirc 中设置您的 PyPI 登录详细信息,如 PyPI 文档中所述。如果您要发布到 Fedora,您必须在机器人运行时拥有有效的 Kerberos 票据,或者使用 -k/–keytab 指定 Kerberos keytab 文件的路径。此外,fedpkg 要求您的密钥环中有一个您上传到 FAS 的 SSH 密钥。

如何部署 release-bot

有两种使用 release-bot 的方式:作为 Docker 镜像或作为 OpenShift 模板。

Docker 镜像

让我们使用 s2i 命令构建镜像

$ s2i build $CONFIGURATION_REPOSITORY_URL usercont/release-bot app-name

其中 $CONFIGURATION_REPOSITORY_URL 是对 GitHub 仓库的引用,例如 https://<GIT_LAB_PATH>/mtf-release-conf.

让我们看看 Docker 镜像

$ docker images
REPOSITORY                               	TAG             	IMAGE ID        	CREATED         	SIZE
mtf-release-bot                     	latest          	08897871e65e    	6 minutes ago   	705 MB
docker.io/usercont/release-bot           	latest          	5b34aa670639    	9 days ago      	705 MB

现在让我们尝试使用以下命令运行 mtf-release-bot 镜像

$ docker run mtf-release-bot
---> Setting up ssh key...
Agent pid 12
Identity added: ./.ssh/id_rsa (./.ssh/id_rsa)
12:21:18.982 configuration.py  DEBUG  Loaded configuration for fedora-modularity/meta-test-family
12:21:18.982 releasebot.py 	INFO   release-bot v0.4.1 reporting for duty!
12:21:18.982 github.py     	DEBUG  Fetching release-conf.yaml
12:21:37.611 releasebot.py 	DEBUG  No merged release PR found
12:21:38.282 releasebot.py 	INFO   Found new release issue with version: 0.8.5
12:21:42.565 releasebot.py 	DEBUG  No more open issues found
12:21:43.190 releasebot.py 	INFO   Making a new PR for release of version 0.8.5 based on an issue.
12:21:46.709 utils.py      	DEBUG  ['git', 'clone', 'https://github.com/fedora-modularity/meta-test-family.git', '.']

12:21:47.401 github.py     	DEBUG  {"message":"Branch not found","documentation_url":"https://developer.github.com/v3/repos/branches/#get-branch"}
12:21:47.994 utils.py      	DEBUG  ['git', 'config', 'user.email', 'the.conu.bot@gmail.com']

12:21:47.996 utils.py      	DEBUG  ['git', 'config', 'user.name', 'Release bot']

12:21:48.009 utils.py      	DEBUG  ['git', 'checkout', '-b', '0.8.5-release']

12:21:48.014 utils.py      	ERROR  No version files found. Aborting version update.
12:21:48.014 utils.py      	WARNING No CHANGELOG.md present in repository
[Errno 2] No such file or directory: '/tmp/tmpmbvb05jq/CHANGELOG.md'
12:21:48.020 utils.py      	DEBUG  ['git', 'commit', '--allow-empty', '-m', '0.8.5 release']
[0.8.5-release 7ee62c6] 0.8.5 release

12:21:51.342 utils.py      	DEBUG  ['git', 'push', 'origin', '0.8.5-release']

12:21:51.905 github.py     	DEBUG  No open PR's found
12:21:51.905 github.py     	DEBUG  Attempting a PR for 0.8.5-release branch
12:21:53.215 github.py     	INFO   Created PR: https://github.com/fedora-modularity/meta-test-family/pull/243
12:21:53.216 releasebot.py 	INFO   I just made a PR request for a release version 0.8.5
12:21:54.154 github.py     	DEBUG  Comment added to PR: I just made a PR request for a release version 0.8.5
 Here's a [link to the PR](https://github.com/fedora-modularity/meta-test-family/pull/243)
12:21:54.154 github.py     	DEBUG  Attempting to close issue #242
12:21:54.992 github.py     	DEBUG  Closed issue #242

正如您所看到的,release-bot 自动关闭了以下 issue,该 issue 请求发布 meta-test-family 的新上游版本:https://github.com/fedora-modularity/meta-test-family/issues/243

此外,release-bot 创建了一个包含 changelog 的新 PR。您可以更新 PR——例如,压缩 changelog——一旦您合并它,它将自动发布到 GitHub,并启动 PyPI 和 Fedora。

现在您有了一个可行的解决方案,可以轻松地将软件包的上游版本发布到 PyPi 和 Fedora。

OpenShift 模板

使用 release-bot 交付自动化发布的另一个选项是在 OpenShift 中部署它。

OpenShift 模板如下所示

kind: Template
apiVersion: v1
metadata:
  name: release-bot
  annotations:
    description: S2I Relase-bot image builder
    tags: release-bot s2i
    iconClass: icon-python
labels:
  template: release-bot
  role: releasebot_application_builder
objects:
  - kind : ImageStream
    apiVersion : v1
    metadata :
        name : ${APP_NAME}
        labels :
          appid : release-bot-${APP_NAME}
  - kind : ImageStream
    apiVersion : v1
    metadata :
      name : ${APP_NAME}-s2i
      labels :
        appid : release-bot-${APP_NAME}
    spec :
      tags :
        - name : latest
          from :
            kind : DockerImage
            name : usercont/release-bot:latest
         #importPolicy:
         #  scheduled: true
  - kind : BuildConfig
    apiVersion : v1
    metadata :
      name : ${APP_NAME}
      labels :
        appid : release-bot-${APP_NAME}
    spec :
      triggers :
        - type : ConfigChange
        - type : ImageChange
      source :
        type : Git
        git :
          uri : ${CONFIGURATION_REPOSITORY}
          contextDir : ${CONFIGURATION_REPOSITORY}
        sourceSecret :
          name : release-bot-secret
      strategy :
        type : Source
        sourceStrategy :
          from :
            kind : ImageStreamTag
            name : ${APP_NAME}-s2i:latest
      output :
        to :
          kind : ImageStreamTag
          name : ${APP_NAME}:latest
  - kind : DeploymentConfig
    apiVersion : v1
    metadata :
      name: ${APP_NAME}
      labels :
        appid : release-bot-${APP_NAME}
    spec :
      strategy :
        type : Rolling
      triggers :
         - type : ConfigChange
         - type : ImageChange
           imageChangeParams :
             automatic : true
             containerNames :
               - ${APP_NAME}
             from :
               kind : ImageStreamTag
               name : ${APP_NAME}:latest
      replicas : 1
      selector :
        deploymentconfig : ${APP_NAME}
      template :
        metadata :
          labels :
            appid: release-bot-${APP_NAME}
            deploymentconfig : ${APP_NAME}
        spec :
          containers :
            - name : ${APP_NAME}
              image : ${APP_NAME}:latest
              resources:
                requests:
                  memory: "64Mi"
                  cpu: "50m"
                limits:
                  memory: "128Mi"
                  cpu: "100m"

parameters :
  - name : APP_NAME
    description : Name of application
    value :
    required : true
  - name : CONFIGURATION_REPOSITORY
    description : Git repository with configuration
    value :
    required : true

将包含秘密文件的 mtf-release-bot 仓库部署到 OpenShift 的最简单方法是使用以下两个命令

$ curl -sLO https://github.com/user-cont/release-bot/raw/master/openshift-template.yml

在您的 OpenShift 实例中,通过运行以下命令部署模板

oc process -p APP_NAME="mtf-release-bot" -p CONFIGURATION_REPOSITORY="git@<git_lab_path>/mtf-release-conf.git" -f openshift-template.yml | oc apply

总结

请参阅 meta-test-family 上游仓库中的示例 pull request,您将在其中找到有关 release-bot 发布内容的信息。一旦您到达这一点,您就可以看到 release-bot 能够将新的上游版本推送到 GitHub、PyPI 和 Fedora,而无需大量用户干预。它自动化了所有步骤,因此您无需手动上传和构建软件包的新上游版本。

User profile image.
红帽高级软件工程师。他是多个专注于容器的项目的贡献者。他是 Userspace Containerization 团队的成员,Python 开发者。他正在从事容器的持续交付管道工作。让我们尽快测试容器。

评论已关闭。

© . All rights reserved.