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

huginn: init at 2016-09-14 #18590

Closed
wants to merge 1 commit into from
Closed

huginn: init at 2016-09-14 #18590

wants to merge 1 commit into from

Conversation

mogorman
Copy link
Contributor

Motivation for this change

This is a new package huginn, http://github.com/cantino/huginn , it is an agent platform. This is my first service module, as well as my first ruby package. I would appreciate people looking it over. this pr also depends on #18361 or it can't be built due to unicode ruby files in the dependencies. I would also like to backport this into 16.09 after master if someone could show me how.

Things done
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • [x ] NixOS
    • OS X
    • Linux
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@mention-bot
Copy link

@mogorman, thanks for your PR! By analyzing the annotation information on this pull request, we identified @edolstra, @joachifm and @offlinehacker to be potential reviewers

@mogorman
Copy link
Contributor Author

fixed merge conflict

@mogorman
Copy link
Contributor Author

bumped id number again to fix merge conflict

@joachifm
Copy link
Contributor

What's up with the need to add ~3,600 lines of code to the main repo for a single package and a service?

@mogorman
Copy link
Contributor Author

the majority of the bloat was just defining the config file completely so it can be easily configured by nix. it isn't really bloat is it?

@@ -0,0 +1,169 @@
Encoding.default_external = Encoding::UTF_8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file could be probably replaced by

source "https://rubygems.org"

gem 'huginn', git: "https://github.com/cantino/huginn.git", ref: '005be58d30181b1e0ca5b29cc9a8729ee0d7bcab'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, this will not work, because you apply patches.

preStart = ''
rm -rf ${cfg.statePath}/tmp
mkdir -p ${cfg.statePath}/log
mkdir -p ${cfg.statePath}/tmp/pids
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be replaced by a single mkdir:

mkdir -p ${cfg.statePath}/log  ${cfg.statePath}/tmp/{pids,cache,sockets}

mkdir -p ${cfg.statePath}/tmp/sockets

touch ${cfg.statePath}/tmp/secrets
if [ "${cfg.appSecretToken}" = "" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, can you fix the indentation?

${config.services.postgresql.package}/bin/createdb --owner ${cfg.databaseUser} ${cfg.databaseName} huginn || true
if [ "${cfg.databasePassword}" = "" ]; then
echo "creating db"
${huginn-rake}/bin/huginn-rake db:create RAILS_ENV=production APP_SECRET_TOKEN="null" DATABASE_PASSWORD=`cat ${cfg.statePath}/db-password`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rake accepts multiple tasks at once: ${huginn-rake}/bin/huginn-rake db:create db:migrate db:seed


in {

options = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, many options here. This could be split into a separate file probably

cp -r . $out/share/huginn
cp ${gemfile} $out/share/huginn/Gemfile
cp ${lockfile} $out/share/huginn/Gemfile.lock
#I dont know why these need to exist but what can i say
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you could also use a single mkdir


installPhase = ''
export LD_LIBRARY_PATH=${curl.out}/lib:${postgresql}/lib
RAILS_ENV=production APP_SECRET_TOKEN=REPLACE_ME_NOW! DATABASE_ADAPTER=nulldb HUGINN_STATE_PATH=tmp/ SKIP_STORAGE_VALIDATION=true bundle exec rake assets:precompile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be break into multiple lines using \ for readability.

ASSET_HOST=cfg.assetHost;
FORCE_SSL= (if cfg.forceSSL then "true" else "false");
INVITATION_CODE=cfg.registration.invitationCode;
SKIP_INVITATION_CODE=(if cfg.registration.skipInvitation then "true" else "false");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe replace by a helper function:

toBool = option : if option then "true" else "false";
...
SKIP_INVITATION_CODE=(toBool cfg.registration.skipInvitation);

echo "migrating db"
${huginn-rake}/bin/huginn-rake db:migrate RAILS_ENV=production APP_SECRET_TOKEN="null"
echo "seeding db"
${huginn-rake}/bin/huginn-rake db:seed RAILS_ENV=production APP_SECRET_TOKEN="null" SEED_USERNAME=${cfg.initialUser} SEED_PASSWORD=${cfg.initialPassword} SKIP_INVITATION_CODE=true REQUIRE_CONFIRMED_EMAIL=false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if you pass DATABASE_PASSWORD= to rake? If this works you could save the if expression.

if [ "${cfg.appSecretToken}" = "" ]; then
printf "APP_SECRET_TOKEN=" >> ${cfg.statePath}/tmp/secrets
tr -dc A-Za-z0-9 < /dev/urandom 2> /dev/null | head -c 32 >> ${cfg.statePath}/tmp/secrets
echo "" >> ${cfg.statePath}/tmp/secrets
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

printf 'APP_SECRET_TOKEN=%s\n' "$(tr -dc A-Za-z0-9 < /dev/urandom 2> /dev/null|head -c32)" > ${cfg.statePath}/tmp/secrets

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this could be also wrapped and reused in a shell function

gen_secret() {
  printf "$1=%s\n" "$(tr -dc A-Za-z0-9 < /dev/urandom 2> /dev/null|head -c32)" > "$2"
}

gen_secret "APP_SECRET_TOKEN" "${cfg.statePath}/tmp/secrets"

@ocharles
Copy link
Contributor

Hi @mogorman, what is the status of this pull request? It looks like @Mic92 has given you a thorough code review.

@bachp
Copy link
Member

bachp commented Aug 27, 2017

@mogorman I would also like to see this finished. Do you need any help?

@disassembler
Copy link
Member

Closing this out since there's been no response for over a year. @bachp and @ocharles please open a new PR for this if you're interested in working on this.

@CMCDragonkai
Copy link
Member

This would really be nice to have. Might work on it later if nobody picks this up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants