Skip to content

Commit

Permalink
initial code for docker+k8 setup (#6)
Browse files Browse the repository at this point in the history
initial code for docker+k8 setup
  • Loading branch information
danielborowski authored and i80and committed Nov 19, 2018
1 parent c97d9b1 commit 1e60c0e
Show file tree
Hide file tree
Showing 8 changed files with 329 additions and 36 deletions.
32 changes: 32 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
pipeline:
publish:
image: plugins/ecr
secrets: [ ecr_access_key, ecr_secret_key]
registry: 795250896452.dkr.ecr.us-east-1.amazonaws.com
repo: 795250896452.dkr.ecr.us-east-1.amazonaws.com/docs/${DRONE_REPO_NAME}
create_repository: true
tags:
- git-${DRONE_COMMIT_SHA:0:7}
- latest
when:
branch: master
event: push

deploy-staging:
image: quay.io/ipedrazas/drone-helm
release: snooty
namespace: docs
environment:
- API_SERVER=https://api.staging.mongodb.sh
prefix: STAGING
secrets: [ staging_kubernetes_token ]
helm_repos: mongodb=https://10gen-ops.github.io/helm-charts
chart: mongodb/web-app
chart_version: 3.1.0
tiller_ns: docs
client_only: true
values: "image.tag=git-${DRONE_COMMIT_SHA:0:7},image.repository=795250896452.dkr.ecr.us-east-1.amazonaws.com/docs/${DRONE_REPO_NAME},ingress.enabled=true,ingress.hosts[0]=snooty.docs.staging.mongodb.sh"
when:
branch: master
event: push
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ __pycache__/
.DS_Store
parser/snooty.py
*.dist/
node_modules/
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# this Dockerfile packages up this application and allows the front-end
# of the docs site to be built online and push changes to aws

# get nodejs
FROM node:10.10.0

COPY front-end/ .

# following instructions from front-end/README.md
RUN npm -g config set user root
RUN npm install
RUN npm -g install gatsby

# entry to expose route that kicks-off build
EXPOSE 8080
CMD ["npm", "start"]
2 changes: 0 additions & 2 deletions front-end/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ const path = require('path');
const fs = require('fs');
const crypto = require('crypto');
const uuidv1 = require('uuid/v1');
const contentful = require('contentful');
const mongoclient = require('mongodb').MongoClient;
const { Stitch, AnonymousCredential } = require('mongodb-stitch-server-sdk');

const LANGUAGES = [
Expand Down
78 changes: 46 additions & 32 deletions front-end/package-lock.json

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

6 changes: 4 additions & 2 deletions front-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.8"
},
"scripts": {
"start": "node server.js"
},
"dependencies": {
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-transform-react-jsx": "^7.0.0",
"axios": "^0.18.0",
"babel-plugin-transform-react-jsx": "^6.24.1",
"contentful": "^7.0.3",
"express": "^4.16.4",
"gatsby": "^2.0.2",
"mongodb": "^3.1.6",
"mongodb-stitch-browser-sdk": "^4.0.13",
"mongodb-stitch-server-sdk": "^4.0.13",
"react": "^16.5.2",
Expand Down
74 changes: 74 additions & 0 deletions front-end/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const http = require('http');
const fs = require('fs');
const express = require('express');
const bodyParser = require('body-parser');
const querystring = require('querystring');
const router = express.Router();
const exec = require('child_process').exec;

const app = express();
app.use('/', router);
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

const port = 8080;

const beginBuild = (req, res) => {
// start sending output to client
res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
res.write('<html>');
res.write('<body>');
res.write('<h1>Building site...</h1>');
// get params
const STITCH_ID = req.query.stitch_id;
const NAMESPACE = req.query.namespace;
const PREFIX = req.query.prefix;
if (!STITCH_ID || !NAMESPACE || !PREFIX) {
res.write('<p>Error with query params</p>');
return;
}
// set env variables
const env = Object.assign({}, process.env);
env['STITCH_ID'] = STITCH_ID;
env['NAMESPACE'] = NAMESPACE;
env['PREFIX'] = PREFIX;
// kick off build
const gatsbyBuild = exec('gatsby build --prefix-paths', { env: env }, (err, stdout, stderr) => {
if (err || stderr) {
console.log('ERROR: problem with kicking off build using Gatsby');
}
});
// get console data as build is running
gatsbyBuild.stdout.on('data', (data) => {
console.log(data);
res.write('<p style="margin:0;font-size:13px;">' + data + '</p>');
});
// when build is finished
gatsbyBuild.on('exit', function() {
const gatsbyServe = exec('gatsby serve');
gatsbyServe.stdout.on('data', (data) => {
console.log(data);
// TODO: upload files to aws
res.write('<p style="margin:0;font-size:13px;font-size:25px;font-weight:bold;">' + data + '</p>');
res.write('</body>');
res.write('</html>');
res.end();
});
});
};

// https://github.com/gatsbyjs/gatsby/issues/3485
router.get('/', (req, res) => {
// pre-build config
console.log('running makefile to get docs-tools');
exec('make static', () => {
beginBuild(req, res);
});
});

app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});



Loading

0 comments on commit 1e60c0e

Please sign in to comment.