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

如果您拥有或维护一个GitHub存储库,并且曾经将某个软件包从其中推送到PyPI和/或Fedora中 ,那么您就会知道,使用Fedora基础架构还需要做一些额外的工作。

好消息:我们开发了一个称为release-bot的工具,该工具可以自动执行该过程。 您所需要做的就是将一个问题提交到上游存储库,而发布机器人负责其余的工作。 但是,让我们不要超越自己。 首先,让我们看一下要实现这种自动化需要设置什么。 我选择了meta-test-family上游存储库作为示例。

发布机器人的配置文件

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

conf.yaml

bot初始化期间必须可以访问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配置文件

将新软件包版本上传到PyPI时,需要将文件.pypirc存储在mtf-release-bot私有存储库中:


   
   
[ pypi ]
username = phracek
password = xxxxxxxx

您在FAS中配置的SSH私钥id_rsa

git存储库的最终结构以及conf.yaml和其他结构如下所示:


   
   
$ 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

要求

适用于Python 2和Python 3的wheel软件包 ,因此请同时安装pip的两个版本的requirements.txt 。 您还必须按照PyPI文档中的说明,在$ HOME / .pypirc中设置您的PyPI登录详细信息。 如果要发布到Fedora,则在漫游器运行时必须具有活动的Kerberos票证,或使用-k/–keytab指定Kerberos密钥表文件的路径。 另外, fedpkg要求您在上传到FAS的密钥环中具有SSH密钥。

如何部署发布机器人

有两种使用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自动关闭了以下问题,并请求meta-test-family的新上游发行版: https : //github.com/fedora-modularity/meta-test-family/issues/243

此外,release-bot使用changelog创建了一个新的PR。 您可以更新PR(例如,squash 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上游存储库中的示例拉取请求 ,您可以在其中找到有关发行的发行版机器人的信息。 一旦达到这一点,您就可以看到release-bot能够将新的上游版本推入GitHub,PyPI和Fedora,而无需过多的用户干预。 它可以自动执行所有步骤,因此您无需手动上传和构建软件包的新上游版本。

翻译自: https://opensource.com/article/18/10/upstream-releases-pypi-fedora-release-bot

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值