Skip to content

Commit

Permalink
Replace nix with poetry (#10)
Browse files Browse the repository at this point in the history
* Remove nix
* Introduce poetry to lock dependencies
* Update Poetry to 1.1.15

Co-authored-by: Hanfei Shen <[email protected]>
  • Loading branch information
slovdahl and Hanfei Shen authored Dec 22, 2022
1 parent 9e9cc0c commit 3ba2516
Show file tree
Hide file tree
Showing 22 changed files with 1,458 additions and 1,081 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: cachix/install-nix-action@v13
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Dockerize
run: make dockerize
- name: Deploy to DockerHub
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ jobs:
- '3.8'
- '3.9'
- '3.10'
poetry-version:
- '1.1.15'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
run: pip install poetry==${{ matrix.poetry-version }}
- name: Install requirements
run: pip install -r requirements_frozen.txt
run: poetry install
- name: Run tests
run: pytest
run: poetry run pytest
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ ENV/
*.egg-info
.coverage
.pytest_cache

# nix stuff
result
result-*
/MANIFEST
/build/
/dist/

# Editor
*.sw[po]
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM python:3.9-slim AS builder

ARG POETRY_VERSION=1.1.15
RUN pip install poetry==$POETRY_VERSION

WORKDIR /src

COPY pyproject.toml poetry.lock README.md pylintrc ./
COPY marge/ ./marge/
RUN poetry export -o requirements.txt && \
poetry build


FROM python:3.9-slim

RUN apt-get update && apt-get install -y \
git-core \
&& \
rm -rf /var/lib/apt/lists/*

COPY --from=builder /src/requirements.txt /src/dist/marge-*.tar.gz /tmp/

RUN pip install -r /tmp/requirements.txt && \
pip install /tmp/marge-*.tar.gz

ENTRYPOINT ["marge"]
36 changes: 19 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
VERSION?=$$(git rev-parse --abbrev-ref HEAD)

.PHONY: all
all: requirements_frozen.txt requirements.nix requirements_override.nix marge-bot dockerize
all: dockerize

.PHONY: marge-bot
marge-bot:
nix-build --keep-failed --attr marge-bot default.nix
.PHONY: bump
bump: bump-requirements

.PHONY: clean
clean:
rm -rf .cache result result-* requirements_frozen.txt
poetry.lock:
poetry install

.PHONY: bump
bump: bump-requirements bump-sources
requirements.txt: poetry.lock
poetry export -o $@

.PHONY: bump-sources
bump-sources:
nix-shell --run niv update
requirements_development.txt: poetry.lock
poetry export --dev -o $@

.PHONY: bump-requirements
bump-requirements: clean requirements_frozen.txt
.PHONY: bump-poetry-lock
bump-poetry-lock:
poetry update

requirements_frozen.txt requirements.nix requirements_override.nix: requirements.txt
pypi2nix -V 3.6 -r $^
.PHONY: clean-requirements
clean-requirements:
rm -rf requirements.txt requirements_development.txt

.PHONY: bump-requirements
bump-requirements: bump-poetry-lock clean-requirements requirements.txt requirements_development.txt

.PHONY: dockerize
dockerize:
docker load --input $$(nix-build --attr docker-image default.nix)
docker build --tag hiboxsystems/marge-bot:$$(cat version) .

.PHONY: docker-push
docker-push:
Expand Down
45 changes: 20 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ optional arguments:
[env var: MARGE_USE_MERGE_COMMIT_BATCHES] (default: False)
--skip-ci-batches Skip CI when updating individual MRs when using batches [env var: MARGE_SKIP_CI_BATCHES] (default: False)
```
Here is a config file example
```yaml
add-part-of: true
add-reviewers: true
Expand All @@ -164,8 +166,8 @@ ssh-key-file: token.FILE
# OR use HTTPS instead of SSH
#use-https: true
```
For more information about configuring marge-bot see `--help`
For more information about configuring marge-bot see `--help`
## Running
Expand Down Expand Up @@ -280,6 +282,7 @@ docker run --restart=on-failure \ # restart if marge crashes because GitLab is f
HTTPS can be used using any other deployment technique as well.
### Running marge-bot in kubernetes
It's also possible to run marge in kubernetes, e.g. here's how you use a ktmpl
template:
Expand All @@ -298,6 +301,7 @@ Once running, the bot will continuously monitor all projects that have its user
will pick up any changes in membership at runtime.
### Running marge-bot in Swarm
Or you can run marge in Docker Swarm, e.g. here's how you use a compose file:
```yaml
Expand Down Expand Up @@ -364,46 +368,39 @@ run:
### Running marge-bot as a plain python app
#### Installing marge-bot with nix
Alternatively, if you prefer not to use docker, you can also directly run marge.
If you use [nix](https://nixos.org/nix/) do `nix-env --install -f default.nix`.
The nix install should be fully reproducible on any version of linux (and also
work on OS X, although this is not something we properly test). If you don't
want to use docker we recommend you give nix a try.
#### Installing marge-bot the old-fashioned way
Finally, although this is our least preferred alternative, you can always do
`python3 setup.py install` (note that you will need python3.6).
Install all dependencies with `poetry install` (note that you will need Python 3.6+).
Afterwards, the minimal way to run marge is as follows.
```bash
marge.app --auth-token-file marge-bot.token \
--gitlab-url 'http://your.gitlab.instance.com' \
--ssh-key-file marge-bot-ssh-key
poetry run marge --auth-token-file marge-bot.token \
--gitlab-url 'http://your.gitlab.instance.com' \
--ssh-key-file marge-bot-ssh-key
```
However, we suggest you use a systemd unit file or some other mechanism to
automatically restart marge-bot in case of intermittent GitLab problems.
### Setting up a development environment
## Setting up a development environment
Install `nix` by following https://nix.dev/tutorials/install-nix:
1. Install `poetry` with `pip install poetry`.
2. Check out this repository.
3. Run `poetry install` in the repository root.
### Running linting and tests
```shell
$ sh <(curl -L https://nixos.org/nix/install) --daemon
poetry run pytest
```
After that, a Docker image can be built with:
### Run marge-bot
```shell
$ make dockerize
poetry run marge
```
## Suggested workflow
1. Alice creates a new merge request and assigns Bob and Charlie as reviewers
2. Both review the code and after all issues they raise are resolved by Alice,
Expand All @@ -416,7 +413,6 @@ $ make dockerize
the merge request via the GitLab API. It can also add some headers to all
commits in the merge request as described in the next section.
## Adding Reviewed-by:, Tested: and Part-of: to commit messages
Marge-bot supports automated addition of the following
Expand Down Expand Up @@ -456,6 +452,7 @@ commits introduced by a single Merge Request when using a fast-forward/rebase
based merge workflow.
## Impersonating approvers
If you want a full audit trail, you will configure GitLab
[require approvals](https://docs.gitlab.com/ee/user/project/merge_requests/merge_request_approvals.html#approvals-required)
for PRs and also turn on
Expand All @@ -478,7 +475,6 @@ More than one embargo period can be specified, separated by commas. Any merge
request assigned to her during an embargo period, will be merged in only once all
embargoes are over.
## Batching Merge Requests
The flag `--batch` enables testing and merging merge requests in batches. This can
Expand Down Expand Up @@ -600,7 +596,6 @@ This reverts commit 0af5b70a98858c9509c895da2a673ebdb31e20b1.
E.g. `git revert-mr 123`.
## Troubleshooting
Marge-bot continuously logs what she is doing, so this is a good place to look
Expand Down
6 changes: 0 additions & 6 deletions default.nix

This file was deleted.

40 changes: 0 additions & 40 deletions dockerize.nix

This file was deleted.

12 changes: 0 additions & 12 deletions marge.app

This file was deleted.

40 changes: 0 additions & 40 deletions marge.nix

This file was deleted.

19 changes: 19 additions & 0 deletions marge/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from marge.app import main


def run():
try:
main()
except Exception as err:
print('Exception occured')
if hasattr(err, 'stdout'):
# pylint: disable=no-member
print(f'stdout was: {err.stdout}')
if hasattr(err, 'stderr'):
# pylint: disable=no-member
print(f'stderr was: {err.stderr}')
raise


if __name__ == '__main__':
run()
25 changes: 0 additions & 25 deletions nix/sources.json

This file was deleted.

Loading

0 comments on commit 3ba2516

Please sign in to comment.