Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #237 from marusinm/github-app
Browse files Browse the repository at this point in the history
release-bot as a GitHub Application
  • Loading branch information
jpopelka authored Nov 21, 2019
2 parents 26fd936 + f25fa7e commit 3b58d06
Show file tree
Hide file tree
Showing 29 changed files with 460 additions and 623 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ __pycache__/
# Editors and IDEs
.idea/
.vscode/
.DS_Store

dump.rdb


11 changes: 0 additions & 11 deletions .s2i-dev/bin/assemble

This file was deleted.

20 changes: 0 additions & 20 deletions .s2i-dev/bin/run

This file was deleted.

10 changes: 0 additions & 10 deletions .s2i-dev/bin/usage

This file was deleted.

11 changes: 0 additions & 11 deletions .s2i/bin/assemble

This file was deleted.

20 changes: 0 additions & 20 deletions .s2i/bin/run

This file was deleted.

10 changes: 0 additions & 10 deletions .s2i/bin/usage

This file was deleted.

38 changes: 0 additions & 38 deletions Dockerfile

This file was deleted.

32 changes: 32 additions & 0 deletions Dockerfile.app
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM registry.fedoraproject.org/fedora:30

ENV LANG=en_US.UTF-8
# nicer output from the playbook run
ENV ANSIBLE_STDOUT_CALLBACK=debug
# Ansible doesn't like /tmp
COPY files/ /src/files/

USER 0

RUN mkdir /home/release-bot && chmod 0776 /home/release-bot

# Install packages first and reuse the cache as much as possible
RUN dnf install -y ansible \
&& cd /src/ \
&& ansible-playbook -vv -c local -i localhost, files/install-rpm-packages.yaml \
&& dnf clean all

COPY setup.py setup.cfg files/recipe.yaml /src/
# setuptools-scm
COPY .git /src/.git
COPY release_bot/ /src/release_bot/

RUN cd /src/ \
&& ansible-playbook -vv -c local -i localhost, files/recipe.yaml


USER 1001
ENV USER=release-bot
ENV HOME=/home/release-bot

CMD ["release-bot -c /home/release-bot/.config/conf.yaml"]
39 changes: 0 additions & 39 deletions Dockerfile.dev

This file was deleted.

10 changes: 2 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ IMAGE_NAME := usercont/release-bot
IMAGE_NAME_DEV := usercont/release-bot:dev
TEST_IMAGE_NAME := release-bot-tests

image:
docker build --tag=$(IMAGE_NAME) .

image-dev:
docker build --tag=$(IMAGE_NAME_DEV) -f Dockerfile.dev .

image-dev-no-cache:
docker build --no-cache --tag=$(IMAGE_NAME_DEV) -f Dockerfile.dev .
image: files/install-rpm-packages.yaml files/recipe.yaml
docker build --rm -f Dockerfile.app --tag=$(IMAGE_NAME) .

