do some updates

This commit is contained in:
John Bintz 2020-04-10 07:29:40 -04:00
parent ddf624cdb7
commit 6dcfb1856a
11 changed files with 568 additions and 503 deletions

View File

@ -16,7 +16,7 @@ end
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Base on the Sandstorm snapshots of the official Debian 8 (jessie) box.
config.vm.box = "debian/contrib-stretch64"
config.vm.box_version = "9.3.0"
config.vm.box_version = ">= 0"
if Vagrant.has_plugin?("vagrant-vbguest") then
# vagrant-vbguest is a Vagrant plugin that upgrades

View File

@ -21,5 +21,5 @@ fi
cd /opt/app
cp post-receive /var/git/.git/hooks
caddy &
NODE_ENV=production HOME=/tmp npm start
npm start

File diff suppressed because it is too large Load Diff

View File

@ -17,11 +17,11 @@ const pkgdef :Spk.PackageDefinition = (
# This manifest is included in your app package to tell Sandstorm
# about your app.
appTitle = (defaultText = "Hugo"),
appTitle = (defaultText = "Hugo (new)"),
appVersion = 3, # Increment this for every release.
appVersion = 4, # Increment this for every release.
appMarketingVersion = (defaultText = "0.20.7-sandstorm3"),
appMarketingVersion = (defaultText = "0.68.3-sandstorm3"),
# Human-readable representation of appVersion. Should match the way you
# identify versions of your app in documentation and marketing.
@ -242,6 +242,9 @@ const myCommand :Spk.Manifest.Command = (
# Note that this defines the *entire* environment seen by your app.
(key = "PATH", value = "/usr/local/bin:/usr/bin:/bin"),
(key = "SANDSTORM", value = "1"),
(key = "HOME", value = "/var"),
(key = "NODE_ENV", value = "production"),
(key = "NODE_DEBUG", value = "fs"),
# Export SANDSTORM=1 into the environment, so that apps running within Sandstorm
# can detect if $SANDSTORM="1" at runtime, switching UI and/or backend to use
# the app's Sandstorm-specific integration code.

View File

@ -5,35 +5,44 @@
set -euo pipefail
export HUGO_VERSION=0.68.3
export NODE_VERSION=10
apt-get update
apt-get install -y git
apt-get install -y git strace
# First, get capnproto from master and install it to
# /usr/local/bin. This requires a C++ compiler. We opt for clang
# because that's what Sandstorm is typically compiled with.
# /usr/local/bin. This requires a C++ compiler. We opt for gcc-6
# because that's what capnproto now requires.
if [ ! -e /usr/local/bin/capnp ] ; then
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -q clang autoconf pkg-config libtool
cd /tmp
if [ ! -e capnproto ]; then git clone https://github.com/sandstorm-io/capnproto; fi
if [ ! -e capnproto ]; then git clone https://github.com/capnproto/capnproto; fi
cd capnproto
git checkout f73ac9f6667d7b87c395d23f3753dde63937cf00
#git checkout master
git checkout master
cd c++
make clean || true
autoreconf -i
./configure
make -j2
sudo make install
fi
rm /opt/app/sandstorm-integration/getPublicId || true
rm -Rf /opt/app/sandstorm-integration/tmp || true
# Second, compile the small C++ program within
# /opt/app/sandstorm-integration.
if [ ! -e /opt/app/sandstorm-integration/getPublicId ] ; then
pushd /opt/app/sandstorm-integration
make clean || true
make
fi
cp /opt/app/sandstorm-integration/bin/getPublicId /usr/local/bin
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
curl -sL https://deb.nodesource.com/setup_${NODE_VERSION}.x | sudo -E bash -
apt-get install -y nodejs
npm install -g yarn
@ -41,16 +50,6 @@ apt-get install -y python-pip asciidoctor
pip install pygments
cd /tmp
wget https://github.com/gohugoio/hugo/releases/download/v0.49.2/hugo_0.49.2_Linux-64bit.deb -O hugo.deb
wget https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_Linux-64bit.deb -O hugo.deb
dpkg -i hugo.deb
rm hugo.deb
# cd /tmp
# wget https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz -O go.tar.gz
# tar xfz go.tar.gz
# mv go /usr/local
# rm go.tar.gz
wget "https://caddyserver.com/download/build?os=linux&arch=amd64&features=filemanager%2Chugo" -O /tmp/caddy.tar.gz
cd /tmp
tar xfz caddy.tar.gz
mv caddy /usr/local/bin
rm caddy.tar.gz

View File

@ -1,4 +1,6 @@
127.0.0.1:8001
127.0.0.1:8001 {
root /var/git
}
errors stderr
log stdout
hugo /var/git {

View File

@ -44,8 +44,6 @@
<render-template
rpcId="gitPush"
:template="'git remote add origin ' + this.gitUrl + '\ngit push -fu origin master'"/>
<h2>Admin Interface</h2>
<p>Simple site changes can be made directly in the included <a href="/admin/">administrative interface</a>.</p>
</div>
</template>

View File

@ -48,7 +48,10 @@ namespace sandstorm {
request.setId(sessionId);
auto session = request.send().getContext().castAs<HackSessionContext>();
kj::Promise<void> promise = session.getPublicIdRequest().send().then([](auto result) {
kj::Promise<void> promise = session
.getPublicIdRequest()
.send()
.then([](capnp::Response<sandstorm::HackSessionContext::GetPublicIdResults>&& result) {
auto publicId = result.getPublicId();
auto hostname = result.getHostname();
auto autoUrl = result.getAutoUrl();
@ -73,3 +76,4 @@ namespace sandstorm {
} // namespace sandstorm
KJ_MAIN(sandstorm::GetPublicIdMain)

View File

@ -0,0 +1,75 @@
// Sandstorm - Personal Cloud Sandbox
// Copyright (c) 2014 Sandstorm Development Group, Inc. and contributors
//
// Hack around stdlib bug with C++14.
#include <initializer_list> // force libstdc++ to include its config
#undef _GLIBCXX_HAVE_GETS // correct broken config
// End hack.
#include <kj/main.h>
#include <kj/debug.h>
#include <kj/async-io.h>
#include <kj/async-unix.h>
#include <kj/io.h>
#include <capnp/rpc-twoparty.h>
#include <capnp/rpc.capnp.h>
#include <capnp/ez-rpc.h>
#include <sandstorm/sandstorm-http-bridge.capnp.h>
#include <unistd.h>
#include <sandstorm/hack-session.capnp.h>
namespace sandstorm {
class GetPublicIdMain {
public:
GetPublicIdMain(kj::ProcessContext& context): context(context) { }
kj::MainFunc getMain() {
return kj::MainBuilder(context, "GetPublicId version: 0.0.2",
"Runs the getPublicId command from hack-session.capnp. "
"Outputs the return arguments as separate lines on stdout.")
.expectArg("<sessionId>", KJ_BIND_METHOD(*this, setSessionId))
.callAfterParsing(KJ_BIND_METHOD(*this, run))
.build();
}
kj::MainBuilder::Validity setSessionId(kj::StringPtr id) {
sessionId = kj::heapString(id);
return true;
}
kj::MainBuilder::Validity run() {
capnp::EzRpcClient client("unix:/tmp/sandstorm-api");
SandstormHttpBridge::Client restorer = client.getMain<SandstormHttpBridge>();
auto request = restorer.getSessionContextRequest();
request.setId(sessionId);
auto session = request.send().getContext().castAs<HackSessionContext>();
kj::Promise<void> promise = session.getPublicIdRequest().send().then([](auto result) {
auto publicId = result.getPublicId();
auto hostname = result.getHostname();
auto autoUrl = result.getAutoUrl();
auto isDemoUser = result.getIsDemoUser();
kj::String msg = kj::str(publicId, "\n", hostname, "\n", autoUrl, "\n",
isDemoUser ? "true" : "false", "\n");
kj::FdOutputStream(STDOUT_FILENO).write(msg.begin(), msg.size());
}, [] (auto e) {
auto desc = e.getDescription();
kj::FdOutputStream(STDOUT_FILENO).write(desc.begin(), desc.size());
});
promise.wait(client.getWaitScope());
return true;
}
private:
kj::ProcessContext& context;
kj::String sessionId;
};
} // namespace sandstorm
KJ_MAIN(sandstorm::GetPublicIdMain)

View File

@ -0,0 +1,83 @@
// Sandstorm - Personal Cloud Sandbox
// Copyright (c) 2014 Sandstorm Development Group, Inc. and contributors
//
// Hack around stdlib bug with C++14.
#include <initializer_list> // force libstdc++ to include its config
#undef _GLIBCXX_HAVE_GETS // correct broken config
// End hack.
#include <kj/main.h>
#include <kj/debug.h>
#include <kj/async-io.h>
#include <kj/async-unix.h>
#include <kj/io.h>
#include <capnp/rpc-twoparty.h>
#include <capnp/rpc.capnp.h>
#include <capnp/ez-rpc.h>
#include <sandstorm/sandstorm-http-bridge.capnp.h>
#include <unistd.h>
#include <sandstorm/hack-session.capnp.h>
namespace sandstorm {
class GetPublicIdMain {
public:
GetPublicIdMain(kj::ProcessContext& context): context(context) { }
kj::MainFunc getMain() {
return kj::MainBuilder(context, "GetPublicId version: 0.0.2",
"Runs the getPublicId command from hack-session.capnp. "
"Returns the ID and the host name as two lines on stdout.")
.expectArg("<sessionId>", KJ_BIND_METHOD(*this, setSessionId))
.callAfterParsing(KJ_BIND_METHOD(*this, run))
.build();
}
kj::MainBuilder::Validity setSessionId(kj::StringPtr id) {
sessionId = kj::heapString(id);
return true;
}
kj::MainBuilder::Validity run() {
capnp::EzRpcClient client("unix:/tmp/sandstorm-api");
SandstormHttpBridge::Client restorer = client.getMain<SandstormHttpBridge>();
auto request = restorer.getSessionContextRequest();
request.setId(sessionId);
auto session = request.send().getContext().castAs<HackSessionContext>();
kj::Promise<void> promise = session.getPublicIdRequest().send().then(
[](HackSessionContext::GetPublicIdResults::Reader result) {
auto publicId = result.getPublicId();
auto hostname = result.getHostname();
auto autoUrl = result.getAutoUrl();
kj::String msg =
kj::str(
"Your content has automatically been published at\n",
" ", autoUrl, "\n",
"You can show this content on a custom domain by adding the following\n"
"DNS records:\n"
" <host> IN CNAME ", hostname, "\n"
" sandstorm-www.<host> IN TXT ", publicId, "\n");
kj::FdOutputStream(STDOUT_FILENO).write(msg.begin(), msg.size());
}, [] (kj::Exception&& e) {
auto desc = e.getDescription();
kj::FdOutputStream(STDOUT_FILENO).write(desc.begin(), desc.size());
});
promise.wait(client.getWaitScope());
return true;
}
private:
kj::ProcessContext& context;
kj::String sessionId;
};
} // namespace sandstorm
KJ_MAIN(sandstorm::GetPublicIdMain)

View File

@ -1,9 +1,11 @@
import Nuxt from "nuxt"
import logger from "morgan"
import fs from 'fs'
const exec = require("child_process").exec
const execFile = require("child_process").execFile
import Express from "express"
import gitBackend from "git-http-backend"
import httpProxy from "http-proxy"
//import httpProxy from "http-proxy"
const spawn = require("child_process").spawn
const app = new Express()
@ -17,17 +19,49 @@ app.set("port", port)
app.get("/publicId", (req, res) => {
const sessionId = req.headers["x-sandstorm-session-id"]
exec(`getPublicId ${sessionId}`, (err, rv) => {
if(err)
return res.end(err)
const lines = rv.split("\n")
let allData = ""
const file = `/var/publicid-${sessionId}`
const handleResult = () => {
const lines = allData.split("\n")
const publicId = lines[0]
const hostname = lines[1]
const domain = publicId+"."+hostname
const url = lines[2]
const isDemo = lines[3] == "true"
res.json({publicId, hostname, domain, url, isDemo})
})
}
try {
allData = fs.readFileSync(file, 'utf8').toString()
} catch (e) {
// nothing
}
const lines = allData.split("\n")
if (lines.length >= 4) {
handleResult()
} else {
const gpId = spawn('getPublicId', [sessionId])
allData = ""
gpId.stdout.on('data', (data) => {
fs.appendFileSync(file, data)
allData += data
})
gpId.on('error', (err) => {
return res.send(err)
})
gpId.on('close', (code) => {
if (code !== 0) {
return res.send(code)
}
handleResult()
})
}
})
app.use("/git", (req, res) => {
@ -41,12 +75,12 @@ app.use("/git", (req, res) => {
})).pipe(res)
})
const proxy = httpProxy.createProxyServer({
target: "http://127.0.0.1:8001/admin/",
changeOrigin: true
})
//const proxy = httpProxy.createProxyServer({
// target: "http://127.0.0.1:8001/admin/",
// changeOrigin: true
//})
app.use("/admin/", (req, res) => proxy.web(req, res))
// app.use("/admin/", (req, res) => proxy.web(req, res))
// Import and Set Nuxt.js options
let config = require("./nuxt.config.js")
@ -60,6 +94,7 @@ app.use(nuxt.render)
if (config.dev) {
nuxt.build()
.catch((error) => {
console.log('whoa')
console.error(error) // eslint-disable-line no-console
process.exit(1)
})