Skip to content

Commit

Permalink
Improve deployment (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
ry authored Feb 21, 2019
1 parent befbf88 commit 2eb4d61
Show file tree
Hide file tree
Showing 13 changed files with 358 additions and 68 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
packaged.yaml
.idea
.aws-sam
src/node_modules/

23 changes: 11 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
language: python
cache: pip
env:
global:
- AWS_DEFAULT_REGION=us-east-1
- AWS_ACCESS_KEY_ID=AKIAJR55YEUPEHS4YU2Q
- secure: "RUXi4zQJoJkSVBQ6Qdamh2ajFITnIiq7V9DXetJwuVDtXRArHSIdAcXV8pGxqGWhXxkgmBt4qrEPRAx4vOCspUnQ2iny+drhnoJUE4qmQj/VHfrgHVVdzQOZxB8jp5TuOQSSi1RTCGt6L2VnEvGfUSYTYeNPUNsN+HUDmjL8i6yi9lidYdpzWypg+Tm26bLoyg/blI6/SXw3HfVBsipDdh6hQ5D3DhRDV7xpDlHSm0lgwUJg4F8hR788zN/TG5gEDzthsXHFRqeRhfIultMm8C1R24UbrxtjiV5Y6rdKQn0e022IUQeLuKi5AdSS1SX5cRxL/rttSzkZPQMMkVPfvXo7ABvhfB3oCSFhryNKM5/WxRBXOErBXA1WJ9vOX5Q7LgPLb8Alfr+mJtrKor7kuyq+2/HU5sMfPHHn86A3hQ7Lqy7qr4OXyBTGG8BD8TUkAIs4VQyosL0k8eK+eHtqDAOvKg1j3gqUORTtpz6m2N4gTGvD5fn6OeZpfRnRyRzXyAqp1bTxmBXbVXse5dYKzsefce+NzQCI8YyB5yYO+Utt0MB5zolblt1DgLehthIWkSlEGhQDwxstfD4wgk2D1Q/vtC2xBHUIkQ++c+iHxOoHI5rf8WP1kgPCTEnuxdna2zYQf15uzWz4zK7q/a2GEl0ILIYIAN264qe/hNkfMY4="
before_install:
- pip install awscli
jobs:
include:
- name: test
script:
- "./test.sh"
- name: deploy
script: "./deploy.sh"
if: branch = master
- AWS_ACCESS_KEY_ID=AKIAJU3VDX3UWND273VA
- secure: "Rl/2TQP6Ty5+nldT+PKBhNEvPee9wLlVknCVwMS9SHAjPsqfp7ubNmybamF8+dAKoTWuNAsNd3BY8o0tn+V+iH6FXC1aY0xh4N/AJ3IU09XeCIYPDGd3/sQcVr08B2grc3nAnGO7UHVQBR0fhEh6tsgeSF6P2IogE/8IJW51jolLnJLukCTL7VW3cTtBaAPWzo9Tjq6eNh+5jao+Zf7NZwB3hXpdggomDMo6vYyd0GENpIYSphc2qBof3z9L7maSRj6lByS9dTTnar/IYRWuMAbx87uiPoLsD8IF1n/l7Z/En1wiVHJy65uOJ/WDbeQHoUzjvpH/LQD1hiPFyfmXw9i0w4dtiWcbTJZJhuf2DnCVxViWZlD1sQYqrhkj/LER6SOLZIgqC5RbhX68qVCCDC//k8LBm4nHjKDtMGVVje2c8vYNjDkNL9wXXIGHnyZlvdWfJD+WZrfr776Dmn1s5Rwi2ttqSkbN2Sgef1nSMxCoYczwyQFBsRg/jZ2E5zysFNNP8sd7Xk4U+27k5VQD3JEGpyUcbg23qxkoQDG23EjS3XVuvOxsodBFg3vg+rqI73cMPCf+O/HWs7llPuc1kuplIJRg3XwbPN4JsoAaSddOZOsNaIIGe+/+tbfZqQFp0p13HfxoLA/Ri6J+KlEkrhxdTRGSa/ADMQWdVz+sTVA="
install:
- (cd src && npm install)
script: "./test.sh"
deploy:
provider: script
script: "./deploy.sh"
on:
branch: master
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Deno Module Registry

[![Build Status](https://travis-ci.com/denoland/registry.svg?branch=master)](https://travis-ci.com/denoland/registry)

This is the webserver and database for the https://deno.land/x/ service.

This service allows people to create pretty URLs which redirect to github (or
Expand Down
26 changes: 21 additions & 5 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

set -ev

bash test.sh
#./test.sh

# If travis doesn't have awscli, install it.
if [[ ! `aws --version` ]]; then
pip install awscli aws-sam-cli -q
fi

print_errors() {
aws cloudformation describe-stack-events --stack-name denoland1 \
Expand All @@ -14,15 +19,26 @@ aws cloudformation validate-template --template-body "`cat template.yaml`"

aws cloudformation package \
--template-file template.yaml \
--output-template-file packaged.yaml \
--s3-bucket deno.land \
--s3-prefix cloudformation_package \
--output-template-file packaged.yaml
--s3-prefix cloudformation_package

aws cloudformation wait stack-update-complete || true

aws cloudformation deploy \
--template-file packaged.yaml \
--stack-name denoland1 \
--tags stack=denoland1 \
--capabilities CAPABILITY_IAM || print_errors
--capabilities CAPABILITY_IAM \
|| print_errors

aws cloudfront create-invalidation --distribution-id E2HNK8Z3X3JDVG --paths "/*"

# aws cloudformation delete-stack --stack-name denoland1
# aws cloudformation cancel-update-stack --stack-name denoland1

#sam build
#sam package --s3-bucket deno.land --output-template-file packaged.yaml

#sam deploy --stack-name denoland1 --template-file packaged.yaml \
# || print_errors
#sam publish -t packaged.yaml --region us-east-1
80 changes: 78 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,48 @@
const DATABASE = require("./database.json");
const homepageHTML = require("./homepage");
const { assert } = console;
const fetch = require("node-fetch");

async function serveDir(u) {
return {
status: "200",
body: "Directories not yet supported.",
headers: {
"Content-Type": [
{
key: "Content-Type",
value: "text/plain"
}
]
}
};
}

async function fetchRemote(u) {
// console.log("fetchRemote", u);

if (u.endsWith("/") || u.endsWith("/index.html")) {
return serveDir(u);
}

const res = await fetch(u);
// console.log("res", res);
const body = await res.text();
// console.log("body", body);

return {
status: "200",
body,
headers: {
"Content-Type": [
{
key: "Content-Type",
value: "text/plain"
}
]
}
};
}

const notFound = {
status: "404",
Expand All @@ -17,6 +59,9 @@ const notFound = {
};

function proxy(pathname) {
if (pathname.startsWith("/core") || pathname.startsWith("/std")) {
return proxy("/x" + pathname);
}
if (!pathname.startsWith("/x/")) {
return null;
}
Expand Down Expand Up @@ -58,8 +103,36 @@ function indexPage() {
}
exports.indexPage = indexPage;

exports.lambdaHandler = (event, context, callback) => {
// console.log("Received event:", JSON.stringify(event, null, 2));
const sourceHtmlPrefix = /* HTML */ `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.14.2/build/styles/default.min.css"
/>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.14.2/build/styles/github-gist.min.css"
/>
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.14.2/build/highlight.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.14.2/build/languages/typescript.min.js"></script>
<link rel="stylesheet" href="https://deno.land/style.css" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
</head>
<body>
<main><pre></pre></main>
</body>
</html>
`;

exports.lambdaHandler = async (event, context, callback) => {
context.callbackWaitsForEmtpyEventLoop = false;
// console.log("event:", JSON.stringify(event, null, 2));
// console.log("context:", JSON.stringify(context, null, 2));
const { request } = event.Records[0].cf;

const olduri = request.uri;
Expand All @@ -82,6 +155,9 @@ exports.lambdaHandler = (event, context, callback) => {
return callback(null, request);
}

//const response = await fetchRemote(l);
//callback(null, response);

console.log("redirect", pathname, l);
const response = {
status: "302",
Expand Down
11 changes: 11 additions & 0 deletions src/context1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"callbackWaitsForEmptyEventLoop": true,
"logGroupName": "/aws/lambda/us-east-1.denoland1-DenoLandFunction-WHRRTS0VA8SI",
"logStreamName": "2019/02/20/[34]e529251a14f64b419d3bdfd54fe313b5",
"functionName": "us-east-1.denoland1-DenoLandFunction-WHRRTS0VA8SI",
"memoryLimitInMB": "128",
"functionVersion": "34",
"invokeid": "30ce2738-f61f-400a-99c2-e1cca090d0c7",
"awsRequestId": "30ce2738-f61f-400a-99c2-e1cca090d0c7",
"invokedFunctionArn": "arn:aws:lambda:us-east-1:996721126982:function:us-east-1.denoland1-DenoLandFunction-WHRRTS0VA8SI:34"
}
31 changes: 23 additions & 8 deletions src/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const homepageHTML = /* HTML */ `
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Deno modules</title>
<title>Deno Modules</title>
<link
rel="stylesheet"
Expand All @@ -21,37 +21,52 @@ const homepageHTML = /* HTML */ `
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.14.2/build/highlight.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.14.2/build/languages/typescript.min.js"></script>
<link rel="stylesheet" href="/style.css" />
<link rel="stylesheet" href="https://deno.land/style.css" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
</head>
<body>
<main>
<img src="${LOGO_PATH}" width="150px" />
<h1>Deno Modules</h1>
<p>This is a URL redirection service for Deno scripts.</p>
<p>
The basic format is
<code>https://deno.land/x/MODULE_NAME@BRANCH/SCRIPT.ts</code>. If you
leave out the branch, it will default to master.
</p>
<h2>Standard</h2>
<ul class="modules">
<li>
<code>https://deno.land/std/</code>
<a href="https://github.com/denoland/deno_std">repo</a>
</li>
<li>
<code>https://deno.land/core/</code>
<a href="https://github.com/denoland/deno">repo</a>
</li>
</ul>
<h2 id="modules"><a href="#modules">#</a>Modules</h2>
<h2 id="modules">Third Party</h2>
<ul class="modules">
${
Object.entries(DATABASE)
.sort(([nameA], [nameB]) => nameA.localeCompare(nameB))
.map(
([name, { repo }]) =>
`<li><code>https://deno.land/x/<b>${name}</b>/</code> — <a href="${repo}">Repo</a></li>`
)
.map(([name, { repo }]) => {
const link = `https://deno.land/x/${name}/`;
return `<li><a href=${link}>${link}</a> — <a href="${repo}">Repo</a></li>`;
})
.join("\n")
}
</ul>
<br />
<h2 id="contributing"><a href="#contributing">#</a>Contributing</h2>
<h2 id="contributing">Contributing</h2>
<p>
To add a module send a pull request to
Expand Down
13 changes: 13 additions & 0 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"name": "denoland",
"main": "app.js",
"version": "0.0.0"
"version": "0.0.0",
"dependencies": {
"node-fetch": "^2.3.0"
}
}
71 changes: 71 additions & 0 deletions src/req3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"Records": [
{
"cf": {
"config": {
"distributionDomainName": "dv4g3y42wun47.cloudfront.net",
"distributionId": "E2HLQND4HVTX7O",
"eventType": "origin-request"
},
"request": {
"clientIp": "68.173.125.147",
"headers": {
"user-agent": [
{
"key": "User-Agent",
"value": "Amazon CloudFront"
}
],
"via": [
{
"key": "Via",
"value": "1.1 836d15812518886911b1ae2be813f462.cloudfront.net (CloudFront)"
}
],
"x-forwarded-for": [
{
"key": "X-Forwarded-For",
"value": "68.173.125.147"
}
],
"accept-encoding": [
{
"key": "Accept-Encoding",
"value": "gzip"
}
],
"upgrade-insecure-requests": [
{
"key": "Upgrade-Insecure-Requests",
"value": "1"
}
],
"host": [
{
"key": "Host",
"value": "deno.land.s3.amazonaws.com"
}
],
"cache-control": [
{
"key": "Cache-Control",
"value": "max-age=0"
}
]
},
"method": "GET",
"origin": {
"s3": {
"authMethod": "none",
"customHeaders": {},
"domainName": "deno.land.s3.amazonaws.com",
"path": ""
}
},
"querystring": "",
"uri": "/std@v0.2.10/http/server.ts"
}
}
}
]
}
Loading

0 comments on commit 2eb4d61

Please sign in to comment.