Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump nixpkgs and python devs, improve out nix build #179

Merged
merged 7 commits into from
May 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* 0.8.2:
- Fix: bump all dependencies (getting rid of vulnerable packages)
* 0.8.1
- Feature: allow merging in order of last-update time #149
* 0.8.0
Expand Down
37 changes: 23 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
VERSION?=$$(git rev-parse --abbrev-ref HEAD)

requirements_frozen.txt requirements.nix requirements_override.nix: requirements.txt
pypi2nix -V 3.6 -r $^

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

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

.PHONY: clean
clean:
rm -rf .cache result requirements_frozen.txt

.PHONY: bump
bump: bump-requirements bump-sources

.PHONY: bump-sources
bump-sources:
nix-shell --run niv update

.PHONY: bump-requirements
bump-requirements: clean requirements_frozen.txt

.PHONY: dockerize
dockerize: dockerize.nix
docker load --input $$(nix-build dockerize.nix)
requirements_frozen.txt requirements.nix requirements_override.nix: requirements.txt
pypi2nix -V 3.6 -r $^

.PHONY: dockerize
dockerize:
docker load --input $$(nix-build --attr docker-image default.nix)

.PHONY: docker-push
docker-push:
if [ -n "$$DOCKER_USERNAME" -a -n "$$DOCKER_PASSWORD" ]; then \
docker login -u "$${DOCKER_USERNAME}" -p "$${DOCKER_PASSWORD}"; \
docker login -u "$${DOCKER_USERNAME}" -p "$${DOCKER_PASSWORD}"; \
else \
docker login; \
docker login; \
fi
docker tag smarkets/marge-bot:$$(cat version) smarkets/marge-bot:$(VERSION)
if [ "$(VERSION)" = "$$(cat version)" ]; then \
docker tag smarkets/marge-bot:$$(cat version) smarkets/marge-bot:latest; \
docker tag smarkets/marge-bot:$$(cat version) smarkets/marge-bot:stable; \
docker push smarkets/marge-bot:stable; \
docker push smarkets/marge-bot:latest; \
docker tag smarkets/marge-bot:$$(cat version) smarkets/marge-bot:latest; \
docker tag smarkets/marge-bot:$$(cat version) smarkets/marge-bot:stable; \
docker push smarkets/marge-bot:stable; \
docker push smarkets/marge-bot:latest; \
fi
docker push smarkets/marge-bot:$(VERSION)
# for backwards compatibility push to previous location
Expand Down
9 changes: 6 additions & 3 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
let pkgs = import ./pinnedNixpkgs.nix;
in
pkgs.callPackage ./marge.nix {}
let sources = import ./nix/sources.nix; in
with import sources.nixpkgs {};
{
marge-bot = callPackage ./marge.nix {};
docker-image = callPackage ./dockerize.nix {};
}
47 changes: 29 additions & 18 deletions dockerize.nix
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
{ pkgs ? import ./pinnedNixpkgs.nix }:
let callPackage = pkgs.lib.callPackageWith (pkgs);
marge = callPackage ./marge.nix {};
version = marge.version;
let
marge = pkgs.callPackage ./marge.nix {};
version = marge.version;
basicShadow =
# minimal user setup, so ssh won't whine 'No user exists for uid 0'
pkgs.runCommand "basic-shadow-setup" {}
''
mkdir -p $out
cd $out
${pkgs.dockerTools.shadowSetup}
mkdir -p root/.ssh
'';
in
pkgs.dockerTools.buildImage {
name = "smarkets/marge-bot";
tag = "${version}";
# minimal user setup, so ssh won't whine 'No user exists for uid 0'
runAsRoot = ''
#!${pkgs.stdenv.shell}
${pkgs.dockerTools.shadowSetup}
mkdir -p /root/.ssh
'';
contents = [marge pkgs.bash pkgs.coreutils pkgs.openssh pkgs.glibcLocales];
config = {
Entrypoint = [ "/bin/marge.app" ];
Env = ["LANG=en_US.UTF-8" ''LOCALE_ARCHIVE=/lib/locale/locale-archive''];
};
}
pkgs.dockerTools.buildImage {
name = "smarkets/marge-bot";
tag = "${version}";
contents =
with pkgs; [
basicShadow
bash
coreutils
git
glibcLocales
openssh
] ++ [ marge ];
config = {
Entrypoint = [ "/bin/marge.app" ];
Env = ["LANG=en_US.UTF-8" ''LOCALE_ARCHIVE=/lib/locale/locale-archive''];
};
}
58 changes: 38 additions & 20 deletions marge.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
{pkgs ? import ./pinnedNixpkgs.nix }:
let version = builtins.replaceStrings ["\n"] [""] (builtins.readFile ./version);
python = (import ./requirements.nix { inherit pkgs; });
py = python.packages;
{ pkgs
, lib
}:
let
python = import ./requirements.nix { inherit pkgs; };
version = lib.fileContents ./version;
in
python.mkDerivation {
version = "${version}";
name = "marge-${version}";
src = ./.;
buildInputs = [py.pytest py.pytest-cov py.pytest-flake8 py.pytest-pylint py.pytest-runner];
propagatedBuildInputs = [py.ConfigArgParse py.maya py.PyYAML py.requests pkgs.openssh pkgs.git];
meta = {
homepage = "https://github.com/smarkets/marge-bot";
description = "A build bot for GitLab";
license = with pkgs.lib.licenses; [bsd3] ;
maintainers = [
"Alexander Schmolck <[email protected]>"
"Jaime Lennox <[email protected]>"
python.mkDerivation {
version = "${version}";
name = "marge-${version}";
src = lib.sourceByRegex ./. [
"marge(/.*\.py)?"
"tests(/.*\.py)?"
"marge\.app"
"pylintrc"
"setup\.cfg"
"setup\.py"
"version"
];
platforms = pkgs.lib.platforms.linux ++ pkgs.lib.platforms.darwin;
};
}
checkInputs = with python.packages; [
pytest
pytest-cov
pytest-flake8
pytest-pylint
pytest-runner
];
propagatedBuildInputs = with python.packages; [
ConfigArgParse maya PyYAML requests
];
meta = {
homepage = "https://github.com/smarkets/marge-bot";
description = "A build bot for GitLab";
license = lib.licenses.bsd3;
maintainers = [
"Alexander Schmolck <[email protected]>"
"Jaime Lennox <[email protected]>"
];
platforms = pkgs.lib.platforms.linux ++ pkgs.lib.platforms.darwin;
};
}
2 changes: 1 addition & 1 deletion marge/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
MergeRequest = merge_request_module.MergeRequest


class Bot(object):
class Bot:
def __init__(self, *, api, config):
self._api = api
self._config = config
Expand Down
4 changes: 2 additions & 2 deletions marge/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import requests


class Api(object):
class Api:
def __init__(self, gitlab_url, auth_token):
self._auth_token = auth_token
self._api_base_url = gitlab_url.rstrip('/') + '/api/v4'
Expand Down Expand Up @@ -191,7 +191,7 @@ class UnexpectedError(ApiError):
pass


class Resource(object):
class Resource:
def __init__(self, api, info):
self._info = info
self._api = api
Expand Down
4 changes: 2 additions & 2 deletions marge/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def find_weekday(string_or_day):
raise ValueError('Not a week day: %r' % string_or_day)


class WeeklyInterval(object):
class WeeklyInterval:
def __init__(self, from_weekday, from_time, to_weekday, to_time):
from_weekday = find_weekday(from_weekday)
to_weekday = find_weekday(to_weekday)
Expand Down Expand Up @@ -111,7 +111,7 @@ def _interval_covers(self, date):
return True


class IntervalUnion(object):
class IntervalUnion:
def __init__(self, iterable):
self._intervals = list(iterable)

Expand Down
5 changes: 2 additions & 3 deletions marge/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .pipeline import Pipeline


class MergeJob(object):
class MergeJob:

def __init__(self, *, api, user, project, repo, options):
self._api = api
Expand Down Expand Up @@ -59,8 +59,7 @@ def ensure_mergeable_mr(self, merge_request):
if state not in ('opened', 'reopened', 'locked'):
if state in ('merged', 'closed'):
raise SkipMerge('The merge request is already {}!'.format(state))
else:
raise CannotMerge('The merge request is in an unknown state: {}'.format(state))
raise CannotMerge('The merge request is in an unknown state: {}'.format(state))

if self.during_merge_embargo():
raise SkipMerge('Merge embargo!')
Expand Down
1 change: 1 addition & 0 deletions marge/pylintrc
6 changes: 3 additions & 3 deletions marge/single_merge_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ def update_merge_request_and_accept(self, approvals):
raise CannotMerge(
'The request was marked as WIP as I was processing it (maybe a WIP commit?)'
)
elif merge_request.state == 'reopened':
if merge_request.state == 'reopened':
raise CannotMerge(
'GitLab refused to merge this branch. I suspect that a Push Rule or a git-hook '
'is rejecting my commits; maybe my email needs to be white-listed?'
)
elif merge_request.state == 'closed':
if merge_request.state == 'closed':
raise CannotMerge('Someone closed the merge request while I was attempting to merge it.')
elif merge_request.state == 'merged':
if merge_request.state == 'merged':
# We are not covering any observed behaviour here, but if at this
# point the request is merged, our job is done, so no need to complain
log.info('Merge request is already merged, someone was faster!')
Expand Down
2 changes: 1 addition & 1 deletion marge/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from . import git


class RepoManager(object):
class RepoManager:

def __init__(self, user, root_dir, ssh_key_file=None, timeout=None, reference=None):
self._root_dir = root_dir
Expand Down
25 changes: 25 additions & 0 deletions nix/sources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"nixpkgs": {
"url": "https://github.com/NixOS/nixpkgs-channels/archive/915ce0f1e1a75adec7079ddb6cd3ffba5036b3fc.tar.gz",
"owner": "NixOS",
"branch": "nixos-19.03",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz",
"repo": "nixpkgs-channels",
"type": "tarball",
"sha256": "1kmx29i3xy4701z4lgmv5xxslb1djahrjxmrf83ig1whb4vgk4wm",
"description": "Nixpkgs/NixOS branches that track the Nixpkgs/NixOS channels",
"rev": "915ce0f1e1a75adec7079ddb6cd3ffba5036b3fc"
},
"niv": {
"homepage": "https://github.com/nmattia/niv",
"url": "https://github.com/nmattia/niv/archive/e5e441998ede88dfce5b8b9a7ea99e1e0f1102fa.tar.gz",
"owner": "nmattia",
"branch": "master",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz",
"repo": "niv",
"type": "tarball",
"sha256": "0s3pwakbp9qmwzznl8xd3smmymz1s2vrvyip8yizqdllaps4pf18",
"description": "Easy dependency management for Nix projects",
"rev": "e5e441998ede88dfce5b8b9a7ea99e1e0f1102fa"
}
}
11 changes: 11 additions & 0 deletions nix/sources.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read in the json spec for packages we want (so it can be auto-updated).
# niv: no_update