image-test:
docker build --tag=$(TEST_IMAGE_NAME) -f Dockerfile.test .
Expand Down
59 changes: 4 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ Note that you have to setup your login details (see [Requirements](#requirements
```
$ pip install release-bot
```
Other possible installations are through
[Docker](#docker-image), [OpenShift](#openshift-template), [Arch User Repository](#arch-user-repository).
Other possible installations are through [Arch User Repository](#arch-user-repository) or install on repo as [Github Application](#github-application).

First interaction with release bot may be automated releases on Github. Let's do it.

Expand Down Expand Up @@ -187,60 +186,10 @@ Are specified in `requirements.txt`.
You have to setup your PyPI login details in `$HOME/.pypirc` as described in
[PyPI documentation](https://packaging.python.org/tutorials/distributing-packages/#create-an-account).

## Docker image
To make it easier to run this, release-bot is available as an
[source-to-image](https://github.com/openshift/source-to-image) builder image.
## Github Application

You can then create the final image like this:
```
$ s2i build $CONFIGURATION_REPOSITORY_URL usercont/release-bot app-name
```

where $CONFIGURATION_REPOSITORY_URL is link to repository with conf.yaml and .pypirc files.

To test it locally, you can the run the final image like this:

```
$ docker run <app-name>
```

once all changes, configuration files exist in GitHub and git repository contains needed files,
you can try to create an issue in your GitHub repository with string like "X.Y.Z release"
and you can see log like this:
```
$ docker run meta-test-family-bot
---> Setting up ssh key...
Agent pid 12
Identity added: ./.ssh/id_rsa (./.ssh/id_rsa)
11:47:36.212 configuration.py DEBUG Loaded configuration for fedora-modularity/meta-test-family
11:47:36.212 releasebot.py INFO release-bot v0.4.1 reporting for duty!
11:47:36.212 github.py DEBUG Fetching release-conf.yaml
11:47:51.636 releasebot.py DEBUG No merged release PR found
11:47:52.196 releasebot.py INFO Found new release issue with version: 0.8.4
11:47:55.578 releasebot.py DEBUG No more open issues found
11:47:56.098 releasebot.py INFO Making a new PR for release of version 0.8.5 based on an issue.
11:47:57.608 utils.py DEBUG ['git', 'clone', 'https://github.com/fedora-modularity/meta-test-family.git', '.']
...
```
## OpenShift template
You can also run this bot in OpenShift using [openshift-template.yml](openshift-template.yml) in this repository.
You must set two environment variables, the `$APP_NAME` is the name of your release-bot deployment,
and `$CONFIGURATION_REPOSITORY` which contains configuration for the release-bot.
The contents of the repository are described [above](#docker-image).
Note that if you use private repository (which you **absolutely** should),
you will need to set up a new [OpenShift secret](https://docs.openshift.com/container-platform/3.7/dev_guide/secrets.html) named
`release-bot-secret` to authenticate. It can be a ssh private key that you can use to access the repository
(for GitHub see [deploy keys](https://developer.github.com/v3/guides/managing-deploy-keys/)).
Here's an [guide](https://blog.openshift.com/deploy-private-git-repositories/) on
how to do that in OpenShift GUI, or another
[guide](https://blog.openshift.com/deploying-from-private-git-repositories/)
that uses `oc` commandline tool.

By default, the release-bot builder image won't update itself when a
new version of this image is pushed to docker hub.
You can change it by uncommenting lines with `#importPolicy:`
and `#scheduled: true` in [openshift-template.yml](openshift-template.yml).
Then the image will be pulled on a new release.
Release-bot as Github Application is currently in testing and will be available soon in Github market.
Github application will speed-up configuration process.

## Arch User Repository
For Arch or Arch based Linux distributions, you can install the bot from the [AUR Package](https://aur.archlinux.org/packages/release-bot).
Expand Down
5 changes: 5 additions & 0 deletions files/gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[user]
name = Release Bot
email = [email protected]
[push]
default = current
26 changes: 26 additions & 0 deletions files/install-rpm-packages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Install dependencies for release-bot
hosts: all
tasks:
- name: Install all RPM packages needed to run release-bot.
dnf:
name:
- python3-flask
- python3-ipdb # for easy debugging
- python3-jsonschema
- python3-ogr
- python3-pip
- python3-pyyaml
- python3-requests
- python3-setuptools
- python3-setuptools_scm
- python3-setuptools_scm_git_archive
- python3-wheel # for bdist_wheel
- python3-celery
- python3-cryptography
- python3-jwt
- python3-pystache
- python3-redis
- python3-semantic_version
- twine
state: present
55 changes: 55 additions & 0 deletions files/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
- name: This is a recipe for how to cook with release-bot
hosts: all
vars:
home_path: "{{ lookup('env', 'HOME') }}"
ansible_bender:
base_image: FROM registry.fedoraproject.org/fedora:30
#base_image: fedora:29
target_image:
name: docker.io/usercont/release-bot
environment:
FLASK_APP: releasebot.service.web_hook
cmd: flask-3 run -h 0.0.0.0
working_container:
volumes:
- '{{ playbook_dir }}:/src:Z'
tasks:
- name: Create some home dirs
file:
state: directory
path: '{{ home_path }}/{{ item }}'
mode: 0700
with_items:
- .ssh
- .config
- name: Create /secrets
file:
state: directory
path: /secrets
mode: 0777
- name: Copy gitconfig
copy:
src: gitconfig
dest: '{{ home_path }}/.gitconfig'
- name: stat /src
stat:
path: /src
tags:
- no-cache
register: src_path
- name: Let's make sure /src is present
assert:
that:
- 'src_path.stat.isdir'
- name: Copy run.sh
copy:
src: run.sh
dest: /usr/bin/run.sh
mode: 0777
- name: Install release-bot from /src
pip:
name: /src
executable: pip3
- name: Clean all the cache files (especially pip)
shell: rm -rf ~/.cache/*
6 changes: 6 additions & 0 deletions files/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/bash

export RELEASE_BOT_HOME=/home/release-bot

exec release-bot -c /home/release-bot/.config/conf.yaml &
exec celery -A release_bot.celery_task worker -l info
Loading

0 comments on commit 3b58d06

Please sign in to comment.