Skip to content

Commit

Permalink
Add deploy on heroku badge
Browse files Browse the repository at this point in the history
  • Loading branch information
wilzbach committed Jul 19, 2017
1 parent 64ed9f8 commit e9125e3
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 19 deletions.
1 change: 1 addition & 0 deletions .d-compiler
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ldc-1.3.0
3 changes: 3 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
default_process_types:
web: ./dub-registry --port $PORT --mirror=https://code.dlang.org --hostname=dub-registry.heroku.com --separate-cron --vv --bind 0.0.0.0
cron: ./dub-registry --mirror=https://code.dlang.org --run-cron --vv
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ DUB registry
![vibe.d logo](public/images/logo-small.png) Online registry for [dub](https://github.com/dlang/dub/) packages, see <http://code.dlang.org/>.

[![Build Status](https://travis-ci.org/dlang/dub-registry.svg)](https://travis-ci.org/dlang/dub-registry)

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/dlang/dub-registry)
23 changes: 23 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "DUB registry (mirror)",
"description": "A mirror of code.dlang.org",
"repository": "https://github.com/dub/dub-registry",
"website": "https://github.com/dub/dub-registry",
"logo": "https://dlang.org/images/dlogo_opengraph.png",
"keywords": ["d", "dlang", "dub", "mirror"],
"buildpacks": [
{
"url": "http://github.com/MartinNowak/heroku-buildpack-d.git"
}
],
"addons": [
{
"plan": "mongolab:sandbox",
"as": "MONGO"
},
{
"plan": "scheduler:standard",
"as": "SCHEDULER"
}
]
}
5 changes: 2 additions & 3 deletions dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ homepage "http://code.dlang.org/"
authors "Sönke Ludwig" "Matthias Dondorff"
license "GPL-3.0"

dependency "vibe-d" version="~>0.8.0-beta"
dependency "dub" version="~>1.3.0-beta"
dependency "vibe-d" version="~>0.8.0"
dependency "dub" version="~>1.3.0"
dependency "userman" version="~>0.3.2"
subConfiguration "dub" "library-nonet"

Expand All @@ -14,7 +14,6 @@ versions "VibeJsonFieldNames"
configuration "application" {
targetType "executable"
mainSourceFile "source/app.d"
versions "VibeDefaultMain"
}

configuration "library" {
Expand Down
39 changes: 30 additions & 9 deletions source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,52 @@ DubRegistry s_registry;
DubRegistryWebFrontend s_web;
string s_mirror;

void checkForNewVersions()
{
if (s_mirror.length) s_registry.mirrorRegistry(URL(s_mirror));
else s_registry.checkForNewVersions();
}

void startMonitoring()
{
void monitorNewVersions()
{
sleep(10.seconds()); // give the cache a chance to warm up first
while(true){
if (s_mirror.length) s_registry.mirrorRegistry(URL(s_mirror));
else s_registry.checkForNewVersions();
checkForNewVersions;
sleep(30.minutes());
}
}
s_checkTask = runTask(&monitorNewVersions);
}

version (linux) private immutable string certPath;

shared static this()
{
enum debianCA = "/etc/ssl/certs/ca-certificates.crt";
enum redhatCA = "/etc/pki/tls/certs/ca-bundle.crt";
immutable certPath = redhatCA.exists ? redhatCA : debianCA;
}

void main()
{
setLogFile("log.txt", LogLevel.diagnostic);

string hostname = "code.dlang.org";
bool separateCron;
bool runCron;

readOption("mirror", &s_mirror, "URL of a package registry that this instance should mirror (WARNING: will overwrite local database!)");
readOption("hostname", &hostname, "Domain name of this instance (default: code.dlang.org)");
readOption("separate-cron", &separateCron, "Use a separate cron job to query for packages.");
readOption("run-cron", &runCron, "Run cron operation.");

// validate provided mirror URL
if (s_mirror.length)
validateMirrorURL(s_mirror);

version (linux) {
logInfo("Enforcing certificate trust.");
enum debianCA = "/etc/ssl/certs/ca-certificates.crt";
enum redhatCA = "/etc/pki/tls/certs/ca-bundle.crt";
certPath = redhatCA.exists ? redhatCA : debianCA;

HTTPClient.setTLSSetupCallback((ctx) {
ctx.useTrustedCertificateFile(certPath);
ctx.peerValidationMode = TLSPeerValidationMode.trustedCert;
Expand All @@ -80,12 +91,20 @@ shared static this()

auto router = new URLRouter;
if (s_mirror.length) router.any("*", (req, res) { req.params["mirror"] = s_mirror; });
router.get("*", (req, res) @trusted { if (!s_checkTask.running) startMonitoring(); });
if (!separateCron)
router.get("*", (req, res) @trusted { if (!s_checkTask.running) startMonitoring(); });

// VPM registry
import dubregistry.mongodb : databaseName;
auto regsettings = new DubRegistrySettings;
regsettings.databaseName = databaseName;
s_registry = new DubRegistry(regsettings);

if (runCron) {
checkForNewVersions;
return;
}

UserManController userdb;

if (!s_mirror.length) {
Expand Down Expand Up @@ -115,5 +134,7 @@ shared static this()
listenHTTP(settings, router);

// poll github for new project versions
startMonitoring();
if (!separateCron)
startMonitoring();
runApplication();
}
5 changes: 3 additions & 2 deletions source/dubregistry/cache.d
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class URLCache {

this()
{
m_db = connectMongoDB("127.0.0.1");
import dubregistry.mongodb : getMongoClient;
m_db = getMongoClient();
m_entries = m_db.getCollection("urlcache.entries");
m_entries.ensureIndex([tuple("url", 1)]);
}
Expand Down Expand Up @@ -70,7 +71,7 @@ class URLCache {
// invalidate out of date cache entries
if (be["_id"].get!BsonObjectID.timeStamp < now - m_maxCacheTime)
m_entries.remove(["_id": be["_id"]]);

deserializeBson(entry, be);
if (mode == CacheMatchMode.always) {
// directly return cache result for cache_priority == true
Expand Down
3 changes: 2 additions & 1 deletion source/dubregistry/dbcontroller.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class DbController {

this(string dbname)
{
auto db = connectMongoDB("127.0.0.1").getDatabase(dbname);
import dubregistry.mongodb : getMongoClient;
auto db = getMongoClient.getDatabase(dbname);
m_packages = db["packages"];
m_downloads = db["downloads"];

Expand Down
24 changes: 24 additions & 0 deletions source/dubregistry/mongodb.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module dubregistry.mongodb;

import vibe.db.mongo.client : MongoClient;
import vibe.db.mongo.mongo : connectMongoDB;
import vibe.db.mongo.settings : MongoClientSettings, MongoAuthMechanism, parseMongoDBUrl;

MongoClientSettings mongoSettings;
string databaseName = "vpmreg";

shared static this()
{
import std.process : environment;
auto mongodbURI = environment.get("MONGODB_URI", "mongodb://127.0.0.1");
parseMongoDBUrl(mongoSettings, mongodbURI);
mongoSettings.authMechanism = MongoAuthMechanism.scramSHA1;
if (mongoSettings.database.length != 0)
databaseName = mongoSettings.database;
mongoSettings.safe = true;
}

MongoClient getMongoClient()
{
return connectMongoDB(mongoSettings);
}
11 changes: 7 additions & 4 deletions source/dubregistry/notificationcenter.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import userman.db.controller;
import vibe.core.log;
import vibe.mail.smtp;
import vibe.stream.memory;
import vibe.templ.diet;
import vibe.stream.wrapper : StreamOutputRange;
import diet.html : compileHTMLDietFile;


class NotificationCenter {
Expand Down Expand Up @@ -52,7 +53,8 @@ class NotificationCenter {
mail.headers["Subject"] = format("[%s] Errors in new version %s", package_name, branch_or_version);

auto dst = createMemoryOutputStream();
dst.compileDietFile!("dubregistry.mail.package-version-errors.dt", user, settings, package_name, branch_or_version, errors);
auto output = StreamOutputRange(dst);
output.compileHTMLDietFile!("dubregistry.mail.package-version-errors.dt", user, settings, package_name, branch_or_version, errors);
mail.bodyText = cast(string)dst.data;

sendMail(settings.mailSettings, mail);
Expand Down Expand Up @@ -85,10 +87,11 @@ class NotificationCenter {
mail.headers["Subject"] = format("Weekly deprecation warnings reminder");

auto dst = createMemoryOutputStream();
dst.compileDietFile!("dubregistry.mail.package-deprecation-warnings.dt", user, settings, deprecations);
auto output = StreamOutputRange(dst);
output.compileHTMLDietFile!("dubregistry.mail.package-deprecation-warnings.dt", user, settings, deprecations);
mail.bodyText = cast(string)dst.data;

sendMail(settings.mailSettings, mail);
//sendMail(settings.mailSettings, mail);
} catch (Exception e) {
logDiagnostic("Failed to send deprecation mail to %s <%s>: %s", user.fullName, user.email, e.msg);
logDebug("Full error: %s", e.toString().sanitize);
Expand Down
1 change: 1 addition & 0 deletions views/dubregistry.mail.package-version-errors.dt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ block title

block body
- import vibe.textfilter.urlencode;
- import std.algorithm.searching : startsWith;

p The following errors have been detected for the recently added/updated version <strong>#{branch_or_version}</strong> of package <strong>#{package_name}</strong>:

Expand Down

0 comments on commit e9125e3

Please sign in to comment.