# make travis happy, reasonably new nix doesn't need this
let mapAttrs = builtins.mapAttrs or
(f: set:
builtins.listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (builtins.attrNames set)));
in with builtins;
mapAttrs
(_: spec: spec // { outPath = fetchTarball { inherit (spec) url sha256; }; })
(fromJSON (readFile ./sources.json))
15 changes: 7 additions & 8 deletions pinnedNixpkgs.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
let
fetchFromGitHub = (import <nixpkgs> {}).fetchFromGitHub;
pkgs = import (fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs";
rev = "90afb0c10fe6f437fca498298747b2bcb6a77d39";
sha256 = "0mvzdw5aygi1vjnvm0bc8bp7iwb9rypiqg749m6a6km84m7srm0w";
}) {};
in pkgs
spec = builtins.fromJSON (builtins.readFile ./pinnedNixpkgs.src.json);
src = builtins.fetchTarball {
url = "https://github.com/${spec.owner}/${spec.repo}/archive/${spec.rev}.tar.gz";
sha256 = spec.sha256;
};
in
import src {}
6 changes: 6 additions & 0 deletions pinnedNixpkgs.src.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "1985e76c2ee8b0bfc144ff4a495d68bb432d9153",
"sha256": "0lvdd749idxkqb91damn504zd310d9hqxhph8mg874wpld5kv87n"
}
1 change: 1 addition & 0 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ disable=bad-continuation,
fixme,
missing-docstring,
no-self-use,
unsubscriptable-object

[SIMILARITIES]
min-similarity-lines=10
Expand Down
Loading